linux/drivers/nfc
Pengpeng Hou 20a57de2e7 nfc: s3fwrn5: allocate rx skb before consuming bytes
[ Upstream commit 5c14a19d5b ]

s3fwrn82_uart_read() reports the number of accepted bytes to the serdev
core. The current code consumes bytes into recv_skb and may already
deliver a complete frame before allocating a fresh receive buffer.

If that alloc_skb() fails, the callback returns 0 even though it has
already consumed bytes, and it leaves recv_skb as NULL for the next
receive callback. That breaks the receive_buf() accounting contract and
can also lead to a NULL dereference on the next skb_put_u8().

Allocate the receive skb lazily before consuming the next byte instead.
If allocation fails, return the number of bytes already accepted.

Fixes: 3f52c2cb7e ("nfc: s3fwrn5: Support a UART interface")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Link: https://patch.msgid.link/20260402042148.65236-1-pengpeng@iscas.ac.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-06-01 17:35:02 +02:00
..
fdp nfc: fdp: add null check of devm_kmalloc_array in fdp_nci_i2c_read_device_properties 2023-03-17 08:48:53 +01:00
microread nfc: microread: remove unused header includes 2021-08-26 09:13:35 +01:00
nfcmrvl nfc: nfcmrvl: Fix potential memory leak in nfcmrvl_i2c_nci_send() 2022-11-10 18:15:28 +01:00
nxp-nci NFC: nxp-nci: allow GPIOs to sleep 2026-04-18 10:33:17 +02:00
pn533 nfc: pn533: allocate rx skb before consuming bytes 2026-04-18 10:33:37 +02:00
pn544 minmax: make generic MIN() and MAX() macros available everywhere 2025-10-19 16:21:52 +02:00
s3fwrn5 nfc: s3fwrn5: allocate rx skb before consuming bytes 2026-06-01 17:35:02 +02:00
st-nci nfc: st-nci: Fix use after free bug in ndlc_remove due to race condition 2023-03-22 13:31:26 +01:00
st21nfca nfc: fix memory leak of se_io context in nfc_genl_se_io 2023-03-11 13:57:29 +01:00
st95hf nfc: st95hf: Make spi remove() callback return zero 2021-10-20 14:41:20 +01:00
Kconfig nfc: Add a virtual nci device driver 2021-01-29 18:03:33 -08:00
Makefile nfc: Add a virtual nci device driver 2021-01-29 18:03:33 -08:00
mei_phy.c nfc: mei_phy: constify buffer passed to mei_nfc_send() 2021-07-29 12:28:02 +01:00
mei_phy.h nfc: constify nfc_phy_ops 2021-07-25 09:21:21 +01:00
nfcsim.c nfcsim.c: Fix error checking for debugfs_create_dir 2023-06-28 10:29:51 +02:00
port100.c NFC: port100: fix use-after-free in port100_send_complete 2022-03-16 14:23:39 +01:00
trf7970a.c NFC: trf7970a: disable all regulators on removal 2024-05-02 16:24:45 +02:00
virtual_ncidev.c Revert "nfc/nci: Add the inconsistency check between the input data length and count" 2026-02-06 16:41:53 +01:00