Netdev List
 help / color / mirror / Atom feed
From: "Juraj Šarinay" <juraj@sarinay.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: krzk@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: nfc: Propagate ISO14443 type A target ATS to userspace via netlink
Date: Sun, 03 Nov 2024 12:31:16 +0100	[thread overview]
Message-ID: <ee3c732fc23517439642d4da9ee9b198e8b77bce.camel@sarinay.com> (raw)
In-Reply-To: <20241030183747.0a042cb9@kicinski-fedora-PC1C0HJN>

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


      reply	other threads:[~2024-11-03 11:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-27 14:37 [PATCH net-next] net: nfc: Propagate ISO14443 type A target ATS to userspace via netlink Juraj Šarinay
2024-10-29 10:47 ` Krzysztof Kozlowski
2024-10-31  1:37 ` Jakub Kicinski
2024-11-03 11:31   ` Juraj Šarinay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee3c732fc23517439642d4da9ee9b198e8b77bce.camel@sarinay.com \
    --to=juraj@sarinay.com \
    --cc=krzk@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox