mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-07-08 18:13:59 +02:00
nfc: pn533: allocate rx skb before consuming bytes
commitc71ba669b5upstream. pn532_receive_buf() reports the number of accepted bytes to the serdev core. The current code consumes bytes into recv_skb and may already hand a complete frame to pn533_recv_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:c656aa4c27("nfc: pn533: add UART phy driver") Cc: stable@vger.kernel.org Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Link: https://patch.msgid.link/20260405094003.3-pn533-v2-pengpeng@iscas.ac.cn Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
a8d2a37a93
commit
2ca64fb7e2
@@ -211,6 +211,13 @@ static int pn532_receive_buf(struct serdev_device *serdev,
|
||||
|
||||
del_timer(&dev->cmd_timeout);
|
||||
for (i = 0; i < count; i++) {
|
||||
if (!dev->recv_skb) {
|
||||
dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN,
|
||||
GFP_KERNEL);
|
||||
if (!dev->recv_skb)
|
||||
return i;
|
||||
}
|
||||
|
||||
if (unlikely(!skb_tailroom(dev->recv_skb)))
|
||||
skb_trim(dev->recv_skb, 0);
|
||||
|
||||
@@ -219,9 +226,7 @@ static int pn532_receive_buf(struct serdev_device *serdev,
|
||||
continue;
|
||||
|
||||
pn533_recv_frame(dev->priv, dev->recv_skb, 0);
|
||||
dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN, GFP_KERNEL);
|
||||
if (!dev->recv_skb)
|
||||
return 0;
|
||||
dev->recv_skb = NULL;
|
||||
}
|
||||
|
||||
return i;
|
||||
|
||||
Reference in New Issue
Block a user