[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ee3c732fc23517439642d4da9ee9b198e8b77bce.camel@sarinay.com>
Date: Sun, 03 Nov 2024 12:31:16 +0100
From: Juraj Ĺ arinay <juraj@...inay.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: krzk@...nel.org, netdev@...r.kernel.org
Subject: Re: [PATCH net-next] net: nfc: Propagate ISO14443 type A target ATS
to userspace via netlink
On Wed, 2024-10-30 at 18:37 -0700, Jakub Kicinski wrote:
> > + u8 ats_len;
> > + u8 ats[NFC_ATS_MAXSIZE];
>
> New fields need kdoc:
>
> include/net/nfc/nfc.h:111: warning: Function parameter or struct member 'ats_len' not described in 'nfc_target'
> include/net/nfc/nfc.h:111: warning: Function parameter or struct member 'ats' not described in 'nfc_target'
Thanks, I shall adapt the patch accordingly.
> > + if (ntf->activation_params.nfca_poll_iso_dep.rats_res_len > 0) {
> > + ndev->target_ats_len = ntf->activation_params.nfca_poll_iso_dep.rats_res_len;
> > + memcpy(ndev->target_ats, ntf->activation_params.nfca_poll_iso_dep.rats_res,
> > + ndev->target_ats_len);
>
> somewhat tangential but does something validate the buffer vs this
> length? I see handling in nci_extract_activation_params_iso_dep()
> does a min(*data, 20) but there is no buffer length passed in.
> Is there a generic length validation somewhere vs the bounds of @data?
It does appear that nothing else gets checked after the call to
nci_valid_size() within nci_rx_work(). An invalid length byte within
the payload might well lead to a read beyond the packet boundary.
Although the packets come from a NFC Controller expected to conform to
NCI, it might still be worthwhile to make sure all the lengths add up.
The problem is common to all nci_extract_* functions. Given the various
packet types I do not see a generic way to solve it other than passing
the (remaining) buffer length down to each of the specific functions.
On a positive note, my proposed change does not make the matters worse.
For clarity, I shall replace the hard-coded constant 20 by
NFC_ATS_MAXSIZE, yet keep the following rather redundant check:
+ if (ntf->activation_params.nfca_poll_iso_dep.rats_res_len > NFC_ATS_MAXSIZE) {
+ pr_debug("ATS too long\n");
+ return NCI_STATUS_RF_PROTOCOL_ERROR;
+ }
Juraj
Powered by blists - more mailing lists