mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx
@ 2022-05-16  2:10 Duoming Zhou
  2022-05-16  6:44 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Duoming Zhou @ 2022-05-16  2:10 UTC (permalink / raw)
  To: linux-kernel, krzysztof.kozlowski
  Cc: davem, edumazet, kuba, pabeni, gregkh, alexander.deucher,
	broonie, netdev, Duoming Zhou

There are sleep in atomic context bugs when the request to secure
element of st21nfca is timeout. The root cause is that kzalloc and
alloc_skb with GFP_KERNEL parameter is called in st21nfca_se_wt_timeout
which is a timer handler. The call tree shows the execution paths that
could lead to bugs:

   (Interrupt context)
st21nfca_se_wt_timeout
  nfc_hci_send_event
    nfc_hci_hcp_message_tx
      kzalloc(..., GFP_KERNEL) //may sleep
      alloc_skb(..., GFP_KERNEL) //may sleep

This patch changes allocation mode of kzalloc and alloc_skb from
GFP_KERNEL to GFP_ATOMIC in order to prevent atomic context from
sleeping. The GFP_ATOMIC flag makes memory allocation operation
could be used in atomic context.

Fixes: 8b8d2e08bf0d ("NFC: HCI support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 net/nfc/hci/hcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/hci/hcp.c b/net/nfc/hci/hcp.c
index 05c60988f59..1caf9c2086f 100644
--- a/net/nfc/hci/hcp.c
+++ b/net/nfc/hci/hcp.c
@@ -30,7 +30,7 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
 	int hci_len, err;
 	bool firstfrag = true;
 
-	cmd = kzalloc(sizeof(struct hci_msg), GFP_KERNEL);
+	cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
 	if (cmd == NULL)
 		return -ENOMEM;
 
@@ -58,7 +58,7 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
 			  data_link_len + ndev->tx_tailroom;
 		hci_len -= data_link_len;
 
-		skb = alloc_skb(skb_len, GFP_KERNEL);
+		skb = alloc_skb(skb_len, GFP_ATOMIC);
 		if (skb == NULL) {
 			err = -ENOMEM;
 			goto out_skb_err;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-17 12:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  2:10 [PATCH net] NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx Duoming Zhou
2022-05-16  6:44 ` Krzysztof Kozlowski
2022-05-16 10:18   ` duoming
2022-05-16 10:43     ` Krzysztof Kozlowski
2022-05-17 10:56       ` duoming
2022-05-17 11:39         ` Krzysztof Kozlowski
2022-05-17 12:24           ` duoming

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®