Commit f7b52956 authored by Jia-Ju Bai's avatar Jia-Ju Bai Committed by Kleber Sacilotto de Souza

net: nfc: nci: fix a possible sleep-in-atomic-context bug in nci_uart_tty_receive()

BugLink: https://bugs.launchpad.net/bugs/1858462

[ Upstream commit b7ac8936 ]

The kernel may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:

net/nfc/nci/uart.c, 349:
	nci_skb_alloc in nci_uart_default_recv_buf
net/nfc/nci/uart.c, 255:
	(FUNC_PTR)nci_uart_default_recv_buf in nci_uart_tty_receive
net/nfc/nci/uart.c, 254:
	spin_lock in nci_uart_tty_receive

nci_skb_alloc(GFP_KERNEL) can sleep at runtime.
(FUNC_PTR) means a function pointer is called.

To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC for
nci_skb_alloc().

This bug is found by a static analysis tool STCheck written by myself.
Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 756dd772
...@@ -355,7 +355,7 @@ static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data, ...@@ -355,7 +355,7 @@ static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,
nu->rx_packet_len = -1; nu->rx_packet_len = -1;
nu->rx_skb = nci_skb_alloc(nu->ndev, nu->rx_skb = nci_skb_alloc(nu->ndev,
NCI_MAX_PACKET_SIZE, NCI_MAX_PACKET_SIZE,
GFP_KERNEL); GFP_ATOMIC);
if (!nu->rx_skb) if (!nu->rx_skb)
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment