* [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer
@ 2026-06-03 14:13 Doruk Tan Ozturk
2026-06-03 14:28 ` Alexander Lobakin
2026-06-06 12:10 ` David Heidelberg
0 siblings, 2 replies; 4+ messages in thread
From: Doruk Tan Ozturk @ 2026-06-03 14:13 UTC (permalink / raw)
To: David Heidelberg, oe-linux-nfc
Cc: Aleksander Lobakin, netdev, linux-kernel, Doruk Tan Ozturk, stable
digital_in_recv_sensf_res() memcpy()s resp->len bytes from a remote
NFC-F device response into the NFC_SENSF_RES_MAXSIZE-byte target.sensf_res
field without an upper-bound check. A nearby malicious NFC-F device can
send an oversized SENSF_RES response to overflow the stack-local struct
nfc_target.
Clamp resp->len to NFC_SENSF_RES_MAXSIZE before the copy.
Found by 0sec automated security-research tooling (https://0sec.ai).
Fixes: 8c0695e4998d ("NFC Digital: Add NFC-F technology support")
Cc: stable@vger.kernel.org
Signed-off-by: Doruk Tan Ozturk <doruk@0sec.ai>
---
v2:
- Clamp resp->len with min_t() before the copy (Alexander Lobakin).
- Add Fixes: tag and Cc: stable (Alexander Lobakin).
- Frame as a stack buffer overflow (saved-return overwrite not demonstrated).
net/nfc/digital_technology.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
index ae63c5eb0..ae6487c10 100644
--- a/net/nfc/digital_technology.c
+++ b/net/nfc/digital_technology.c
@@ -778,6 +778,8 @@ static void digital_in_recv_sensf_res(struct nfc_digital_dev *ddev, void *arg,
sensf_res = (struct digital_sensf_res *)resp->data;
+ resp->len = min_t(unsigned int, resp->len, NFC_SENSF_RES_MAXSIZE);
+
memcpy(target.sensf_res, sensf_res, resp->len);
target.sensf_res_len = resp->len;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer
2026-06-03 14:13 [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer Doruk Tan Ozturk
@ 2026-06-03 14:28 ` Alexander Lobakin
2026-06-03 16:46 ` Doruk (0sec)
2026-06-06 12:10 ` David Heidelberg
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2026-06-03 14:28 UTC (permalink / raw)
To: Doruk Tan Ozturk
Cc: David Heidelberg, oe-linux-nfc, netdev, linux-kernel, stable
From: Doruk Tan Ozturk <doruk@0sec.ai>
Date: Wed, 3 Jun 2026 16:13:55 +0200
> digital_in_recv_sensf_res() memcpy()s resp->len bytes from a remote
> NFC-F device response into the NFC_SENSF_RES_MAXSIZE-byte target.sensf_res
> field without an upper-bound check. A nearby malicious NFC-F device can
> send an oversized SENSF_RES response to overflow the stack-local struct
> nfc_target.
>
> Clamp resp->len to NFC_SENSF_RES_MAXSIZE before the copy.
>
> Found by 0sec automated security-research tooling (https://0sec.ai).
>
> Fixes: 8c0695e4998d ("NFC Digital: Add NFC-F technology support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Doruk Tan Ozturk <doruk@0sec.ai>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
> ---
> v2:
> - Clamp resp->len with min_t() before the copy (Alexander Lobakin).
> - Add Fixes: tag and Cc: stable (Alexander Lobakin).
> - Frame as a stack buffer overflow (saved-return overwrite not demonstrated).
> net/nfc/digital_technology.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
> index ae63c5eb0..ae6487c10 100644
> --- a/net/nfc/digital_technology.c
> +++ b/net/nfc/digital_technology.c
> @@ -778,6 +778,8 @@ static void digital_in_recv_sensf_res(struct nfc_digital_dev *ddev, void *arg,
>
> sensf_res = (struct digital_sensf_res *)resp->data;
>
> + resp->len = min_t(unsigned int, resp->len, NFC_SENSF_RES_MAXSIZE);
> +
> memcpy(target.sensf_res, sensf_res, resp->len);
> target.sensf_res_len = resp->len;
I was wondering whether we need to record this in the kernel log.
But given that a malicious device can and would be happy to flood with
such packets, it would be pr_warn_once() or something similar at max.
But I guess it's not needed at all, we can just silently clamp such packets?
Thanks,
Olek
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer
2026-06-03 14:28 ` Alexander Lobakin
@ 2026-06-03 16:46 ` Doruk (0sec)
0 siblings, 0 replies; 4+ messages in thread
From: Doruk (0sec) @ 2026-06-03 16:46 UTC (permalink / raw)
To: aleksander.lobakin; +Cc: david, oe-linux-nfc, netdev, linux-kernel, stable
On Wed, Jun 03, 2026 04:28 PM, Alexander Lobakin
<aleksander.lobakin@intel.com> wrote:
> But I guess it's not needed at all, we can just silently clamp such packets?
I agree, thanks for the review!
Doruk
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer
2026-06-03 14:13 [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer Doruk Tan Ozturk
2026-06-03 14:28 ` Alexander Lobakin
@ 2026-06-06 12:10 ` David Heidelberg
1 sibling, 0 replies; 4+ messages in thread
From: David Heidelberg @ 2026-06-06 12:10 UTC (permalink / raw)
To: Doruk Tan Ozturk
Cc: Aleksander Lobakin, netdev, linux-kernel, stable, oe-linux-nfc
On Wed, 03 Jun 2026 16:13:55 +0200, Doruk Tan Ozturk wrote:
> nfc: digital: clamp SENSF_RES length to the destination buffer
Applied, thanks!
[1/1] nfc: digital: clamp SENSF_RES length to the destination buffer
commit: b3d780a22685ea355e18bfeac79d15252236d70e
Best regards,
--
David Heidelberg <david@ixit.cz>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-06 12:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03 14:13 [PATCH net v2] nfc: digital: clamp SENSF_RES length to the destination buffer Doruk Tan Ozturk
2026-06-03 14:28 ` Alexander Lobakin
2026-06-03 16:46 ` Doruk (0sec)
2026-06-06 12:10 ` David Heidelberg
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®