From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8715C47089 for ; Mon, 5 Dec 2022 19:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233533AbiLETUy (ORCPT ); Mon, 5 Dec 2022 14:20:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233548AbiLETUg (ORCPT ); Mon, 5 Dec 2022 14:20:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 052172A24F for ; Mon, 5 Dec 2022 11:16:54 -0800 (PST) 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 7429B61307 for ; Mon, 5 Dec 2022 19:16:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86F00C433C1; Mon, 5 Dec 2022 19:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670267779; bh=sg5HHIKNNo6ORzPd5iL/qOGTp9eN7Ld3/znCI3ZZACM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F1wc98AkuHPNFfJcpDynFlDoR1N+CKjEFah+BCfMtm0EDM/UqnXjSgRhUhliZpKZ9 /PN1+LNPrSDd+aKEbSOeCuG+ClgtdGKiadXPRv3/VcrI+hV4neTnPvQ/jast+S4oEH FToeFg5Frdo7n53E4c0OJnNnA2xzpnnCLLoZxhc8= 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 4.14 10/77] nfc/nci: fix race with opening and closing Date: Mon, 5 Dec 2022 20:09:01 +0100 Message-Id: <20221205190801.232776174@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190800.868551051@linuxfoundation.org> References: <20221205190800.868551051@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 99f4573fd917..216228c39acb 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