Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3665613lfo; Mon, 23 May 2022 10:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1SAnFrhRRRBsxnm2I5fkkMfpFTSF9eAYfXWYfl/4fnoCOC9rj4ZW55jTj5btZzAOvnpQb X-Received: by 2002:a17:90b:1651:b0:1df:c567:ebb3 with SMTP id il17-20020a17090b165100b001dfc567ebb3mr129527pjb.171.1653328005355; Mon, 23 May 2022 10:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653328005; cv=none; d=google.com; s=arc-20160816; b=Vm/R5GNApUTMClNoqCCmWVjriuFwNLcQJJNfziQn1ubrOuealJhsED2MqS+TZMOHqe 4bt5UlhVs8/azp/9ZuCtaopz233oDg5KD1SFD44GOPeV2wW71Lwntj/nxwc2wHX/lYgV Jzp1Rnw8CvfqUoHIV082aAYbeD7T1sdQbC9QuOlejViNXRTVHwWxns1yBnIcsyKhpdyy uv1nmeRcbUPPXi2pfDybhi/n5R+ff7BloaS+AJxssBfoPxat3Z2dFx/B+nm1NcmIdV0y jZZ61TAyd/iePiG+FQw1e+ggejJD+cqALXvMB1sYfZAMEsBcu/KZkwY99pmvdRWjHiPv JB2Q== 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=tdTWD0JolnUenm1oe8BRYnODYYFiqXigKhvZlW+ANhs=; b=Tr3oMMhgKUXbnfAuoQR/MYmunszW1lnFozU7N3ObaXCJHJy69XU+MBQ9TWi2UubWds zIBlsUAnGrq3UJP+80J7/M8v4l4RGzLYCwBqpS8nP4TBNM8EiMkSxIIN2TbDc/MGZqVs Omq96o4LWpGZqN1LfjjgmnRNj4GMSCAEUMnfmFBll5kdqXc/X0gA0wc8H1+bmuUFQr3Z EX1QV+tS3RmPvppzuwJdRBRBbKxILHaQeMHI6SdjBMGmTFgTF17KgfYd6wIVQ4/z+Dez V169Arh9qDlcQvbRODOOT3PZKOhar0z2NmTRfB94ihXvSLhH7x3NYDj3gYkB92JR2Xgb qBUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DXrFvkCW; 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 g132-20020a636b8a000000b003f24f2ab5c5si11406383pgc.335.2022.05.23.10.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:46: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=DXrFvkCW; 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 1E44CA76CF; Mon, 23 May 2022 10:45:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243824AbiEWRml (ORCPT + 99 others); Mon, 23 May 2022 13:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242607AbiEWR1s (ORCPT ); Mon, 23 May 2022 13:27:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3E198022A; Mon, 23 May 2022 10:23:53 -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 A97AB6152F; Mon, 23 May 2022 17:13:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78D7AC385A9; Mon, 23 May 2022 17:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326021; bh=BW5Jbg92phWLgEjXChy3GA+iNXA+MLZLVE+rEXvsh+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DXrFvkCW2uehh4Bwhq/Wm7Q0oWJLRhaduYyvweDjCOwzHNl6jXAsJW/TBXRwlfr4t rqS6EuFHjC95G6RcX9+LxBta1pyU0WEohdPCg/uAchn8Jqz1+5mf5pwDl+G0GTEuSK GF5nOv53u9hv3KbkPMDHAONLUsUEXO3sXAOJHezc= 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 5.4 43/68] NFC: nci: fix sleep in atomic context bugs caused by nci_skb_alloc Date: Mon, 23 May 2022 19:05:10 +0200 Message-Id: <20220523165809.719807111@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@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 ce3382be937f..b002e18f38c8 100644 --- a/net/nfc/nci/data.c +++ b/net/nfc/nci/data.c @@ -118,7 +118,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 04e55ccb3383..4fe336ff2bfa 100644 --- a/net/nfc/nci/hci.c +++ b/net/nfc/nci/hci.c @@ -153,7 +153,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; @@ -186,7 +186,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