From patchwork Mon Oct 28 07:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQlc0Jvnz1xxV for ; Mon, 28 Oct 2024 18:59:39 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Kex-0005J9-UH; Mon, 28 Oct 2024 07:59:31 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Kev-0005GB-BL for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:29 +0000 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 140793F175 for ; Mon, 28 Oct 2024 07:59:29 +0000 (UTC) Received: by mail-il1-f200.google.com with SMTP id e9e14a558f8ab-3a3b2aee1a3so38385215ab.1 for ; Mon, 28 Oct 2024 00:59:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102367; x=1730707167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=63hIU2PA/t/d4o9u2fAS6HUYj/dxJq9DZoHJc3INyVY=; b=mPeOY3MtE71BWUFexsodS/iLvHpnzZk8XXH8zvZh49wbZDbBsdn1lglBbSNMtlm+wl xfpgQi0kYFTswzzwojP6xPdAxq1952HYltEmlbBQOHvIfz+GJwnJJpRqF2CEjIWWhrB7 s6HXsZBJDmjlNmO7aKczTeUb2DCrBDW6Xquc7SFqvPKqz13qH+D5rTJdimOZsE+o6Urs YzLZzjy2c+k4B6VSXKEyzW69R/IejG8gtujgNqFAjt1zumqvUMa3b68Fxa/DsTCBy3YP bNGtggnxJQMUiGSmNg9OBZmM7bixYdDbA9Q7KEI1SS6E1GgfyU4MrYC7xtm1opg+p3Sg S6PQ== X-Gm-Message-State: AOJu0YyMJc6o3FfC+78H+Yrv0PP6UR8V2KSJUE46WdBazi9VzQ8pkLs7 uJfF7wYXXu5tWZ1NNUf5oI1OFr9cLhS1pGZ7/sV+cpz8aTbdcjaaBf49LJXeBfDfs/atFFfKYnV 3prJpCZ/owv+2OHuEzWsd4FPTRsctu0y9OMNOhrNBImlF+yb8YwtfsuWOaTfXLk3rOCtHJT1A4J LhQFaH1vxCKA== X-Received: by 2002:a05:6e02:1c01:b0:3a3:4175:79da with SMTP id e9e14a558f8ab-3a4ed2b0af4mr58387295ab.13.1730102367542; Mon, 28 Oct 2024 00:59:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfzNW6M/7Js79kbgEqwCPCcpihv4isl0110l1siu18EMYAcpLP1fnPBohnaJrNCiFqMSdNMg== X-Received: by 2002:a05:6e02:1c01:b0:3a3:4175:79da with SMTP id e9e14a558f8ab-3a4ed2b0af4mr58387225ab.13.1730102367115; Mon, 28 Oct 2024 00:59:27 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:26 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/4] Bluetooth: SCO: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:58:52 +0900 Message-ID: <20241028075902.114546-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit 51eda36d33e43201e7a4fd35232e069b2c850b01 ] syzbot reported sco_sock_setsockopt() is copying data without checking user input length. BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in sco_sock_setsockopt+0xc0b/0xf90 net/bluetooth/sco.c:893 Read of size 4 at addr ffff88805f7b15a3 by task syz-executor.5/12578 Fixes: ad10b1a48754 ("Bluetooth: Add Bluetooth socket voice option") Fixes: b96e9c671b05 ("Bluetooth: Add BT_DEFER_SETUP option to sco socket") Fixes: 00398e1d5183 ("Bluetooth: Add support for BT_PKT_STATUS CMSG data for SCO connections") Fixes: f6873401a608 ("Bluetooth: Allow setting of codec for HFP offload use case") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (cherry picked from commit b0e30c37695b614bee69187f86eaf250e36606ce linux-5.10.y) CVE-2024-35967 Signed-off-by: Koichiro Den --- include/net/bluetooth/bluetooth.h | 9 +++++++++ net/bluetooth/sco.c | 19 ++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 355835639ae5..7d2bd562da4b 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -487,6 +487,15 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk, return skb; } +static inline int bt_copy_from_sockptr(void *dst, size_t dst_size, + sockptr_t src, size_t src_size) +{ + if (dst_size > src_size) + return -EINVAL; + + return copy_from_sockptr(dst, src, dst_size); +} + int bt_to_errno(u16 code); void hci_sock_set_flag(struct sock *sk, int nr); diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 7d2c6b42b432..743d1df09c14 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -829,7 +829,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen) { struct sock *sk = sock->sk; - int len, err = 0; + int err = 0; struct bt_voice voice; u32 opt; @@ -845,10 +845,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt) set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); @@ -865,11 +864,10 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, voice.setting = sco_pi(sk)->setting; - len = min_t(unsigned int, sizeof(voice), optlen); - if (copy_from_sockptr(&voice, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&voice, sizeof(voice), optval, + optlen); + if (err) break; - } /* Explicitly check for these values */ if (voice.setting != BT_VOICE_TRANSPARENT && @@ -882,10 +880,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, break; case BT_PKT_STATUS: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt) sco_pi(sk)->cmsg_mask |= SCO_CMSG_PKT_STATUS; From patchwork Mon Oct 28 07:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQlc1Xgzz1xxY for ; Mon, 28 Oct 2024 18:59:39 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Key-0005JK-6I; Mon, 28 Oct 2024 07:59:32 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Kew-0005GY-LI for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:30 +0000 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 761E03F2A2 for ; Mon, 28 Oct 2024 07:59:30 +0000 (UTC) Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3e606c05b87so3553678b6e.2 for ; Mon, 28 Oct 2024 00:59:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102369; x=1730707169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0IPhtGnQMlLYiHZg4HICi6jCMC70ekL1ZTswxlhlQUI=; b=EI/Nsf2QAHQd9LI/QOh0e6D4pPHfdFapbMUsGv/DpsCzzLuY/hrDoXDTiWnuCr7pNg LTgfz52H5fPN9R6xElVnRHg2LEFLOr0V+JtZdQBDr6aO5ZX3BX+dLWx5cMS+a7xF7HZR XX2BsP4dro1DxuDrCkIoAHnAe2h2uI9pSfqmGHJtuNQ7K8o8+k9wNKY+vxfCMt5MeotZ 72AfKD6fKzsReQKYEB5wLDbdgjsRtZRzbNRVxyThaZIfdnQHsYWkZ5XexPei7283j6h+ PpOv0Y03v6suZJ5czBwqv9aiBF8PZ0ybar8yGrPO7LgdXqLBZDV3S04BWd3+42AO08lh aiUA== X-Gm-Message-State: AOJu0YxXs2ZUDXu6+nRDo8mtPhAvnx2zcqGQtwWnQP/J2qA9+f7kxjlL HMGYqSoBvxFPcvOv/mmToK0o+76CKOrN9Dx+pHlOprsK+SRb8wHmH84gHcACEwZNxN9Wgdeqa7d UV9LOTpvSRF4TxjNhnSk+h52yMvvHx7S+w7sftV2EreGJLwibhecc8/Pw+vgbf83vpvKdTLjeR8 Yw+IY32OVTew== X-Received: by 2002:a05:6808:219f:b0:3e6:16f7:9742 with SMTP id 5614622812f47-3e63848e130mr4906319b6e.33.1730102369197; Mon, 28 Oct 2024 00:59:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOmOoNFBYeuNvVlsY5PUrW3Y3qZ9n5LZETeutkaFd2GdX8ygMwGvvpMSeeiyzBhHxr1FX6aw== X-Received: by 2002:a05:6808:219f:b0:3e6:16f7:9742 with SMTP id 5614622812f47-3e63848e130mr4906304b6e.33.1730102368863; Mon, 28 Oct 2024 00:59:28 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:28 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 2/4] Bluetooth: RFCOMM: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:58:53 +0900 Message-ID: <20241028075902.114546-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit a97de7bff13b1cc825c1b1344eaed8d6c2d3e695 ] syzbot reported rfcomm_sock_setsockopt_old() is copying data without checking user input length. BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in rfcomm_sock_setsockopt_old net/bluetooth/rfcomm/sock.c:632 [inline] BUG: KASAN: slab-out-of-bounds in rfcomm_sock_setsockopt+0x893/0xa70 net/bluetooth/rfcomm/sock.c:673 Read of size 4 at addr ffff8880209a8bc3 by task syz-executor632/5064 Fixes: 9f2c8a03fbb3 ("Bluetooth: Replace RFCOMM link mode with security level") Fixes: bb23c0ab8246 ("Bluetooth: Add support for deferring RFCOMM connection setup") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (cherry picked from commit eea40d33bf936a5c7fb03c190e61e0cfee00e872 linux-6.1.y) CVE-2024-35966 Signed-off-by: Koichiro Den --- net/bluetooth/rfcomm/sock.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 4397e14ff560..c9bd5c7d6260 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -636,7 +636,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, switch (optname) { case RFCOMM_LM: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { + if (bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen)) { err = -EFAULT; break; } @@ -671,7 +671,6 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, struct sock *sk = sock->sk; struct bt_security sec; int err = 0; - size_t len; u32 opt; BT_DBG("sk %p", sk); @@ -693,11 +692,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, sec.level = BT_SECURITY_LOW; - len = min_t(unsigned int, sizeof(sec), optlen); - if (copy_from_sockptr(&sec, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&sec, sizeof(sec), optval, optlen); + if (err) break; - } if (sec.level > BT_SECURITY_HIGH) { err = -EINVAL; @@ -713,10 +710,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt) set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); From patchwork Mon Oct 28 07:58:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQlf5vvxz1xwF for ; Mon, 28 Oct 2024 18:59:42 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Kf1-0005Lp-Ft; Mon, 28 Oct 2024 07:59:35 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Key-0005J7-2D for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:32 +0000 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B50C53F175 for ; Mon, 28 Oct 2024 07:59:31 +0000 (UTC) Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-7180cb79f3cso4025427a34.3 for ; Mon, 28 Oct 2024 00:59:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102370; x=1730707170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8mslEOMKRjzk5YfxgtKhdiAqvEQHi3LbmwmXy2BDjx4=; b=JNV5vxiiKgYZPby+NzAZNlnMrWxDfWKGuosPLqcJC4b3bVCciIBetBtQaKvmASkuZd RxrsgvYp2SGq5hWYc0zU0hdZglHeTqxd8tYJcdalmbslzHpa0/PnW5R4ZB+54IqzPSrH x+h31E756SxMBkRpmSRSns9ipjmlzJhax+c52vbbxXEN3hSi+Cy8qImBt4Z3HHFhdpbs QKz0l+SllqlVidoQyTbZ3ZjpRHKMOexqo/cehJJYKi3+81CyUYtColPB859+e65RnsAU At4/K05pDXfbJgVtITm7Uqi7Dijzi8OxDW2Es+WQcmDQM7AMHeKH25xONKR0ZXkVF8pp KDig== X-Gm-Message-State: AOJu0YwyDMVzEdjFVijN0gqil5sQDsTWjDAxafZTVU24Y+LiHjH4TNId P7GxJyEdrox9l8XehCDbjdBwDS/kF26NDkurpPqL3fQhTq423VMKLTqo8PLXiHKPi+kCBSeOCzZ 2OVXKD5fC3vsGt3CC4UZEijhHVPLMOYiMr2cM/cr7hIuG+YChIXmXykfBjPGcy+fO4iFlnN5tfg ER1X5dC73IpA== X-Received: by 2002:a05:6830:611a:b0:714:fc39:6f2b with SMTP id 46e09a7af769-718682283e0mr6866917a34.16.1730102370483; Mon, 28 Oct 2024 00:59:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPrMGobBmPPVNnqYZTE4NELrldMl3memw/D8ikCg/Wfq6FgedRAvOGYpHBhB61Auj+nhCWjQ== X-Received: by 2002:a05:6830:611a:b0:714:fc39:6f2b with SMTP id 46e09a7af769-718682283e0mr6866894a34.16.1730102370057; Mon, 28 Oct 2024 00:59:30 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:29 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 3/4] Bluetooth: L2CAP: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:58:54 +0900 Message-ID: <20241028075902.114546-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit 4f3951242ace5efc7131932e2e01e6ac6baed846 ] Check user input length before copying data. Fixes: 33575df7be67 ("Bluetooth: move l2cap_sock_setsockopt() to l2cap_sock.c") Fixes: 3ee7b7cd8390 ("Bluetooth: Add BT_MODE socket option") Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (cherry picked from commit 9d42f373391211c7c8af66a3a316533a32b8a607 linux-6.1.y) CVE-2024-35965 Signed-off-by: Koichiro Den --- net/bluetooth/l2cap_sock.c | 52 +++++++++++++++----------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 3a2be1b4a574..93afa52c0466 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -745,7 +745,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, struct sock *sk = sock->sk; struct l2cap_chan *chan = l2cap_pi(sk)->chan; struct l2cap_options opts; - int len, err = 0; + int err = 0; u32 opt; BT_DBG("sk %p", sk); @@ -772,11 +772,9 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, opts.max_tx = chan->max_tx; opts.txwin_size = chan->tx_win; - len = min_t(unsigned int, sizeof(opts), optlen); - if (copy_from_sockptr(&opts, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opts, sizeof(opts), optval, optlen); + if (err) break; - } if (opts.txwin_size > L2CAP_DEFAULT_EXT_WINDOW) { err = -EINVAL; @@ -819,10 +817,9 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, break; case L2CAP_LM: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt & L2CAP_LM_FIPS) { err = -EINVAL; @@ -903,7 +900,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, struct bt_security sec; struct bt_power pwr; struct l2cap_conn *conn; - int len, err = 0; + int err = 0; u32 opt; u16 mtu; u8 mode; @@ -929,11 +926,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, sec.level = BT_SECURITY_LOW; - len = min_t(unsigned int, sizeof(sec), optlen); - if (copy_from_sockptr(&sec, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&sec, sizeof(sec), optval, optlen); + if (err) break; - } if (sec.level < BT_SECURITY_LOW || sec.level > BT_SECURITY_FIPS) { @@ -978,10 +973,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt) { set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); @@ -993,10 +987,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; case BT_FLUSHABLE: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt > BT_FLUSHABLE_ON) { err = -EINVAL; @@ -1028,11 +1021,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, pwr.force_active = BT_POWER_FORCE_ACTIVE_ON; - len = min_t(unsigned int, sizeof(pwr), optlen); - if (copy_from_sockptr(&pwr, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&pwr, sizeof(pwr), optval, optlen); + if (err) break; - } if (pwr.force_active) set_bit(FLAG_FORCE_ACTIVE, &chan->flags); @@ -1041,10 +1032,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; case BT_CHANNEL_POLICY: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt > BT_CHANNEL_POLICY_AMP_PREFERRED) { err = -EINVAL; @@ -1089,10 +1079,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&mtu, optval, sizeof(u16))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&mtu, sizeof(mtu), optval, optlen); + if (err) break; - } if (chan->mode == L2CAP_MODE_EXT_FLOWCTL && sk->sk_state == BT_CONNECTED) @@ -1120,10 +1109,9 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&mode, optval, sizeof(u8))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&mode, sizeof(mode), optval, optlen); + if (err) break; - } BT_DBG("mode %u", mode); From patchwork Mon Oct 28 07:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQlh2YnDz1xxV for ; Mon, 28 Oct 2024 18:59:44 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Kf2-0005NF-MK; Mon, 28 Oct 2024 07:59:36 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Kez-0005Kk-R4 for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:33 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 5448E3F2A2 for ; Mon, 28 Oct 2024 07:59:33 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-71e58fe926cso3787491b3a.3 for ; Mon, 28 Oct 2024 00:59:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102372; x=1730707172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I7YRyYTtwpFBHUgTlZCIqaaX5YEDjIYrkYEPvMOztDc=; b=C6ovvNVNnL+VOTper8X0+FDmJMNY48sdfHi6jNuvzi+J44c3+zuG3cnRyqP7dbLWWS WjoFhKN2gSwBrS1A9OMBorWPVqI8MWFzXQYMu8RJslDNovitdbqQMdvvIXj+6tdxXnDf Cd/doauRhyrA9ZBeaYHuRWvn20WUtym+ZdBzaAftfYrpKCwofllNU1Wgu2ik651wepFX qg211RTej+AYIPXae0TU/h3dWwK4XVB1k+74SEPT0+oyin8xkCHsXddngFOyyzEi7QNl jOCqZip4ENIpXYTJj0f0XJhdQ26su3kLTvkDpqUCKNqrJZeiG4ecBrV3uTMge1S3gye4 25Fg== X-Gm-Message-State: AOJu0Yyis9cvXaGikynronW4EtzD4BnBW+l7ef0COoocUA2Tl3vIDuZw zB3JHBbI4c3enNMUlqSdC+vlanb4j9O4iRBULgozbbq4lItxnHSEDhcc2JKBSf0LLTHFaq7Nqzy 6/O1u1KdXV6o+QPxF/ZLmlPUjnL6tW4y8G8Uv3wRPQwgQSCHbEJnoxVNzUSaaB83UoSLVk8jyVl BZg4G1+tWGaA== X-Received: by 2002:a05:6a00:3d0e:b0:71e:55e2:2c54 with SMTP id d2e1a72fcca58-72062fb8c93mr11992719b3a.12.1730102371688; Mon, 28 Oct 2024 00:59:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8oMllQDjBNfldkPUJ3Cwr1gUbPbnzw3viM4Mf4BnN32f9UGmtVhe6qjGv47bTIaB001Gymg== X-Received: by 2002:a05:6a00:3d0e:b0:71e:55e2:2c54 with SMTP id d2e1a72fcca58-72062fb8c93mr11992704b3a.12.1730102371283; Mon, 28 Oct 2024 00:59:31 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:31 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 4/4] Bluetooth: hci_sock: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:58:55 +0900 Message-ID: <20241028075902.114546-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit b2186061d6043d6345a97100460363e990af0d46 ] Check user input length before copying data. Fixes: 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (backported from commit 781f3a97a38a338bc893b6db7f9f9670bf1a9e37 linux-6.1.y) [koichiroden: Adjusted context due to missing commit 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")] CVE-2024-35963 Signed-off-by: Koichiro Den --- net/bluetooth/hci_sock.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 28222c7c098e..cc541e937116 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -1910,10 +1910,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, switch (optname) { case HCI_DATA_DIR: - if (copy_from_sockptr(&opt, optval, sizeof(opt))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len); + if (err) break; - } if (opt) hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR; @@ -1922,10 +1921,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, break; case HCI_TIME_STAMP: - if (copy_from_sockptr(&opt, optval, sizeof(opt))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len); + if (err) break; - } if (opt) hci_pi(sk)->cmsg_mask |= HCI_CMSG_TSTAMP; @@ -1943,11 +1941,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, uf.event_mask[1] = *((u32 *) f->event_mask + 1); } - len = min_t(unsigned int, len, sizeof(uf)); - if (copy_from_sockptr(&uf, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&uf, sizeof(uf), optval, len); + if (err) break; - } if (!capable(CAP_NET_RAW)) { uf.type_mask &= hci_sec_filter.type_mask; From patchwork Mon Oct 28 07:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQln5FHgz1xxV for ; Mon, 28 Oct 2024 18:59:49 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Kf8-0005WI-7T; Mon, 28 Oct 2024 07:59:42 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Kf7-0005UQ-5V for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:41 +0000 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CD0563F2A2 for ; Mon, 28 Oct 2024 07:59:40 +0000 (UTC) Received: by mail-il1-f197.google.com with SMTP id e9e14a558f8ab-3a3c90919a2so40049305ab.0 for ; Mon, 28 Oct 2024 00:59:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102379; x=1730707179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0LAzVzbd4+hUpzEhtVhLzqGP8/dhWHBWRhMA2d1vsAk=; b=F7b1TSN2OLcIm4ab6TxWvEvV4dxUhjjuJuTa93cV/qXZ/CvkLsEvcfHXBCb3BjEGxz Rt35GVCQfU7OqHi4wAIBWTBU0P4Ckes3nQdlUZ7gDKhuRaXylJNl6/rMvdpZhJZa827Y QrvxPGUfe0q3tdxWI3SSkfv0MsgRiMxXLNq7qVdTLRXVZzLpMqc8oJYs0fcIML0S7soB X/LjaJVhmM0bL/9vcVBMObzDUpSCUenzAp/AzNgwPPy14SS+M7OusbYW7pp7y7YANqVq TfQGieeGV8NJNMGh21+pGC41AbjS5FeDNtQVK5wnLAtGGTtLVGqQXJCIjxytDBOId7l8 CnpA== X-Gm-Message-State: AOJu0YxoV3u7aihr5XgAlEwjjW3wNC3nhGVDpccpYElUhYEj65uZj0DK brMqaz+iUdUJBGvtiyayydSlIbd78TEwSesCc4Zan/ATfr3To20OLor2SDNm5gisnD/2TunlQQ3 6Csl9+fiWr7IbKDVNINWnrhw9SI5M/hMCptlBwMLcyKnJPCPAjFcQD8xxHot5ivEKIOntp1LL8S H2E8E2Bq25Yg== X-Received: by 2002:a05:6e02:b49:b0:3a4:ea3d:8014 with SMTP id e9e14a558f8ab-3a4ed26669amr69048275ab.2.1730102379650; Mon, 28 Oct 2024 00:59:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHekW3p15vtFzLDt99nX8nI22t1npLipHtE4dHlHxKJHl+kU9z7b7mP5e9mlhKzntXs14HhTA== X-Received: by 2002:a05:6e02:b49:b0:3a4:ea3d:8014 with SMTP id e9e14a558f8ab-3a4ed26669amr69048165ab.2.1730102379269; Mon, 28 Oct 2024 00:59:39 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:39 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 5/5] Bluetooth: hci_sock: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:59:00 +0900 Message-ID: <20241028075902.114546-10-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit b2186061d6043d6345a97100460363e990af0d46 ] Check user input length before copying data. Fixes: 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (backported from commit 781f3a97a38a338bc893b6db7f9f9670bf1a9e37 linux-6.1.y) [koichiroden: Use bt_copy_from_user instead of bt_copy_from_sockptr, which was introduced in the preceding backport commit "Bluetooth: SCO: Fix not validating setsockopt user input". Also, dropped changes on BT_{SND,RCV}MTU cases due to missing commit 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")] CVE-2024-35963 Signed-off-by: Koichiro Den --- net/bluetooth/hci_sock.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 1d08f7b78fa0..a1a4df215fdc 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -1883,10 +1883,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, switch (optname) { case HCI_DATA_DIR: - if (get_user(opt, (int __user *)optval)) { - err = -EFAULT; + err = bt_copy_from_user(&opt, sizeof(opt), optval, len); + if (err) break; - } if (opt) hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR; @@ -1895,10 +1894,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, break; case HCI_TIME_STAMP: - if (get_user(opt, (int __user *)optval)) { - err = -EFAULT; + err = bt_copy_from_user(&opt, sizeof(opt), optval, len); + if (err) break; - } if (opt) hci_pi(sk)->cmsg_mask |= HCI_CMSG_TSTAMP; @@ -1916,11 +1914,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, uf.event_mask[1] = *((u32 *) f->event_mask + 1); } - len = min_t(unsigned int, len, sizeof(uf)); - if (copy_from_user(&uf, optval, len)) { - err = -EFAULT; + err = bt_copy_from_user(&uf, sizeof(uf), optval, len); + if (err) break; - } if (!capable(CAP_NET_RAW)) { uf.type_mask &= hci_sec_filter.type_mask;