linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Archie Pusaka <apusaka@chromium.org>,
	syzbot+abfc0f5e668d4099af73@syzkaller.appspotmail.com,
	Alain Michaud <alainm@chromium.org>,
	Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 10/25] Bluetooth: check for zapped sk before connecting
Date: Wed,  5 May 2021 12:40:36 -0400	[thread overview]
Message-ID: <20210505164051.3464020-10-sashal@kernel.org> (raw)
In-Reply-To: <20210505164051.3464020-1-sashal@kernel.org>

From: Archie Pusaka <apusaka@chromium.org>

[ 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 <apusaka@chromium.org>
Reported-by: syzbot+abfc0f5e668d4099af73@syzkaller.appspotmail.com
Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 f94b14beba2b..3905af1d300f 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


  parent reply	other threads:[~2021-05-05 17:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 16:40 [PATCH AUTOSEL 4.14 01/25] fs: dlm: fix debugfs dump Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 02/25] tipc: convert dest node's address to network order Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 03/25] net: stmmac: Set FIFO sizes for ipq806x Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 04/25] ALSA: hdsp: don't disable if not enabled Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 05/25] ALSA: hdspm: " Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 06/25] ALSA: rme9652: " Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 07/25] Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 08/25] Bluetooth: verify AMP hci_chan before amp_destroy Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 09/25] Bluetooth: initialize skb_queue_head at l2cap_chan_create() Sasha Levin
2021-05-05 16:40 ` Sasha Levin [this message]
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 11/25] ip6_vti: proper dev_{hold|put} in ndo_[un]init methods Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 12/25] mac80211: clear the beacon's CRC after channel switch Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 13/25] pinctrl: samsung: use 'int' for register masks in Exynos Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 14/25] cuse: prevent clone Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 15/25] selftests: Set CC to clang in lib.mk if LLVM is set Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 16/25] kconfig: nconf: stop endless search loops Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 17/25] sctp: Fix out-of-bounds warning in sctp_process_asconf_param() Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 18/25] powerpc/smp: Set numa node before updating mask Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 19/25] ASoC: rt286: Generalize support for ALC3263 codec Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 20/25] samples/bpf: Fix broken tracex1 due to kprobe argument change Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 21/25] powerpc/pseries: Stop calling printk in rtas_stop_self() Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 22/25] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 23/25] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 24/25] powerpc/iommu: Annotate nested lock for lockdep Sasha Levin
2021-05-05 16:40 ` [PATCH AUTOSEL 4.14 25/25] net: ethernet: mtk_eth_soc: fix RX VLAN offload Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505164051.3464020-10-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=abhishekpandit@chromium.org \
    --cc=alainm@chromium.org \
    --cc=apusaka@chromium.org \
    --cc=groeck@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+abfc0f5e668d4099af73@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).