Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2488887lqp; Sun, 24 Mar 2024 23:13:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUd0g+2xESD+5z/tq7O3TfYx1B4aDXeQLNrDTP9tjxPhxHR1sw0iOm0eqd459/CyYGGP8Of0yRHPhW0iivcFT/uioh37CUouMs8mwv1PQ== X-Google-Smtp-Source: AGHT+IEZUdbKwinjP0Mg30vR51aOI8zTKVGdklqIljKISZOQpKquP2v/r7Nz0ugk0wsDiyTeleR3 X-Received: by 2002:a37:c201:0:b0:78a:2945:8658 with SMTP id i1-20020a37c201000000b0078a29458658mr6295953qkm.33.1711347213480; Sun, 24 Mar 2024 23:13:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347213; cv=pass; d=google.com; s=arc-20160816; b=elIU7hZJhClCon2dk+F71rG5azwWF2OQ7QYKDacIsOLz3gtaj+BOYcEZk0qSfQdqZR hWdUj/I+AFTbV/Sxgv0ihLG3dKQ0mKXbFJiDPFiQletmFaw9zYwsNVd1pnuInKAR7iOT KUzUHG4E3+tFhjgvAiaL+6d0MFllRITHPVvuFIQvPYc2mDvhzjE2UB7P6ITVwknBNEai 5GhMic/WZyeChaMPNDTG/3Mvp6W4lgEmY+dJnnkKHJkctdWudxA6kKTW+HxLj8oQzqEj 0ccnh8XEQBIePM0cSuyuaenasKLZ9ev5YAocRqdu1/KsLjwQUvg6Vyj0W32Q8YUQaMe1 kdrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QWnzBFyK0cO9YMDz34Zsp0RmbcC03/NAdOokWTAFq5g=; fh=/TnrLxI5sd/8bhOUk5NCak+Scug04k+QZYgHCAWUD88=; b=utXWlNatwRXzc0u3Sj1S3ikxxtgd3udbxGxQgPbe54/iySNGIbLtkhdIzDjRGJ+mmn V04U+U92tE0pDd+qr9us5dhlQs1CVivnYxn7e10guH7yTX2IrD8bPcInp+p4LFMKComQ QUqZ1uPk0d2bAen4W4OvNqCeydqJ6cxTvBA3zWegTmIoGwtmTruCkCVHP6Qdt2i5oALm +3C88FPClCgwjeKIrBR4Ua4fJj/WzMPVCOMebJIvui72tOj2X7mi1VD44XDw8ODZW5CE Pu+x0dcLOzjtLl99Ov7p3KGmhEBVty79kLM2Dm/3+WI7ljuOa84x0oh4CzI5IdJ6xI9y OajQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F5FB8nBI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ow24-20020a05620a821800b00789dc60c293si4731622qkn.708.2024.03.24.23.13.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:13:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F5FB8nBI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 396391C2BEAB for ; Mon, 25 Mar 2024 06:13:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 399EF181467; Sun, 24 Mar 2024 23:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F5FB8nBI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B6DC1FB061; Sun, 24 Mar 2024 23:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322129; cv=none; b=XRtgnuqnt6/h1LqU46fZMJQ/1+nnPy2uqxeNeuug3bdm0TB3+F1YVMeLFnHVnAfC3ambpjfiwzy+kbhQGNGRgV6FykQSzCODW7l/rRrlHLzh7ODtjK2LhGSy/Fnhcy3qIu0H99BDQNRX6mpkbWo1kYTzAzEDd9HnbA10AbYzn7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322129; c=relaxed/simple; bh=qZZ0B7thLND9AEuPjl/d4QKT00pV/e/qqEebBteDWf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tUKDAFD7aKS4vUYwhSJuy6QHJdsVq4SveoeiobTWUJzPbDI/6YN/EJuhk3SMo+ikWeMmUYnvDyNUpNOTZ51W0s2ZggMH860XXIrKna7ddD+rLacuBWqMuMjNlHeso7YYMY6EUagl9JItE+9znElAA58+rX2ZYtiGOjr84E0w8Xs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F5FB8nBI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78466C43330; Sun, 24 Mar 2024 23:15:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322128; bh=qZZ0B7thLND9AEuPjl/d4QKT00pV/e/qqEebBteDWf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F5FB8nBIOYJJN+uXW5PXeTfGPPOPa1SwicUM8Q0GMQaU51WE3/IfxqZO1X+i0DLc3 o0SDnTTcLdQFNVF3IDeJuxL/4k+W++VzHjEEJd8nSifEp6ddYJ4+eeikTRmWOd8gjq 2dRKTbOFSza/PEWf3I2t2XFTmQsbAo2FMVm3HZoeDUGThQ8fE9I13wQbRExfAZbh3h 38N5os/73jYkYHPxNo5dj3ClXBWBzf1lwglXQNVDcqdzP+d93bpe27CPgNfDUT1eob NDsg/JTxUF7N0+BoxEfymePDmBZ2nQPYwx+vGWSwn4DkAJGagApUuIYwAFoMfINGjE Sw8+9lB1RGlCg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.1 204/451] Bluetooth: af_bluetooth: Fix deadlock Date: Sun, 24 Mar 2024 19:08:00 -0400 Message-ID: <20240324231207.1351418-205-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz [ Upstream commit f7b94bdc1ec107c92262716b073b3e816d4784fb ] Attemting to do sock_lock on .recvmsg may cause a deadlock as shown bellow, so instead of using sock_sock this uses sk_receive_queue.lock on bt_sock_ioctl to avoid the UAF: INFO: task kworker/u9:1:121 blocked for more than 30 seconds. Not tainted 6.7.6-lemon #183 Workqueue: hci0 hci_rx_work Call Trace: __schedule+0x37d/0xa00 schedule+0x32/0xe0 __lock_sock+0x68/0xa0 ? __pfx_autoremove_wake_function+0x10/0x10 lock_sock_nested+0x43/0x50 l2cap_sock_recv_cb+0x21/0xa0 l2cap_recv_frame+0x55b/0x30a0 ? psi_task_switch+0xeb/0x270 ? finish_task_switch.isra.0+0x93/0x2a0 hci_rx_work+0x33a/0x3f0 process_one_work+0x13a/0x2f0 worker_thread+0x2f0/0x410 ? __pfx_worker_thread+0x10/0x10 kthread+0xe0/0x110 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2c/0x50 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1b/0x30 Fixes: 2e07e8348ea4 ("Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/af_bluetooth.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index f1b7510359e4b..3f9ff02baafe3 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c @@ -264,14 +264,11 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, if (flags & MSG_OOB) return -EOPNOTSUPP; - lock_sock(sk); - skb = skb_recv_datagram(sk, flags, &err); if (!skb) { if (sk->sk_shutdown & RCV_SHUTDOWN) err = 0; - release_sock(sk); return err; } @@ -297,8 +294,6 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, skb_free_datagram(sk, skb); - release_sock(sk); - if (flags & MSG_TRUNC) copied = skblen; @@ -521,10 +516,11 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) if (sk->sk_state == BT_LISTEN) return -EINVAL; - lock_sock(sk); + spin_lock(&sk->sk_receive_queue.lock); skb = skb_peek(&sk->sk_receive_queue); amount = skb ? skb->len : 0; - release_sock(sk); + spin_unlock(&sk->sk_receive_queue.lock); + err = put_user(amount, (int __user *)arg); break; -- 2.43.0