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;