From: Paolo Abeni <pabeni@redhat.com>
To: Michael Thalmeier <michael.thalmeier@hale.at>,
Deepak Sharma <deepak.sharma.472935@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Simon Horman <horms@kernel.org>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] net: nfc: nci: Fix parameter validation for packet data
Date: Thu, 18 Dec 2025 16:36:16 +0100 [thread overview]
Message-ID: <743244a0-41ea-4e7f-bd81-6814e852971d@redhat.com> (raw)
In-Reply-To: <20251210081605.3855663-1-michael.thalmeier@hale.at>
On 12/10/25 9:16 AM, Michael Thalmeier wrote:
> Since commit 9c328f54741b ("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: 9c328f54741b ("net: nfc: nci: Add parameter validation for packet data")
> Cc: stable@vger.kernel.org
> Signed-off-by: Michael Thalmeier <michael.thalmeier@hale.at>
> ---
> Changes in v2:
> - Reference correct commit hash
Minor nit: you should include the target tree ('net' in this case) in
the subj prefix.
> net/nfc/nci/ntf.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
> index 418b84e2b260..5161e94f067f 100644
> --- a/net/nfc/nci/ntf.c
> +++ b/net/nfc/nci/ntf.c
> @@ -58,7 +58,8 @@ static int nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
> struct nci_conn_info *conn_info;
> int i;
>
> - if (skb->len < sizeof(struct nci_core_conn_credit_ntf))
> + /* Minimal packet size for num_entries=1 is 1 x __u8 + 1 x conn_credit_entry */
> + if (skb->len < (sizeof(__u8) + sizeof(struct conn_credit_entry)))
> return -EINVAL;
You can still perform a complete check, splitting such operation in two
steps:
First ensure that input contains enough data to include the length
related field; after reading such field check the the length is valid
and the packet len matches it.
>
> ntf = (struct nci_core_conn_credit_ntf *)skb->data;
> @@ -364,7 +365,8 @@ static int nci_rf_discover_ntf_packet(struct nci_dev *ndev,
> const __u8 *data;
> bool add_target = true;
>
> - if (skb->len < sizeof(struct nci_rf_discover_ntf))
> + /* Minimal packet size is 5 if rf_tech_specific_params_len=0 */
> + if (skb->len < (5 * sizeof(__u8)))
Instead of using a magic number, you could/should use:
offsetof(struct nci_rf_discover_ntf, rf_tech_specific_params_len)
and will make the comment unneeded. Also the same consideration about
full validation apply here.
> return -EINVAL;
>
> data = skb->data;
> @@ -596,7 +598,10 @@ static int nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
> const __u8 *data;
> int err = NCI_STATUS_OK;
>
> - if (skb->len < sizeof(struct nci_rf_intf_activated_ntf))
> + /* Minimal packet size is 11 if
> + * f_tech_specific_params_len=0 and activation_params_len=0
> + */
> + if (skb->len < (11 * sizeof(__u8)))
> return -EINVAL;
Again all the above applies here, too.
/P
prev parent reply other threads:[~2025-12-18 15:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 8:16 Michael Thalmeier
2025-12-18 15:36 ` Paolo Abeni [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=743244a0-41ea-4e7f-bd81-6814e852971d@redhat.com \
--to=pabeni@redhat.com \
--cc=deepak.sharma.472935@gmail.com \
--cc=horms@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.thalmeier@hale.at \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vadim.fedorenko@linux.dev \
/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
all inboxes | Powered by JetHome®