Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6204259iob; Tue, 10 May 2022 12:46:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+HVSChDVN26PSMf84JebTdJhkfLrU74O/2p+HHJi1Vng5WvYjNa+1ePZH4ycNU1sxrqVd X-Received: by 2002:a17:90b:4f87:b0:1dd:100b:7342 with SMTP id qe7-20020a17090b4f8700b001dd100b7342mr1480572pjb.64.1652212002401; Tue, 10 May 2022 12:46:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652212002; cv=none; d=google.com; s=arc-20160816; b=GyiHT/O9lBoXNQQQsZLgyNS6PHn4XrFBA5gYdHZ215kwrZOunlz3PD3cOhcgp1NZ+N 9Y6PVllFp3lUHUQ4lMr54tmDN7ApTw6K5lISe0454VV6Bk7yZtlXNPCVhpQqjsXESM3N YBMlq3kqbLHGc3lqR8lcm8E3uoivk1KSiK3XAFm8btbDfCNYsdnAhdjIAQx+wCuewNdO hiSOv6HMbBAyDFaFPVYR6z2Q+URd3Y6Yroigdoy2rWrHUHoL+R1hLrxn0Qq4iF/NVpG1 PKQJRqXXhxH3IvTHkKV7nwMLY3geR1L4uTb7H7TYAdfyovrlYqHiQG9gLgFbc3O0r/W0 URyQ== 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=V1mndp2wT+llusM4aVBkTZsoTZxwQ0nvq8rteEbMd38=; b=akFlhbqlIA1kunZ+8doHKn43jj28Wl5JOvc3w4LhB4XmA9I9GxCSVDIAbA5gxbeIq6 NPuA7Q01qFrGEbfxUGAnMyvrNs9tBCHOQx8CmZByUC3a7AVECuFK6/4KgrsHCBz9gWXt rqWduWOkHCTZSgdtmynJ7qA+xIEvVOWitL89eNcXyzHnHbU6p2ihpERFQFuhOMeNZeJk 8gB+j9wq6z8iRjOrUJs0r30Rnk6FkQsdMX+dm+gY158nBmI4+2WbhZmt+JjKvHUDs85w 3SxLJXq/PTHrimhjlcjm9a8hQos+k2SJMCrUFwO3VF4GwrVJPWVRtZeYI/pDxxf7sy66 Ak9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ahgLtRgC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a170902b7c700b0015f20748e43si3679605plz.513.2022.05.10.12.46.26; Tue, 10 May 2022 12:46:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ahgLtRgC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343621AbiEJNsS (ORCPT + 99 others); Tue, 10 May 2022 09:48:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243869AbiEJNcT (ORCPT ); Tue, 10 May 2022 09:32:19 -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 64D1449CB6; Tue, 10 May 2022 06:22:54 -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 03B0861763; Tue, 10 May 2022 13:22:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A3C0C385A6; Tue, 10 May 2022 13:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652188973; bh=JpV8vRtiyWpPKkhCTGwdWJ/f2raCu88HguXmG46rotU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ahgLtRgCyhKhl+3p8VAzQCBClDklP+05fMq5vLwi455kcQipacthfWOyc7+PhdhQM iPJKcCO0SeWKwCZkq3tqx+8yvdPDbPhCIjMOllghkIoyyYrvq306eR1cto4JPa0tQX nVaRJcsY0jYh4jk9gItxuGFjRUerWFdYtoPFtGdU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Krzysztof Kozlowski , Paolo Abeni Subject: [PATCH 5.4 22/52] NFC: netlink: fix sleep in atomic bug when firmware download timeout Date: Tue, 10 May 2022 15:07:51 +0200 Message-Id: <20220510130730.501650145@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130729.852544477@linuxfoundation.org> References: <20220510130729.852544477@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 commit 4071bf121d59944d5cd2238de0642f3d7995a997 upstream. There are sleep in atomic bug that could cause kernel panic during firmware download process. The root cause is that nlmsg_new with GFP_KERNEL parameter is called in fw_dnld_timeout which is a timer handler. The call trace is shown below: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:265 Call Trace: kmem_cache_alloc_node __alloc_skb nfc_genl_fw_download_done call_timer_fn __run_timers.part.0 run_timer_softirq __do_softirq ... The nlmsg_new with GFP_KERNEL parameter may sleep during memory allocation process, and the timer handler is run as the result of a "software interrupt" that should not call any other function that could sleep. This patch changes allocation mode of netlink message from GFP_KERNEL to GFP_ATOMIC in order to prevent sleep in atomic bug. The GFP_ATOMIC flag makes memory allocation operation could be used in atomic context. Fixes: 9674da8759df ("NFC: Add firmware upload netlink command") Fixes: 9ea7187c53f6 ("NFC: netlink: Rename CMD_FW_UPLOAD to CMD_FW_DOWNLOAD") Signed-off-by: Duoming Zhou Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220504055847.38026-1-duoming@zju.edu.cn Signed-off-by: Paolo Abeni Signed-off-by: Greg Kroah-Hartman --- net/nfc/netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c @@ -1252,7 +1252,7 @@ int nfc_genl_fw_download_done(struct nfc struct sk_buff *msg; void *hdr; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); if (!msg) return -ENOMEM; @@ -1268,7 +1268,7 @@ int nfc_genl_fw_download_done(struct nfc genlmsg_end(msg, hdr); - genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL); + genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC); return 0;