Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3531827iob; Sun, 1 May 2022 21:40:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoMIw0YEAEVXGCMVN7FCjhZL75Oft1FbOaAbaw9xRRDg2h4PwcFoaH0tQhepNAE7mU57mW X-Received: by 2002:a63:6c0a:0:b0:3ab:8716:3d04 with SMTP id h10-20020a636c0a000000b003ab87163d04mr8207990pgc.507.1651466415635; Sun, 01 May 2022 21:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651466415; cv=none; d=google.com; s=arc-20160816; b=s58nuQpBzqv19NelGScM97KAoU37Jz7fmhVBvJQ2YeLYzPa7gQrt8ffFddMPS5n64S Oq7fhNO7fNtwrMx5xgldgzgIbJHgBcajnj3wFtL8RIGY8HJzrPa+1sLQsfFACLqTYBq/ /wuPFRoVBx4Fp53bWV1MZ/MsXWMQRlFJJwLGQUQmIBpgtobo8Kv0vU+d0UY6vG0yB6bR 7ooZQVsc0dhX+E2YG2VCHM0pGCmRyrk/2gpIYaGaw0ZjK4OiRww+hQcZrwIByUTGQKYL YsrD8ogAKaYgUwqtkf/wM6/mGg+rpNYsaoERIy2MX1ovCt3KgTLcpsN4ESdJZULIHzQy AVTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xjmubfO3cxeydduyjpRYCJA/LNj7jbDcVCBFkF9FEbU=; b=VCJE78WmGcAoArUhnL+/uTRGulLOprG+3wFbaVjspUThYj8NZ9OxOIwXgmFw54xeba Pns054wZ4PX8OpTKdNYy69pDhsBnTNMHDib4kbEvhzqTy7VnQXe5pvkt5lNwBPmLUyGm vFDePEuTOzycbjcQBMSi0K9kUWfDQuyWKLjolHQc6G1h/8K20hLIoRI9m0q7KhEbYXmQ ps06BrIrRFaPLJa0udsNCDCIlNh7zD2aR1hVswjQni5jdNRSuIDLgtf1Nqs81iyEtXvN hZTkvf1iPlEBQTUNz2QVIE/+JU4HqHdCk2nNCHs9Siqqvt4YTq+4J0p1MYu+EuZnAJ0D T14Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="vlYY8/5P"; 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 t9-20020a1709027fc900b00158ba0afc1esi12122985plb.54.2022.05.01.21.39.59; Sun, 01 May 2022 21:40:15 -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="vlYY8/5P"; 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 S1354912AbiD2HGZ (ORCPT + 99 others); Fri, 29 Apr 2022 03:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236404AbiD2HGY (ORCPT ); Fri, 29 Apr 2022 03:06:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BE34B822F; Fri, 29 Apr 2022 00:03:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3F4FEB832FA; Fri, 29 Apr 2022 07:03:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 420D1C385B2; Fri, 29 Apr 2022 07:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651215785; bh=YUw9DM7maXM+o6uWOkN5EuzAhffbboxatFY6O6BcD0o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vlYY8/5Pkh1SmvFF0bj6hu1AXEiof4+7RywXfpihw3yR1UjFhi3rlkjdpLtdbQ2OO Yhm1ZRFJGqDdWJCHRcD5bvrTa5pK4gE+wK8VBEmIRz1uV7+mUMD0Gv5Zk0+mxmZa87 DXdG8VAfhSWTolssUQu9l7w4g4tnvEn+/KfKhUzo= Date: Fri, 29 Apr 2022 09:03:01 +0200 From: Greg KH To: Duoming Zhou Cc: linux-kernel@vger.kernel.org, kuba@kernel.org, krzysztof.kozlowski@linaro.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, alexander.deucher@amd.com, akpm@linux-foundation.org, broonie@kernel.org, netdev@vger.kernel.org, linma@zju.edu.cn Subject: Re: [PATCH net v5 1/2] nfc: replace improper check device_is_registered() in netlink related functions Message-ID: References: <33a282a82c18f942f1f5f9ee0ffcb16c2c7b0ece.1651194245.git.duoming@zju.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33a282a82c18f942f1f5f9ee0ffcb16c2c7b0ece.1651194245.git.duoming@zju.edu.cn> 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 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 On Fri, Apr 29, 2022 at 09:14:32AM +0800, Duoming Zhou wrote: > The device_is_registered() in nfc core is used to check whether > nfc device is registered in netlink related functions such as > nfc_fw_download(), nfc_dev_up() and so on. Although device_is_registered() > is protected by device_lock, there is still a race condition between > device_del() and device_is_registered(). The root cause is that > kobject_del() in device_del() is not protected by device_lock. > > (cleanup task) | (netlink task) > | > nfc_unregister_device | nfc_fw_download > device_del | device_lock > ... | if (!device_is_registered)//(1) > kobject_del//(2) | ... > ... | device_unlock > > The device_is_registered() returns the value of state_in_sysfs and > the state_in_sysfs is set to zero in kobject_del(). If we pass check in > position (1), then set zero in position (2). As a result, the check > in position (1) is useless. > > This patch uses bool variable instead of device_is_registered() to judge > whether the nfc device is registered, which is well synchronized. > > Fixes: 3e256b8f8dfa ("NFC: add nfc subsystem core") > Signed-off-by: Duoming Zhou > --- > Changes in v5: > - Replace device_is_registered() to bool variable. Reviewed-by: Greg Kroah-Hartman