From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B82E79C0 for ; Wed, 30 Nov 2022 18:46:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B18E2C433D6; Wed, 30 Nov 2022 18:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669833985; bh=ySY3bfJZa+Y94Shb1YKZowz2e4b70n9eIqhb8o1OkPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hLNP/xfTwKgy08ak2ouakYw0B+Hg+FX5IhSsbDYbB1VMzU5bgojan7g/Y/ZSdP26A WrCuGkITxIpoJFpAP0J01rydK8owGDg7spTABSpqZUuCLBsPC7VnJnwUCXl2cF/Kfs BSDyKBEGNNDqjw6cOL66rb7OycEtQads0IDGJ6M0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+43475bf3cfbd6e41f5b7@syzkaller.appspotmail.com, Lin Ma , "David S. Miller" , Sasha Levin Subject: [PATCH 6.0 079/289] nfc/nci: fix race with opening and closing Date: Wed, 30 Nov 2022 19:21:04 +0100 Message-Id: <20221130180545.934555514@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130180544.105550592@linuxfoundation.org> References: <20221130180544.105550592@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Lin Ma [ Upstream commit 0ad6bded175e829c2ca261529c9dce39a32a042d ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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..4ffdf2f45c44 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.35.1