From patchwork Fri Apr 5 20:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 786307 Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EE831327FD for ; Fri, 5 Apr 2024 20:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349665; cv=none; b=NnmwsmKIHPyWCKZHtDyTUO1onRQcm4S2CTB61VY/7a/hbkUrlyVNsv0sNieLizI81ZqpoW/1rY9sBFt9EoAq4h3MQwKn5BVdAHzteq769ZeR8+2n3qjcFVrUHQSQ2+SL88cVS6ZNzfFmX+8dym1rgB1DJEtzOpxVRgXgjrtUb54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349665; c=relaxed/simple; bh=H8eFOwRAoV4DFJBAuNi4Irj7C8f2JaeHDdVlNWxOuZk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=s2BmYVpcQQUa/pp3ON9KAWFAOzWp1TZT+Vvyu+MGmjyi1CzJe9taV+I5y3aXlCH2U8xjbDozyrxPFPUdpZHM1SSecDLQluW/4q3IffCCJYSIfHaE/e7PnX+n6OPvVf6/CZiieaS1ke2kooX3UF3k1QXaj0/w1JCkguhCBwmf+VE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K7KyMBZd; arc=none smtp.client-ip=209.85.221.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K7KyMBZd" Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-4da5eb33c45so761478e0c.0 for ; Fri, 05 Apr 2024 13:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712349661; x=1712954461; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=AIO8scaADKE+KJ2bsqCNzXMkWrnS8uUEUgoBXCePjUk=; b=K7KyMBZdhIBXUfc0Xl7h3viP8neePRJ3UOSHJgNwEIz8+M1OqHPUbYBme0I2R+r3u0 /EdimPhUpKi/L5WIFAWTwT+4WETkD0JIb3f4LIXjo8RUqgRJjkE2kElJq9GNRM2eiJNt Bn8o9HmqpW++ioXLA6j1v2zUeNre7Wei9Ts0o1JCLBXNyc9QWV4L7Kmx9OY7wgP2rdCp QOjntk57Cxzo+sfbszGBSnSKZ81AW6H9TVEvkXSJAxdj5Lm4znu2bH+wSciQghLHssdV wXS1pMi9Sl7+nKsA+/Ae7jW2a77AiWv4ykSGZYegaSZoBAueyY+mY5/y1KVaRRCy9I1Q MW+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712349661; x=1712954461; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AIO8scaADKE+KJ2bsqCNzXMkWrnS8uUEUgoBXCePjUk=; b=smjdQkroJwy7Pu56OnePjz1BKkos4rZHJk0MAXVmS92+TiOdv/mgbxsqWeqCAatO4C qOO/yB0exE4N9fp2mJJjIJ1FA4g1cwNLP+uoOr/nTT6aRDlcJSef1ccCX9T8ZBAzERK4 yh8a8hBoSW4inSV2rCYHwptsxHeU0+mmWU6vzpZpBWjHOEl1CL5cxNMKKljDo1E3ayjG XhO6XF+0b9AJPF4HoW/Zc5o2zS2Tou99OBsclPnwSoKS8ygSmmU2Lgr4UEmPXnmKb1lK oKzdsZUACa000+3is/2mr9nqivHcJW3docjhKAoFPE/VsMwLz5teLb5o7X8ACRmz9KYc 7Jow== X-Gm-Message-State: AOJu0YwouFm06dOg4UOSFZZeYns/7xbxs3Ij9j7bg4R2BcqBKoYNBrtL wEhpGFE+mvnDadLH4ReyfNM0Y2/KwXPedkyherXzKGNuhxHHDTyHlPJCYyYc X-Google-Smtp-Source: AGHT+IHcrOulM9BOLEyf5fscQsJCljvEnV6fiZXGpEnr0VsnNoikuldD9I5EN3Z1DXXV8knWmfCQ/Q== X-Received: by 2002:a05:6122:180e:b0:4c0:2d32:612f with SMTP id ay14-20020a056122180e00b004c02d32612fmr2777152vkb.15.1712349659914; Fri, 05 Apr 2024 13:40:59 -0700 (PDT) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id l76-20020a1ffe4f000000b004d89b77e45asm326510vki.51.2024.04.05.13.40.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 13:40:59 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1 1/4] Bluetooth: SCO: Fix not validating setsockopt user input Date: Fri, 5 Apr 2024 16:40:53 -0400 Message-ID: <20240405204056.3451243-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz 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 --- include/net/bluetooth/bluetooth.h | 9 +++++++++ net/bluetooth/sco.c | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 1ada4f85e982..431c907155e7 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -586,6 +586,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); __u8 bt_status(int err); diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 99c2b713d826..cc72f05d4f0e 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -839,7 +839,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; struct bt_codecs *codecs; @@ -858,10 +858,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); @@ -878,11 +877,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 && @@ -905,10 +903,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) set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); @@ -949,9 +946,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(buffer, optval, optlen)) { + err = bt_copy_from_sockptr(buffer, optlen, optval, optlen); + if (err) { hci_dev_put(hdev); - err = -EFAULT; break; } From patchwork Fri Apr 5 20:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 786539 Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 455C8172BCE for ; Fri, 5 Apr 2024 20:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349666; cv=none; b=rg87RJCrlLjD6twE9NUEIohzq0YaiE+QGMGy3G+I/DJRZz79m7az8H3s3b8iVSYAJDNyJCw7fwXYwNZzkWwAPHOQfKjUB7jNoa4JqRLtELHuxgKuxER9nSO5Kp3KP73yBwTyrv5J14BqqcZCZeBJ4qi3ufxi6Vv3+orLdW4o0pM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349666; c=relaxed/simple; bh=scB375BcgWKyVs7APGKmlH3BNN9sCzGwZGn3kP93Dw4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qEv12PhpTn1IRiJ/++HJgebuww9LzaHQ6T5HPYN2KO37YStCOD7VtUTtiySAFdSf+Bn+Sl7i1ZYxkrxW0YcUml4ibHU38aP7CxujHLYbBAhaX7XnG3baFqOBRZztsdmKeWivJA51R/0GSM78ldV5Pe8SlZN15Vqwppzpa//tJxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hRi5NIuB; arc=none smtp.client-ip=209.85.221.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hRi5NIuB" Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-4dac19aa9b5so264868e0c.2 for ; Fri, 05 Apr 2024 13:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712349663; x=1712954463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=EJ8oPaEsLNRDFCeZl16WX8XecPaorqdlk6SPAFE/suI=; b=hRi5NIuBH2OAamaONFKMZX8iHhKWXAS5EO9uu96MGGGuJtLcfSgD8dz5Aw2w7o3ITK PdYHHJnGgxXxUHIYv/syxjips9UCQ1nax4/lv9nflkO9mgm9yUCGPBA0dGLq4a5nXVIT ZKIzBjsW3KS1FQUw/NUZv/ZrXYoKLJHUBWl2n75AfIZU5iEewbGAMtAKG8uyU+n1ZrXz VA4tYz9QTkWtvA5t9luiRbxU7EdIJ9noZV5qxNVH55wchCPZi4b3vu/2c9PKfNU+jNDf hBbC1zxcj22oNYxNHIVspDmvwdGK5OxM4YOHXCq+giY6pM/v5loyHI5irhabS+MsLQiw ZLpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712349663; x=1712954463; 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=EJ8oPaEsLNRDFCeZl16WX8XecPaorqdlk6SPAFE/suI=; b=gex1d4NeqR66R0+q4+0CUJFch3D31cvLhpomCPAtABSXuFA7BoeO4K2Nfbklvzo8+F RlgjOrDMa0IosgFPat7P9Ci4rHl6qBehimaElxqxhifqZEadv3WlmE7DYDImFg+uOHu8 gEbS2ysjeqm5sXZnyZDc9ljiVlgijEeTXL9McrrQ6PpTPFBXfyfCHVlw8aOnCju/mv4W fmbRYm1ZgpRs/LxEZ3yPs+8bIhWL2/avC2GRGRFNJguwJk9sHKvXj4wPEHHBXxKCz0sM zOlmkzLCFIA0ei3vca/4PTLpoRy/f4+e/3qy40RYqmnRc9f3Gtmbly0XX1UOQU+cfY3B Zxiw== X-Gm-Message-State: AOJu0YwZ1hil8Q6OfF+iXTXiKulq+W6dzC7xNLhq/pt5fl8mUF5smQcy j7MgVSfeJ4By4ckZxOwc8LyHM4EAY2jhesVPOdDjn3883+5by9Y1ZYXLz0tM X-Google-Smtp-Source: AGHT+IESyv451olDS/UHqDXehGRyW8zWMpH2hapEU4yg46QWkwxPjEVw4uQXZPTwowzZ1mchjJeDYA== X-Received: by 2002:a05:6122:1c7:b0:4da:ab0f:4a86 with SMTP id h7-20020a05612201c700b004daab0f4a86mr2226343vko.9.1712349661095; Fri, 05 Apr 2024 13:41:01 -0700 (PDT) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id l76-20020a1ffe4f000000b004d89b77e45asm326510vki.51.2024.04.05.13.41.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 13:41:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1 2/4] Bluetooth: RFCOMM: Fix not validating setsockopt user input Date: Fri, 5 Apr 2024 16:40:54 -0400 Message-ID: <20240405204056.3451243-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405204056.3451243-1-luiz.dentz@gmail.com> References: <20240405204056.3451243-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz 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 --- 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 b54e8a530f55..29aa07e9db9d 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -629,7 +629,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; } @@ -664,7 +664,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); @@ -686,11 +685,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; @@ -706,10 +703,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 Fri Apr 5 20:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 786306 Received: from mail-vk1-f174.google.com (mail-vk1-f174.google.com [209.85.221.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63456174EDF for ; Fri, 5 Apr 2024 20:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349668; cv=none; b=ZlZQTx0T0tXP/+v/Mmed5pxKVJOmK3WBQc2ePNYluS+wAYPQlAmvpCLnHKH1qvPizva4EQZ84O1Apf2WV6fjkZLybkL0Rb9UN7UxP/nuSU/m1Tif1Y5QHRvBzF3vDAA8rTNQAh8HOOaOTPE0zk/comLYAq5/gEQaPd2eZBVCGGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349668; c=relaxed/simple; bh=iXNizauSXh66GDHlq1xzX42c+ElqefZx2lOfRicB8yQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gZ8hOwXAMejWToWQLEe1YDBPYioivjesoJZKspCHP1u6LMnQCJHra9L5+qrD8tpLw7rWArrOQNDOgwwMQBlnbpeAz/F8VYNZQOoIT88L+ymJU2Oecu5yYrgjYV8xdEUpSaZXB3jjrcYalFUR/koRxHnyqpUv3BnvDXbDgikvpIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Sjfgo+aD; arc=none smtp.client-ip=209.85.221.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sjfgo+aD" Received: by mail-vk1-f174.google.com with SMTP id 71dfb90a1353d-4dacb2ad01dso21646e0c.3 for ; Fri, 05 Apr 2024 13:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712349664; x=1712954464; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=nUCzNWsmkKyWSoZrbs7OPkZEkFyQh9bUXtmeEbSQTqg=; b=Sjfgo+aDp5640BTpbNK+txKQdz6EU3Tvs7UjeQcWxNPCRicAedVW7sjIlaJkmaEErO fOOruO8879JFaRGI0NfO7KAjbZuPF59ji+dbUMWrO6MfTss458lTduSAti74TUFWUSS4 GuQTtnKW7MPWZHPtRgYWB/4KMP8QNy2WB+wt0hrPPuHGFtXajLb9cfO/iiz0GN3tB1ZU skorQj1A+ARYhoh05HN71IenwF0COT4x1HqtmsH1K/pIkGMMeU3yiyRVrUJDgp9QK3c7 kwW5Q2x/Ul8ZJVn6eW8TlHwIbMOTfXdzKZdM9iaVVoOiPcT8iCOI1svSpKHEFVYLAeSB F6qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712349664; x=1712954464; 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=nUCzNWsmkKyWSoZrbs7OPkZEkFyQh9bUXtmeEbSQTqg=; b=IdbNnJ0zQ/xUX+d6hA0CECet25FVjdY5tG8i2EGunRch6PyC9iuKEGdJ5j0DsiJmS+ Wq5pHq5eyxkR2hkGFqKyZk8O0FsoK8cIoBDQOSd/qFt3WZZD2RdGJA9JjQG4uXykoK5Z BMF6lDW1aq/XSVEpMUZprTGp1t1OK1StgDuwMkxUiRCyhclF40mckjij5itsNjNIvT84 Q7NbhPyUxrud4A5wPVYKAcsEa6Sf3CH9q/gIQwLUSyZy+0pZoXFJYkkQ/ACTBSNUmdna uW+61e4RetVp/uk1tWdsOW1oTHhsnC+TeEj0s5P53M9vdCBe3Q9HqmxjYF/c6j5qIrQE yDzA== X-Gm-Message-State: AOJu0YwhMisZEnS8IKJtuaZTYFzSqDSQfjlkBpT8xHMtjcWWJt7ApOA5 5tiLCpg9mfZHmy3KyV6cNpGPxsaoSg2l6hRkwPtiIuplgRz3OB2YIONmLloB X-Google-Smtp-Source: AGHT+IE/EjOvYLRMeRzjRKFUPUFYo0S31SB6gQiewFstmHSRh6dgpfPbFABwn0890UTJ1BOVKQK6VA== X-Received: by 2002:a05:6122:1792:b0:4d3:3846:73bb with SMTP id o18-20020a056122179200b004d3384673bbmr3309449vkf.7.1712349662306; Fri, 05 Apr 2024 13:41:02 -0700 (PDT) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id l76-20020a1ffe4f000000b004d89b77e45asm326510vki.51.2024.04.05.13.41.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 13:41:01 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1 3/4] Bluetooth: L2CAP: Fix not validating setsockopt user input Date: Fri, 5 Apr 2024 16:40:55 -0400 Message-ID: <20240405204056.3451243-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405204056.3451243-1-luiz.dentz@gmail.com> References: <20240405204056.3451243-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz 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 --- 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 7846a068bf60..b8913fbd77ce 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -728,7 +728,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); @@ -755,11 +755,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; @@ -802,10 +800,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; @@ -886,7 +883,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; @@ -912,11 +909,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) { @@ -961,10 +956,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); @@ -976,10 +970,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; @@ -1011,11 +1004,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); @@ -1024,10 +1015,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; - } err = -EOPNOTSUPP; break; @@ -1056,10 +1046,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) @@ -1087,10 +1076,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 Fri Apr 5 20:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 786538 Received: from mail-vk1-f174.google.com (mail-vk1-f174.google.com [209.85.221.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77A39174EDF for ; Fri, 5 Apr 2024 20:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349671; cv=none; b=uDoKzevSpcuZDmDx38FVLJAhtQVznNdr1pnPARpbRFx9mCPwzYfHS1y5WfB6dJTpgvflsPZXduHPIeuAiSQ+9hoZlqogpMVIF3ZAN4wFQSJt1VXT1Fm2jI5OzcO9NSH/oP2EthjwNQ5VEYmN2Ja01RIodqMBfn2muVjJDG7GdM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712349671; c=relaxed/simple; bh=ebWmWUWlJrRcVryG+Vw2AfIAuohn2aXjWy0rHv4Ff9U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+Nh3I7Suhk9n3attmI6/d86OT0KJ6OgRMepJYuZ4vezlo36Jeffqme8Gh+w8NIwXSyyo6yKenk9Nw1+Z+OzCOZ5w2ZqUSN0iDPTSjW/MphsmUgWmyN1A9zSPQ5VUxst2zDVRTtp+5I5Oxs1saPAqD8PTl7PRunmreDQDdAft6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YsRiDxCp; arc=none smtp.client-ip=209.85.221.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YsRiDxCp" Received: by mail-vk1-f174.google.com with SMTP id 71dfb90a1353d-4daa5d0afb5so608086e0c.0 for ; Fri, 05 Apr 2024 13:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712349667; x=1712954467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VSAz+L9o6nEtGc+9BGwzzWHjTZpHBtpU2X0siDGpeT0=; b=YsRiDxCpj5mbCrGeYj+4qhzASR4tv3RUrbbuqxRpgpWvG2/MrTC1LTLUwDBHoupRjC jWVDxiZFEjHhM1dmmFD0iGTFlrfTe46g66enwovjd6iMGtR71ckopkor5/g4998lrXoY GWERJArTNICDmEsHsqk3WrISY1eGXMrJBelHI88RxZQoS54RM2W82uIo3Rknqfl6VBey yJwLe14G54q0i7zEHktcRR3feiMcCiLvY05doLqTCxcDk1NfvDBvljWykSgvn1eV1n4H 4yvtjpkGlIpo9LNlgUanUQcUKXuwOBu+xqwjN6KO4vVwMh5Dc8bXfdrP+L/IaSuO3Cv5 PDSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712349667; x=1712954467; 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=VSAz+L9o6nEtGc+9BGwzzWHjTZpHBtpU2X0siDGpeT0=; b=wHaLqqNUONjbV5CvxwtYPdoq6v5rJg6spFJefKrim7uDWbOTc0st+6oQdSTj1nfT7T GNZSSMZYEJvkuGR4/1mYP3oxpTv5XfDTXHmpTZh7pHHbfEZ9CFe5dII6qBg+XJ04XgAt +MfSSpd69Q22IMv5SRkCqnI1UU376EQmN4SY7MOGz8cnuEVjJaMAi+Mj5sH1HCp5YGub JkP5cH3UPfifzqBfAr1dfkdNeV6Qlpsazi/0ns5D9bTYw5sCteVMndqm2C/rEqgxNqPI Mb/UrYysEvt0zQVFNRx2uFUj5sUZS67ixd1NtSlEavuvno9qziLfFtZbFQz6FMucauLC FORQ== X-Gm-Message-State: AOJu0YwkP6ScJAz3jYkI6bYCAtIDiVvQwNROA1dDs1znTG162QeMwbQR 4epA3ONd4eHpUFF7qnDjyOQZwdMF9ogj7wvOwKP+21BxoKoxXq57vMq/2jER X-Google-Smtp-Source: AGHT+IGjHc0cNtXUNdJYt4Q70nPFUK89syYLeZlMMDBADUG8zBhA1qcT4BytrpGBSyvbTatj9kuUGA== X-Received: by 2002:a05:6122:45a0:b0:4d8:7970:28e6 with SMTP id de32-20020a05612245a000b004d8797028e6mr2993162vkb.0.1712349666589; Fri, 05 Apr 2024 13:41:06 -0700 (PDT) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id l76-20020a1ffe4f000000b004d89b77e45asm326510vki.51.2024.04.05.13.41.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 13:41:03 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1 4/4] Bluetooth: ISO: Fix not validating setsockopt user input Date: Fri, 5 Apr 2024 16:40:56 -0400 Message-ID: <20240405204056.3451243-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405204056.3451243-1-luiz.dentz@gmail.com> References: <20240405204056.3451243-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz Check user input length before copying data. Fixes: ccf74f2390d6 ("Bluetooth: Add BTPROTO_ISO socket type") Fixes: 0731c5ab4d51 ("Bluetooth: ISO: Add support for BT_PKT_STATUS") Fixes: f764a6c2c1e4 ("Bluetooth: ISO: Add broadcast support") Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/iso.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index 0dda77e2e52c..5964e2e87829 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -1499,7 +1499,7 @@ static int iso_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_iso_qos qos = default_qos; u32 opt; @@ -1514,10 +1514,9 @@ static int iso_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); @@ -1526,10 +1525,9 @@ static int iso_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) set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); @@ -1546,17 +1544,9 @@ static int iso_sock_setsockopt(struct socket *sock, int level, int optname, break; } - len = min_t(unsigned int, sizeof(qos), optlen); - - if (copy_from_sockptr(&qos, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&qos, sizeof(qos), optval, optlen); + if (err) break; - } - - if (len == sizeof(qos.ucast) && !check_ucast_qos(&qos)) { - err = -EINVAL; - break; - } iso_pi(sk)->qos = qos; iso_pi(sk)->qos_user_set = true; @@ -1571,18 +1561,16 @@ static int iso_sock_setsockopt(struct socket *sock, int level, int optname, } if (optlen > sizeof(iso_pi(sk)->base)) { - err = -EOVERFLOW; + err = -EINVAL; break; } - len = min_t(unsigned int, sizeof(iso_pi(sk)->base), optlen); - - if (copy_from_sockptr(iso_pi(sk)->base, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(iso_pi(sk)->base, optlen, optval, + optlen); + if (err) break; - } - iso_pi(sk)->base_len = len; + iso_pi(sk)->base_len = optlen; break;