Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2267065pxb; Sat, 28 Aug 2021 09:19:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmLVzsL4KvhHQE+RetRcK/v6otDYerKkX/JWCF8IME+tT51A2XL7Mdo1r+/SMuBsgwHz3f X-Received: by 2002:a92:440f:: with SMTP id r15mr9936138ila.51.1630167560802; Sat, 28 Aug 2021 09:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630167560; cv=none; d=google.com; s=arc-20160816; b=H3DljXo2k1xr8lcIYpHsFcfzFqpNakClTEaF/mUYy0BVs21L6pjaqZLwU+pJdZXmNt c12ykeBAXPuUMESgl9B4Z/uHCKWC8BhqYwu3LAji3LABmjoSMqriv3eiN6t/eHZBIV0W J7FSNvois/ppdl7Vv3IFLnjicehFEBm4YBmHSFhDBpA4+2+KR6D9gPw3wmEp1gWT5SmQ V3THd3et3lP5EJrOlQliX7BsFcWFfzquczL/Q3NSZ3Ze4RRmNIzvsR96a4zWFf9otwv4 vMwzluzCXTbxQmzH0VvtfWm6NZC25FUhkK+ubapBfLDbYGL8j04cqCm4mhOUARLpY4dI OmNg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=7NrJ+Jhr63Y03bd2F44uKUO8GeWKhPO5AxFymYb2r/Y=; b=Xm41Q6uxuukMCBEAb1hUVFPf+/1HnrqGZsrdZahtLiefx2oWrnUoV98uL2mPiVWrnI Fe6A7HtOyC1KOu6o63FBmU8mQOUmZphTghtH/0/DprNRHSYY3fpqUZmYHiOntputRUHA aK0EEVtRXlMQYdCyxJ766//g3zrdsSz65belD+PXD5zr/+JVYvMyA83Od9hQ0q3Jxnp1 u789/I1+Bg9cnyrzw25sCh5JV48H9q94Bl/AcCJCbJ0k86xVM148eeghiPVYET8t4nn+ lsknKci5I+5KZ+OOCmZ0FG7PraXF2N36tZ6l1o9kRgRpnC4LLio9hZyFltdAXLntaz63 MbYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=QFGFJAzT; dkim=neutral (no key) header.i=@suse.de header.b=0pA5JPxT; 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=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si8280705ilj.76.2021.08.28.09.19.08; Sat, 28 Aug 2021 09:19:20 -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=@suse.de header.s=susede2_rsa header.b=QFGFJAzT; dkim=neutral (no key) header.i=@suse.de header.b=0pA5JPxT; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbhH1QTR (ORCPT + 99 others); Sat, 28 Aug 2021 12:19:17 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:47556 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhH1QTN (ORCPT ); Sat, 28 Aug 2021 12:19:13 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 48C142216D; Sat, 28 Aug 2021 16:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1630167502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7NrJ+Jhr63Y03bd2F44uKUO8GeWKhPO5AxFymYb2r/Y=; b=QFGFJAzTU9QMlsLhfBkgnewcQrt7Y5lLid8CoeSLHXRfYp4HnsTWL5Uwe2oArxxlXXU1Tf 0Qu1iNS1M+fufqLQ4cwZ6lX59eekJkwo0Q9i2ZgjACNqXaTPJOlAFEOSQ8TUh+XbtYE8YW YNPUlxCHqadOg3emwWoEILOEKbIrBno= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1630167502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7NrJ+Jhr63Y03bd2F44uKUO8GeWKhPO5AxFymYb2r/Y=; b=0pA5JPxTwbSi82qoLUOigRp7QS6I6qVGlSgTHqE+7BYixdOJSzpaO4jxHY2gfJItV+iyfL GCuk5aL/ACqHlpDA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 30AF0A3B9D; Sat, 28 Aug 2021 16:18:22 +0000 (UTC) From: Takashi Iwai To: Luiz Augusto von Dentz Cc: Marcel Holtmann , Johan Hedberg , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: sco: Fix lock_sock() blockage by memcpy_from_msg() Date: Sat, 28 Aug 2021 18:18:18 +0200 Message-Id: <20210828161818.31141-1-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sco_send_frame() also takes lock_sock() during memcpy_from_msg() call that may be endlessly blocked by a task with userfaultd technique, and this will result in a hung task watchdog trigger. Just like the similar fix for hci_sock_sendmsg() in commit 92c685dc5de0 ("Bluetooth: reorganize functions..."), this patch moves the memcpy_from_msg() out of lock_sock() for addressing the hang. This should be the last piece for fixing CVE-2021-3640 after a few already queued fixes. Signed-off-by: Takashi Iwai --- net/bluetooth/sco.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 98a881586512..687e05718aad 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -280,7 +280,8 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk) return err; } -static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) +static int sco_send_frame(struct sock *sk, void *buf, int len, + unsigned int msg_flags) { struct sco_conn *conn = sco_pi(sk)->conn; struct sk_buff *skb; @@ -292,15 +293,11 @@ static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) BT_DBG("sk %p len %d", sk, len); - skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err); + skb = bt_skb_send_alloc(sk, len, msg_flags & MSG_DONTWAIT, &err); if (!skb) return err; - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { - kfree_skb(skb); - return -EFAULT; - } - + memcpy(skb_put(skb, len), buf, len); hci_send_sco(conn->hcon, skb); return len; @@ -725,6 +722,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { struct sock *sk = sock->sk; + void *buf; int err; BT_DBG("sock %p, sk %p", sock, sk); @@ -736,14 +734,23 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + if (memcpy_from_msg(buf, msg, len)) { + kfree(buf); + return -EFAULT; + } + lock_sock(sk); if (sk->sk_state == BT_CONNECTED) - err = sco_send_frame(sk, msg, len); + err = sco_send_frame(sk, buf, len, msg->msg_flags); else err = -ENOTCONN; release_sock(sk); + kfree(buf); return err; } -- 2.26.2