From patchwork Tue Sep 29 10:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 290735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75C0FC4727C for ; Tue, 29 Sep 2020 12:44:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EFE22076A for ; Tue, 29 Sep 2020 12:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601383458; bh=73XmBbL5kBfw8v5hmI7Y6kgq/EvxjfR/wQnjwChQaPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kVdf9BLe405Dhcnr+PEBfHltwtd0Ob0LNSDGLt9WG/rX1VigwSM7Itmv4Lzp7taE6 8zff9Lw3SdmEmK9Drrsetp0r0NL0F0IFzWzE0v/M6J5f6SZT6SbC7YjQH1rkjodGxT QyNXBDUt65rYck/04cuyGT6GF011qvyL2XuK6Tn0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbgI2MoQ (ORCPT ); Tue, 29 Sep 2020 08:44:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:47402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgI2LIe (ORCPT ); Tue, 29 Sep 2020 07:08:34 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4EE323444; Tue, 29 Sep 2020 11:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377701; bh=73XmBbL5kBfw8v5hmI7Y6kgq/EvxjfR/wQnjwChQaPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oJRD7ZE9r6UryA3LIE7JsqkuytPy2D+YhcDrkIEBS5xItDoOmQUcdTX5cN3soVUmn nhNNjVGcPt/l7/xcvF/RVObSPxw/RY/kzjiWuOa2/R/XJekuxbECSA0t6wbpr3x6ej LBYVe3Q/Nh6290r8iRC/nf+Y+xYWyaCXhL6uZVdI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c3c5bdea7863886115dc@syzkaller.appspotmail.com, Manish Mandlik , Hillf Danton , Marcel Holtmann , Sasha Levin Subject: [PATCH 4.9 041/121] Bluetooth: prefetch channel before killing sock Date: Tue, 29 Sep 2020 12:59:45 +0200 Message-Id: <20200929105932.226731099@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hillf Danton [ Upstream commit 2a154903cec20fb64ff4d7d617ca53c16f8fd53a ] Prefetch channel before killing sock in order to fix UAF like BUG: KASAN: use-after-free in l2cap_sock_release+0x24c/0x290 net/bluetooth/l2cap_sock.c:1212 Read of size 8 at addr ffff8880944904a0 by task syz-fuzzer/9751 Reported-by: syzbot+c3c5bdea7863886115dc@syzkaller.appspotmail.com Fixes: 6c08fc896b60 ("Bluetooth: Fix refcount use-after-free issue") Cc: Manish Mandlik Signed-off-by: Hillf Danton Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_sock.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 3db8cfebd069a..bbf08c6092f4a 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1189,6 +1189,7 @@ static int l2cap_sock_release(struct socket *sock) { struct sock *sk = sock->sk; int err; + struct l2cap_chan *chan; BT_DBG("sock %p, sk %p", sock, sk); @@ -1198,15 +1199,16 @@ static int l2cap_sock_release(struct socket *sock) bt_sock_unlink(&l2cap_sk_list, sk); err = l2cap_sock_shutdown(sock, 2); + chan = l2cap_pi(sk)->chan; - l2cap_chan_hold(l2cap_pi(sk)->chan); - l2cap_chan_lock(l2cap_pi(sk)->chan); + l2cap_chan_hold(chan); + l2cap_chan_lock(chan); sock_orphan(sk); l2cap_sock_kill(sk); - l2cap_chan_unlock(l2cap_pi(sk)->chan); - l2cap_chan_put(l2cap_pi(sk)->chan); + l2cap_chan_unlock(chan); + l2cap_chan_put(chan); return err; }