Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2378211lqp; Sun, 24 Mar 2024 16:44:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9oGImYRrFupUlT83XXxzuU4r0rMD8m/yV9k+qE7vGv51VzkNFYjZnzeVpLQTDHmPGDNUpUwz2ZPXpGXJ9MjCH/OC7AjjUAjhdPXw8RA== X-Google-Smtp-Source: AGHT+IGDos9ThXSHbT6I0b7s2e2A8mc4v4tSTJqkiY9prthlW1y+cot7kpi++cyv95VdSYHjI9Pv X-Received: by 2002:a17:907:86ab:b0:a47:4116:46ac with SMTP id qa43-20020a17090786ab00b00a47411646acmr4816623ejc.13.1711323847180; Sun, 24 Mar 2024 16:44:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711323847; cv=pass; d=google.com; s=arc-20160816; b=KllvZ+9rsP9x9k72G8pOYHjoRWPBDxOwYjDhUIqL4M7hGUEka5yYUin7s38ai5PebJ js5ya2aQI6c9xogVJr1c2B0O4fdPJvQRPLocHE6XMPCImbWjO0ZvJTxDaIO60LdOjJv0 GGz+0NvMsq3f5TJ2j8nbGoZuwUHqfIkw0V7tjQ4uYxpNpdBRS86kDKqZ3cWQ1ALkKzjM Ym9+QIHfjb6FrenQ4ZYaGNmG7n5lbDkBvJeVe+IwVeL2d9mo5kCCym/5EIvaDfUGCc1j S8Yq0XcwkVRXM5Igm3lLgdC6VWCO2S9/BhCKv0v4uKUBrZ0+HJQnqjNYzhFIBMm1Z1H9 FXeQ== 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=c38yApA1Tu5Sv+XTIASXcwo/e+IvtWiC70hXC9CoR8M=; fh=/TnrLxI5sd/8bhOUk5NCak+Scug04k+QZYgHCAWUD88=; b=t4Is85RRBEHrtnbT3b6lX761S373TvbgjyqvaJCQFoqNe4zsK2lwWa/wnPkS8TRjZ4 jF6geo3hXzGzlJsPSkyib65SyxH4ZkRJd0b1sKHUucqqWfIjO0MaFJqyDvcPLhtoj6X7 BzGXsY7YT378LQ3zAry8TKo7ko70W6A4eddnUTFL1Sep3+4njxMqQ9j+czXNUxArprUX 33trybZFJMe7W3VlVCNQ3WhhecfC7s/EehKKr1bEcudfdU8kP1uBDbM4sW1ISgW+JJq4 rDZQ0ax5r2fjc1bOYIi9Pz4+Ki7RA6XAgPgH6dVu6Febsi0t5/dCshxqnwkjSCpWpH12 EvOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hdLNKv+F; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113206-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113206-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id mf21-20020a170906cb9500b00a444b9d37b9si1893726ejb.408.2024.03.24.16.44.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113206-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hdLNKv+F; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113206-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113206-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E5A4D1F21AC2 for ; Sun, 24 Mar 2024 23:44:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29612131BAD; Sun, 24 Mar 2024 22:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hdLNKv+F" 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 1BECA17D23D; Sun, 24 Mar 2024 22:40:08 +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=1711320008; cv=none; b=J+P3PTdiHD1ZtOahkO9WxOSA2FOeol+z9oqYePeD3XIUKy3rDMfCW5Odc+xjDda+j6ps2rbhIvc165MKs4V0ec7HsP4n5zmAurOchllYum+rCdqrbkpHIKCoej/2FEEfYwhqSbx1Ov+rTyLqZdXQ8vLuX6JPJ5j7yem2ZWZUM1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320008; c=relaxed/simple; bh=8Mq+y2b4QoasCHiS9C0t/oVV7yRpu9gPxY4aigJk7HQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vGOWTShb7N2HBBoxtORLH+ndwZZwaqKmx55hHOsWslxQG+HntHwErVqCl27M32upYsqL8sF8sgbm0/vS1UrU7nFpPcmFS1N0P/ueBjw2ot4gDcEOevTgdtDPTZSM7m3BEqHaJw4n/HIqAS7zQUVT4lhm8h772h/USTk5zrv1hZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hdLNKv+F; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FD2BC433A6; Sun, 24 Mar 2024 22:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320008; bh=8Mq+y2b4QoasCHiS9C0t/oVV7yRpu9gPxY4aigJk7HQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdLNKv+Fi6ObKyk/2ACijgBidyNUF2KE3YJA+uZZSWpDzzEPc3xlUYRCz2RfAcfoo aTuL3eHyJTHQPJD3c5OyX3q8zMcaoGdeuFxBiAfjBJOOisx46Fm+McPhbL6p/P9Mi4 wF9qkebJa+5JpM/Vhw9at2mIcjuA4TiAibmShK45T0B/6z3iZYRRh4vqNtyLJigLmS bgTA5a2xaw153hBzmGy8csPWjVI3f3UEpgA+AB8uCrxUN+nMRLzFPgsUVxL1UJGF2O LGdNgiwkLihA2u4v4nwmH/mvH7bFyN8ftS2/HMZSdc0ZSOnXSd9EBk38XpikT4abRh Ke5xFxU7UNCTA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.8 315/715] Bluetooth: af_bluetooth: Fix deadlock Date: Sun, 24 Mar 2024 18:28:14 -0400 Message-ID: <20240324223455.1342824-316-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 b93464ac3517f..67604ccec2f42 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c @@ -309,14 +309,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; } @@ -346,8 +343,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; @@ -570,10 +565,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