diff mbox series

[2/2,net] nfc: nci: Potential off by one in ->pipes[] array

Message ID 20190403071351.GB5758@kadam (mailing list archive)
State Deferred
Delegated to: Samuel Ortiz
Headers show
Series [1/2,net] NFC: nci: Add some bounds checking in nci_hci_cmd_received() | expand

Commit Message

Dan Carpenter April 3, 2019, 7:13 a.m. UTC
This is similar to commit e285d5bfb7e9 ("NFC: Fix the number of pipes")
where we changed NFC_HCI_MAX_PIPES from 127 to 128.

As the comment next to the define explains, the pipe identifier is 7
bits long.  The highest possible pipe is 127, but the number of possible
pipes is 128.  As the code is now, then there is potential for an
out of bounds array access:

    net/nfc/nci/hci.c:297 nci_hci_cmd_received() warn: array off by one?
    'ndev->hci_dev->pipes[pipe]' '0-127 == 127'

Fixes: 11f54f228643 ("NFC: nci: Add HCI over NCI protocol support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 include/net/nfc/nci_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Miller April 6, 2019, 10:04 p.m. UTC | #1
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 3 Apr 2019 10:13:51 +0300

> This is similar to commit e285d5bfb7e9 ("NFC: Fix the number of pipes")
> where we changed NFC_HCI_MAX_PIPES from 127 to 128.
> 
> As the comment next to the define explains, the pipe identifier is 7
> bits long.  The highest possible pipe is 127, but the number of possible
> pipes is 128.  As the code is now, then there is potential for an
> out of bounds array access:
> 
>     net/nfc/nci/hci.c:297 nci_hci_cmd_received() warn: array off by one?
>     'ndev->hci_dev->pipes[pipe]' '0-127 == 127'
> 
> Fixes: 11f54f228643 ("NFC: nci: Add HCI over NCI protocol support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied.
diff mbox series

Patch

diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index 87499b6b35d6..df5c69db68af 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -166,7 +166,7 @@  struct nci_conn_info {
  * According to specification 102 622 chapter 4.4 Pipes,
  * the pipe identifier is 7 bits long.
  */
-#define NCI_HCI_MAX_PIPES          127
+#define NCI_HCI_MAX_PIPES          128
 
 struct nci_hci_gate {
 	u8 gate;