Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp603922rwb; Wed, 16 Nov 2022 05:23:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5YlaZhIB3Nhx2q2w1S3oMFlqnPbCVH5sOBpNBGvU7hxhSfbkTyK+L6G+T6sD6xzBqr4tb+ X-Received: by 2002:a63:db4e:0:b0:43c:5e0:f2aa with SMTP id x14-20020a63db4e000000b0043c05e0f2aamr20373236pgi.448.1668605038569; Wed, 16 Nov 2022 05:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668605038; cv=none; d=google.com; s=arc-20160816; b=bakHhnu5r9nChJyr5ECd+aSuc0etK368shTHv0dFPpDMT+KN+oefr6dv1v3NM/So6f 7pAqehq4YjK3WXuA6Xhf4eISA28nZxGrez5SGniMD7nJjtKSy9QQYpEkBa+g13UeDbS+ EldBufXF7duGHF+TrF+R5VHaCPjaxv9QKdteX+zfvt37vC+KO+tTJRkR7M6GLjyB0DKX eKFz3LRj4KHPF61nO3HGO2T6ULukfJqEnjbuBzkSBNevqvN2M9RSlLhvGyINQS0eNY0c ePEb2ZTMi2ZQ8A5Ky7u5S4KK5emTD4lB2hWLY3l/qnomXdVA7nxN3RaDYgOugnNqbWSh ASwA== 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 :message-id:date:subject:cc:to:from; bh=ZVsigRxEH0T8OtG0DqGUHdaWafRHvrI+WiElAcj0h0Y=; b=j0o5o8YvEolbcgD0LuDuzOO7ASuwAajCdlsvrX8EU34QtDL8dh68+vWhTjn6P9ezGy /M5PCWJ6UxkpknpGmGXxb+cAtRt3F7GowTLrtCpzxxkp/iTrYv4vmQOWunSF4p6WJ0Vz 8m3hFNC8ztTLmB5a9ncIWtA1N/N8vd747RgLcXlMtuBznLm065dgIDIIIcmGDt8Y5mPl Fgsals5RN/FS1mdrFg3S9kLAI3XFZpBHaOc1M6s6SOMG8afi9VYq6cRK2MSo4q6CBA5F dU4eIiqV/Nz9OCF398yxqGClQOOnG3+lPmUJG+DGNGn7WEvzlDShJ41thGmzkeT1cQZN NhHg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020a17090ad20600b00205f49b70fdsi1757266pju.127.2022.11.16.05.23.46; Wed, 16 Nov 2022 05:23:58 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231292AbiKPNDK (ORCPT + 91 others); Wed, 16 Nov 2022 08:03:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiKPNDI (ORCPT ); Wed, 16 Nov 2022 08:03:08 -0500 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB0252EF08; Wed, 16 Nov 2022 05:03:06 -0800 (PST) Received: from zju.edu.cn (unknown [10.12.77.33]) by mail-app2 (Coremail) with SMTP id by_KCgC3v_eB33RjIaC2Bw--.48260S4; Wed, 16 Nov 2022 21:02:57 +0800 (CST) From: Lin Ma To: krzk@kernel.org, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mudongliangabcd@gmail.com Cc: Lin Ma , syzbot+43475bf3cfbd6e41f5b7@syzkaller.appspotmail.com Subject: [PATCH v2] nfc/nci: fix race with opening and closing Date: Wed, 16 Nov 2022 21:02:49 +0800 Message-Id: <20221116130249.10232-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: by_KCgC3v_eB33RjIaC2Bw--.48260S4 X-Coremail-Antispam: 1UD129KBjvdXoWrKF4DZw45XrWDCFykGF4fGrg_yoWDZrXE93 yxAF4DXws5Aw1xGwsxJF4Dtryaya4Igay09rWrWF4jv345Zrn8ArZ7WrnxXF13ua43uFyD XFn2qFW8C345WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb2kFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AK wVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20x vE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E 87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c 8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_ JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwACjI8F5VA0II8E6IAqYI8I648v4I1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxF aVAv8VW8uw4UJr1UMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr 4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxG rwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJw CI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2 z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VU1a9aPUUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 Previously we leverage NCI_UNREG and the lock inside nci_close_device to prevent the race condition between opening a device and closing a device. However, it still has problem because a failed opening command will erase the NCI_UNREG flag and allow another opening command to bypass the status checking. This fix corrects that by making sure the NCI_UNREG is held. Reported-by: syzbot+43475bf3cfbd6e41f5b7@syzkaller.appspotmail.com Fixes: 48b71a9e66c2 ("NFC: add NCI_UNREG flag to eliminate the race") Signed-off-by: Lin Ma --- V1 -> V2: should be &= instead of = net/nfc/nci/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index 6a193cce2a75..76ade5d4f55a 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -542,7 +542,7 @@ static int nci_open_device(struct nci_dev *ndev) skb_queue_purge(&ndev->tx_q); ndev->ops->close(ndev); - ndev->flags = 0; + ndev->flags &= BIT(NCI_UNREG); } done: -- 2.38.1