From patchwork Wed Nov 16 13:02:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 21050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp127018wru; Wed, 16 Nov 2022 05:04:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7l+7Bin03X0ehSBLe7Agb+G6T2HcL2IXxAnWhbdK6eMfYlJme8RJxY/3vZ/N6w6ar1Iv2U X-Received: by 2002:a17:90a:f982:b0:213:2030:123f with SMTP id cq2-20020a17090af98200b002132030123fmr3689977pjb.3.1668603853377; Wed, 16 Nov 2022 05:04:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668603853; cv=none; d=google.com; s=arc-20160816; b=siG9BpTDF8rjpWDlssSsS+UXZtU3Xjlueloep8WDlavLt3b3mXv4jRJZDOUVnCHZKq UyRCmmRAowYMa/3CNLi/logix7pHXceB06pz5E6fZF1aovh7gA5r0WQTa3Ys8e6OG7Lx C2y5QFl3bb3o74UZa1O50VNfHnNZs0uNNU9WHvxOWIf/hlhAMO11hHknQfpsy/MsY/7E 7Hn27pVj/jdQRRbDC8ERVVQNKttCrwhAorkac5M+GgQysW+bx+okdbYtq9PFvNRuL/3J lIF21Batx4lXrvQAdqVS8mQgLqT6z3AWafGvj39DtmQvWWzUkxaQs8z8LyRB/2B6VC7G 82LA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z23-20020a17090ab11700b0021425cf457fsi1821041pjq.32.2022.11.16.05.03.39; Wed, 16 Nov 2022 05:04:13 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749657869767320716?= X-GMAIL-MSGID: =?utf-8?q?1749657954202064161?= 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: