Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2207312ima; Sat, 2 Feb 2019 16:57:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN79os2P769jO5S90ERliJhij9kfMEMcfgsSqP3H6QZc8sccokZFCIDEYu9Ryc7RToS5ymLA X-Received: by 2002:a17:902:1745:: with SMTP id i63mr44781544pli.145.1549155447758; Sat, 02 Feb 2019 16:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549155447; cv=none; d=google.com; s=arc-20160816; b=hN41FowK+B2yIRSShrzkzvFAuqZQAXELMA4lqOmOrWF4xClW4tfro711Qx6Pwxqy5M Rkwi9JlAv7AvD7zkkheBDlqv0ohK5gMTJpXQakQVoC9ZOP/X6aY0p6Kks/V67XfRo5GH 6RAEQcY/pCszMw1cZyQNdYlFHqvKWIlSwVuNl7ZYMuFkIDbr78RTPjmGXlQhzzfD9OqE Qob55xAxGWBrfUIHZxwjlBfi5vmNJX6sWOkBVzsoQnMFkTGFqQ87VanmQWpNFbqttea8 VE+jtXS7NPka1IqWxFUzwPzAB205+T3eCwr1IWUZn9PmUidUvJ0qN4fnLZdCkUn5CSlp wv7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=ZGcVYn3pyoZQburOYIXpkDXd89ixvABOYmn0RFue96Q=; b=YRwvOxKJTtmriPfXeJY2V4vvLKRS8ZCa1fg4PDINcykAbvsr46TXFytnQPz9f5oKZK 0m1qZGqLYhX9BRD+q18rsctRBESmwGl1uOWMAA/muwwoX8cuISdleCrd3rvuzo/dEIry 6HjW3IcOYvo7LpIQOQbd4mCYvYLrcQi0blJo66q0vGmoz7TYik2CrDiDQzCNIdfLJbjk 1jjgXDKh4w5CiD7JR72TzeyajM3dTvcEmXXCXW9wfKGMtLc99t8zUyMQ3qM5BEUECLLi Bv+XDbfngG22DMJJQ04qQyHHPaWBUR5jMuup5UeL0je90P0XSsCPXGJFInxTRstW2PBC f7Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WwE3jSJ9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si11956395plz.263.2019.02.02.16.56.46; Sat, 02 Feb 2019 16:57:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WwE3jSJ9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727225AbfBCA4l (ORCPT + 99 others); Sat, 2 Feb 2019 19:56:41 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38874 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727017AbfBCA4k (ORCPT ); Sat, 2 Feb 2019 19:56:40 -0500 Received: by mail-pf1-f195.google.com with SMTP id q1so5109784pfi.5; Sat, 02 Feb 2019 16:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=ZGcVYn3pyoZQburOYIXpkDXd89ixvABOYmn0RFue96Q=; b=WwE3jSJ9cRc3a+DuR8QJpVLuJbFK8CVHgotiDfWmnIZRqOMLmP8QJBgrlbIcGVUlKg w6gz4XQkqu0V+4nQuQvbANVGHF0SME1d25m06hltmzD1Md2MMkVfkmC+oym4nJfxd5cP BvQV3ZpAxP3f/+rlzxY6yS69NRrrm36DfQ0MRQd3NqTx1KGWYGjlFrgv/TU0mYw5M4rL y/KUY1OLYBMKV9JsUJO8gQX/vj5I7R3cs5yu7vuYKUd19HsUOfttFQMOib0y8D6+kqWd E88P5vnTOLGwhu8AOxf/WNjgRwiA5MiUnyg2lhGkq6wsRZOScxbKAaeFA9HtsfIngxCC CaSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=ZGcVYn3pyoZQburOYIXpkDXd89ixvABOYmn0RFue96Q=; b=ue89l5afjMW1VO1wB2DdZoaURC9xZZriiwuI4xWjsVtruYzUFAM613cFEXi1iHDN9y jay7YGXCczc4hOhc+3idoYAUH8QEEsOYafhX9pFW1taAEFfS2c9ewiR9FM8F73q3oNq6 L7QOmbVnHg8XWiKo7ZjkNsQICto8J4IUAc9Tm+dVdrGoBfIdRt69Hod2n72ccHktYBwC h45y7dAHvihib0F+D+G+qqrS25cOLkKbn/NA2ZUphVxZhmjgb+FHkQq84/8NLhgTif17 VG1WIIWynGBqmMJt0KtYPCvYs/u03PPfGbehxUdh6vV/vchZlZ0xj43xOy7fMXgsEjDQ QyZA== X-Gm-Message-State: AHQUAuZteIp9xyRSdnI/AHnSp3KNJm7ZHLHTbfdfxS5Z9/AuRQJe/Jad zinyp6LAevEl7b0066uGUKE4MPxp/W0= X-Received: by 2002:a63:1a5f:: with SMTP id a31mr4650129pgm.335.1549155399587; Sat, 02 Feb 2019 16:56:39 -0800 (PST) Received: from myunghoj-Precision-5530 (cpe-76-176-3-80.san.res.rr.com. [76.176.3.80]) by smtp.gmail.com with ESMTPSA id h64sm18341455pfc.142.2019.02.02.16.56.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Feb 2019 16:56:39 -0800 (PST) Date: Sat, 2 Feb 2019 16:56:36 -0800 From: Myungho Jung To: Marcel Holtmann , Johan Hedberg , "David S. Miller" Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: Fix decrementing reference count twice in releasing socket Message-ID: <20190203005634.GA19908@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When releasing socket, it is possible to enter hci_sock_release() and hci_sock_dev_event(HCI_DEV_UNREG) at the same time in different thread. The reference count of hdev should be decremented only once from one of them but if storing hdev to local variable in hci_sock_release() before detached from socket and setting to NULL in hci_sock_dev_event(), hci_dev_put(hdev) is unexpectedly called twice. This is resolved by referencing hdev from socket after bt_sock_unlink() in hci_sock_release(). Reported-by: syzbot+fdc00003f4efff43bc5b@syzkaller.appspotmail.com Signed-off-by: Myungho Jung --- net/bluetooth/hci_sock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 1506e1632394..d4e2a166ae17 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -831,8 +831,6 @@ static int hci_sock_release(struct socket *sock) if (!sk) return 0; - hdev = hci_pi(sk)->hdev; - switch (hci_pi(sk)->channel) { case HCI_CHANNEL_MONITOR: atomic_dec(&monitor_promisc); @@ -854,6 +852,7 @@ static int hci_sock_release(struct socket *sock) bt_sock_unlink(&hci_sk_list, sk); + hdev = hci_pi(sk)->hdev; if (hdev) { if (hci_pi(sk)->channel == HCI_CHANNEL_USER) { /* When releasing a user channel exclusive access, -- 2.17.1