Skip to content

Commit

Permalink
NFC: llcp: integer underflow in nfc_llcp_set_remote_gb()
Browse files Browse the repository at this point in the history
If gb_len is less than 3 it would cause an integer underflow and
possibly memory corruption in nfc_llcp_parse_gb_tlv().

I removed the old test for gb_len == 0.  I also removed the test for
->remote_gb == NULL.  It's not possible for ->remote_gb to be NULL and
we have already dereferenced ->remote_gb_len so it's too late to test.

The old test return -ENODEV but my test returns -EINVAL.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Dan Carpenter authored and John W. Linville committed Feb 8, 2013
1 parent c6d3b20 commit e9a4aa3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions net/nfc/llcp/llcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,13 @@ int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len)
pr_err("No LLCP device\n");
return -ENODEV;
}
if (gb_len < 3)
return -EINVAL;

memset(local->remote_gb, 0, NFC_MAX_GT_LEN);
memcpy(local->remote_gb, gb, gb_len);
local->remote_gb_len = gb_len;

if (local->remote_gb == NULL || local->remote_gb_len == 0)
return -ENODEV;

if (memcmp(local->remote_gb, llcp_magic, 3)) {
pr_err("MAC does not support LLCP\n");
return -EINVAL;
Expand Down

0 comments on commit e9a4aa3

Please sign in to comment.