6lowpan: iphc: Fix an off-by-one check of array index
authorColin Ian King <colin.king@canonical.com>
Mon, 12 Jul 2021 12:14:40 +0000 (13:14 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 22 Jul 2021 14:19:03 +0000 (16:19 +0200)
The bounds check of id is off-by-one and the comparison should
be >= rather >. Currently the WARN_ON_ONCE check does not stop
the out of range indexing of &ldev->ctx.table[id] so also add
a return path if the bounds are out of range.

Addresses-Coverity: ("Illegal address computation").
Fixes: 5609c185f24d ("6lowpan: iphc: add support for stateful compression")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/6lowpan/debugfs.c

index 1c140af06d52739b981b4f18995e2aabaf40f0f7..600b9563bfc534a7a1b71c56e5abeda77336a7c8 100644 (file)
@@ -170,7 +170,8 @@ static void lowpan_dev_debugfs_ctx_init(struct net_device *dev,
        struct dentry *root;
        char buf[32];
 
-       WARN_ON_ONCE(id > LOWPAN_IPHC_CTX_TABLE_SIZE);
+       if (WARN_ON_ONCE(id >= LOWPAN_IPHC_CTX_TABLE_SIZE))
+               return;
 
        sprintf(buf, "%d", id);