Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp349572pxj; Thu, 20 May 2021 10:42:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuoDUOeM3CcO/fr5g8GmtFh4cZxmHQXeqvnAvdpUWJqSZ2xXt+JDOARPQYT9V//KB6IllD X-Received: by 2002:a02:ca4b:: with SMTP id i11mr7442415jal.77.1621532574438; Thu, 20 May 2021 10:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621532574; cv=none; d=google.com; s=arc-20160816; b=PPLCVc7nPueJBdTCFcw3LhhKoKoD9jeUqNu7cFTvmvTruHutyNpMWW2CimiheRjTRY umh6vEG0g52KqdAdFiAaI3geu3x1sTyf0cPEBK8hxxolFEWif00fHZR71mu4l0G6xZxc 3+MrpC1Dw38MpTZEfrqZyAnDuEtgn+EhjU3kweNx3bIV+yvv9bHKgRF2XO+5vhEp3VBp ewm5z8Hrp/622YC95MUS0E2sSgVOL+upXjOgcsbogzo84YFKd6Cmqeq3ZYafyZnAYpmS kN4Nd3zP2QRURcvaPlulbJYfNrcImdaZZOT+yTExdI82dVnZCLqh+WgF0K6BcH7iBJ7A tU9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JPF0E+BvA5iHhGLG5lDHY1XF2VXHR8Zbk2RYL8zpMto=; b=RdVV+KWmPOlW3Kz6Qw6huj8ZhE9X+MWVW/3BmIVqYej1mNdb99PxhDLOYoUdlv99gW LNsUipjwkMMYz9lk29C5zGUlrLANLCIHCc+icK3VbsxAGirC/VBzJnx7JsjKEbXOarwf RZqjsAm7KMigodof9toOknTxZBKpW+lOAYybIqcbc1nU/4pSEuObwTNCbdQEaHk2oPZM PFf3FMngBNf48y/oWnm1j3Lbb6RHhCxW9zetIwEj6D2mCbBQpGFqsog3a4SOloB/kx5R 1bby6uhM6LLWPMrBSQLDdVvOgTUVk+nBACgrFj8Q5p4vFVVbwblLYeCdU+SqJTL4DqPM bKYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rYa34mnk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si2655672jao.56.2021.05.20.10.42.40; Thu, 20 May 2021 10:42:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rYa34mnk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235287AbhETKLQ (ORCPT + 99 others); Thu, 20 May 2021 06:11:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235279AbhETKE3 (ORCPT ); Thu, 20 May 2021 06:04:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D301D61927; Thu, 20 May 2021 09:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503641; bh=0dIJKS4UC7v5gw3yjyaVhZX8A5MKJ3Mh1iBpxzsJ3W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rYa34mnk+d6JC7A3Mx6LROpJ3IQusjkpCrmJlyPZ6P486i1+X0104rXZaVKagstkK GjbFjv5w/aP9WtmdyJplDNXz4sJ3kLaf4GtwO+YlMNeMNEMB3yNe4YBcLLNNQi9PhZ 0b3bkn1FLMrBseIswY3gOAc0hw/eRyP1AkMp6f9k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Archie Pusaka , syzbot+abfc0f5e668d4099af73@syzkaller.appspotmail.com, Alain Michaud , Abhishek Pandit-Subedi , Guenter Roeck , Marcel Holtmann , Sasha Levin Subject: [PATCH 4.19 313/425] Bluetooth: check for zapped sk before connecting Date: Thu, 20 May 2021 11:21:22 +0200 Message-Id: <20210520092141.722766845@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Archie Pusaka [ Upstream commit 3af70b39fa2d415dc86c370e5b24ddb9fdacbd6f ] There is a possibility of receiving a zapped sock on l2cap_sock_connect(). This could lead to interesting crashes, one such case is tearing down an already tore l2cap_sock as is happened with this call trace: __dump_stack lib/dump_stack.c:15 [inline] dump_stack+0xc4/0x118 lib/dump_stack.c:56 register_lock_class kernel/locking/lockdep.c:792 [inline] register_lock_class+0x239/0x6f6 kernel/locking/lockdep.c:742 __lock_acquire+0x209/0x1e27 kernel/locking/lockdep.c:3105 lock_acquire+0x29c/0x2fb kernel/locking/lockdep.c:3599 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:137 [inline] _raw_spin_lock_bh+0x38/0x47 kernel/locking/spinlock.c:175 spin_lock_bh include/linux/spinlock.h:307 [inline] lock_sock_nested+0x44/0xfa net/core/sock.c:2518 l2cap_sock_teardown_cb+0x88/0x2fb net/bluetooth/l2cap_sock.c:1345 l2cap_chan_del+0xa3/0x383 net/bluetooth/l2cap_core.c:598 l2cap_chan_close+0x537/0x5dd net/bluetooth/l2cap_core.c:756 l2cap_chan_timeout+0x104/0x17e net/bluetooth/l2cap_core.c:429 process_one_work+0x7e3/0xcb0 kernel/workqueue.c:2064 worker_thread+0x5a5/0x773 kernel/workqueue.c:2196 kthread+0x291/0x2a6 kernel/kthread.c:211 ret_from_fork+0x4e/0x80 arch/x86/entry/entry_64.S:604 Signed-off-by: Archie Pusaka Reported-by: syzbot+abfc0f5e668d4099af73@syzkaller.appspotmail.com Reviewed-by: Alain Michaud Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Guenter Roeck Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_sock.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 198a1fdd6709..967a9bb14415 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -179,9 +179,17 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, struct l2cap_chan *chan = l2cap_pi(sk)->chan; struct sockaddr_l2 la; int len, err = 0; + bool zapped; BT_DBG("sk %p", sk); + lock_sock(sk); + zapped = sock_flag(sk, SOCK_ZAPPED); + release_sock(sk); + + if (zapped) + return -EINVAL; + if (!addr || alen < offsetofend(struct sockaddr, sa_family) || addr->sa_family != AF_BLUETOOTH) return -EINVAL; -- 2.30.2