Skip to content

Commit

Permalink
6lowpan: iphc: Fix an off-by-one check of array index
Browse files Browse the repository at this point in the history
[ Upstream commit 9af4176 ]

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: 5609c18 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Colin Ian King authored and gregkh committed Sep 15, 2021
1 parent def6efd commit c7ebd36
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/6lowpan/debugfs.c
Expand Up @@ -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);

Expand Down

0 comments on commit c7ebd36

Please sign in to comment.