Skip to content

Commit 9fbc417

Browse files
mthalmeiNipaLocal
authored andcommitted
net: nfc: nci: Fix parameter validation for packet data
Since commit 9c328f5 ("net: nfc: nci: Add parameter validation for packet data") communication with nci nfc chips is not working any more. The mentioned commit tries to fix access of uninitialized data, but failed to understand that in some cases the data packet is of variable length and can therefore not be compared to the maximum packet length given by the sizeof(struct). For these cases it is only possible to check for minimum packet length. Fixes: 9c328f5 ("net: nfc: nci: Add parameter validation for packet data") Cc: stable@vger.kernel.org Signed-off-by: Michael Thalmeier <michael.thalmeier@hale.at> Signed-off-by: NipaLocal <nipa@local>
1 parent e706bd5 commit 9fbc417

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/nfc/nci/ntf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static int nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
5858
struct nci_conn_info *conn_info;
5959
int i;
6060

61-
if (skb->len < sizeof(struct nci_core_conn_credit_ntf))
61+
/* Minimal packet size for num_entries=1 is 1 x __u8 + 1 x conn_credit_entry */
62+
if (skb->len < (sizeof(__u8) + sizeof(struct conn_credit_entry)))
6263
return -EINVAL;
6364

6465
ntf = (struct nci_core_conn_credit_ntf *)skb->data;
@@ -364,7 +365,8 @@ static int nci_rf_discover_ntf_packet(struct nci_dev *ndev,
364365
const __u8 *data;
365366
bool add_target = true;
366367

367-
if (skb->len < sizeof(struct nci_rf_discover_ntf))
368+
/* Minimal packet size is 5 if rf_tech_specific_params_len=0 */
369+
if (skb->len < (5 * sizeof(__u8)))
368370
return -EINVAL;
369371

370372
data = skb->data;
@@ -596,7 +598,10 @@ static int nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
596598
const __u8 *data;
597599
int err = NCI_STATUS_OK;
598600

599-
if (skb->len < sizeof(struct nci_rf_intf_activated_ntf))
601+
/* Minimal packet size is 11 if
602+
* f_tech_specific_params_len=0 and activation_params_len=0
603+
*/
604+
if (skb->len < (11 * sizeof(__u8)))
600605
return -EINVAL;
601606

602607
data = skb->data;

0 commit comments

Comments
 (0)