Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2111668ioo; Mon, 23 May 2022 10:17:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNZYTb3pdSQn2t7uWhUmrB9EKAqwcZTj0fcBmXY3liWlgKAzqbbBHSPyMddgyholvoovqk X-Received: by 2002:a17:90a:6f44:b0:1df:7cfb:d9f9 with SMTP id d62-20020a17090a6f4400b001df7cfbd9f9mr17184pjk.201.1653326265414; Mon, 23 May 2022 10:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653326265; cv=none; d=google.com; s=arc-20160816; b=vCntB34zm1CPjbkCDT0k/TSEP/08D2HfHE7HYKGa4KyZH6ugVZ6hj1hkBu8oTaVJdh NAfeEv39AlI9CeMKf1eBgA2MqH+lu63o4OF7Nlxou0hkuZJ3EKhBnYm+phA6muHrvin8 VMqz2+9gkbqojd69ijM3Cg97jJmnWHhgQ2W5R45Jl+lT1i+HNQ+raslUX1Zr/V/muvGF M9DIMWPRW8JXSn9MD0lFB/H9W3qXH41x266P64ALN4uZDMtGYA1btlX8RLaB36HaeKzw hXzfgIOtc5a0BFzy1zSmxAl/zfDczLRO9n/U5JkS13M0G69a31lT9mKkqDxnps1XwhYc hjeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hHmPeiUIpL9n/j3u+haKy0MEnTS115pDKGdqlFZDse4=; b=RAQXy/CuGDJ4HI7Shy38qcxU9oy6pr9B17DL91JsS1ZGwDZmlzqRmpdItXpJ1KB4Fy LKet5Fd1NBiwqn8LDNEdHWI/DFTiK9HyaoWLWzNngW23AV6S0kfpVIOo9DXzGi510knz 5qQ3e+6PfccG5zWOXi3I8AFJkoWdAgoOHn14iX0PNHB5F/2IQEKZTGd4yXbF6lHO9CzE FzyM9up5b5tMdvAnZihP+p8736nkn0mS+d7Z0zGbpybrkjX43lXIUmorsQAkb1NfwEp4 GqsmdNpTKiKSeguldtbVlgoT+0CNgr+aGjxXylLgnSq+mtyCXA0QJd8ZVBW974p4YlDK R1Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A0VB5COg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m14-20020a17090ab78e00b001d960c22782si13486187pjr.158.2022.05.23.10.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:17:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A0VB5COg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 40395272E; Mon, 23 May 2022 10:17:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239860AbiEWRNt (ORCPT + 99 others); Mon, 23 May 2022 13:13:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240211AbiEWRLt (ORCPT ); Mon, 23 May 2022 13:11:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB4F238B2; Mon, 23 May 2022 10:11:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1BE4E614FB; Mon, 23 May 2022 17:10:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12B53C385A9; Mon, 23 May 2022 17:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325838; bh=z4dNxt/amUl9rRBPcT7kg7wnq1N98gWZo4V9yFbD8ag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0VB5COgH2w61sJgSKvSyoiKOzeBRcuToQ/WFVWv8o8U44+ug5wPPH+TCtuIFdTTO mmsw/jrORDsW8xd8oQ/1g+xUfPE4+TOMtjiP0YSeZcQMnb36uRk/2UqNuzDIdI2IiX gHGUiEYeGPP8E3KWfjpBy+iEosYwX+DxNt9wEu9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Krzysztof Kozlowski , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 27/44] NFC: nci: fix sleep in atomic context bugs caused by nci_skb_alloc Date: Mon, 23 May 2022 19:05:11 +0200 Message-Id: <20220523165758.067441087@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165752.797318097@linuxfoundation.org> References: <20220523165752.797318097@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duoming Zhou [ Upstream commit 23dd4581350d4ffa23d58976ec46408f8f4c1e16 ] There are sleep in atomic context bugs when the request to secure element of st-nci is timeout. The root cause is that nci_skb_alloc with GFP_KERNEL parameter is called in st_nci_se_wt_timeout which is a timer handler. The call paths that could trigger bugs are shown below: (interrupt context 1) st_nci_se_wt_timeout nci_hci_send_event nci_hci_send_data nci_skb_alloc(..., GFP_KERNEL) //may sleep (interrupt context 2) st_nci_se_wt_timeout nci_hci_send_event nci_hci_send_data nci_send_data nci_queue_tx_data_frags nci_skb_alloc(..., GFP_KERNEL) //may sleep This patch changes allocation mode of nci_skb_alloc from GFP_KERNEL to GFP_ATOMIC in order to prevent atomic context sleeping. The GFP_ATOMIC flag makes memory allocation operation could be used in atomic context. Fixes: ed06aeefdac3 ("nfc: st-nci: Rename st21nfcb to st-nci") Signed-off-by: Duoming Zhou Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220517012530.75714-1-duoming@zju.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/nfc/nci/data.c | 2 +- net/nfc/nci/hci.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c index 5405d073804c..9e3f9460f14f 100644 --- a/net/nfc/nci/data.c +++ b/net/nfc/nci/data.c @@ -130,7 +130,7 @@ static int nci_queue_tx_data_frags(struct nci_dev *ndev, skb_frag = nci_skb_alloc(ndev, (NCI_DATA_HDR_SIZE + frag_len), - GFP_KERNEL); + GFP_ATOMIC); if (skb_frag == NULL) { rc = -ENOMEM; goto free_exit; diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c index c972c212e7ca..e5c5cff33236 100644 --- a/net/nfc/nci/hci.c +++ b/net/nfc/nci/hci.c @@ -165,7 +165,7 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 pipe, i = 0; skb = nci_skb_alloc(ndev, conn_info->max_pkt_payload_len + - NCI_DATA_HDR_SIZE, GFP_KERNEL); + NCI_DATA_HDR_SIZE, GFP_ATOMIC); if (!skb) return -ENOMEM; @@ -198,7 +198,7 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 pipe, if (i < data_len) { skb = nci_skb_alloc(ndev, conn_info->max_pkt_payload_len + - NCI_DATA_HDR_SIZE, GFP_KERNEL); + NCI_DATA_HDR_SIZE, GFP_ATOMIC); if (!skb) return -ENOMEM; -- 2.35.1