From nobody Thu Jan 30 23:16:40 2025 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 9EA1B1DAC8C for ; Fri, 24 Jan 2025 05:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737696807; cv=none; b=fuhtaVuSWMngPs6iOP1SQ8lDX+dq/NqNGF8n0Go40cWy0Xo7dlcYydxBVv1QBW+WwAHiK2xUjvFm6JWMXB++1lRIw78GpDQjmcQBGByZkXqj8IOnePbBHTZp6+QOqTrCybvTVA1aQHS5ehbzLrUX0NOYWqY4tCGzfuX+hgJVtyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737696807; c=relaxed/simple; bh=wSIW9SJc6NZV6MAAaotVBRNDtbW5HnbEWkJPdDpU52k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kkRfj7FXeVqTeCEE0lK27G3aEPoK/WoOIIBh/yH6zVxAzDSyyihUXD10jSIqhDcWkdQlnBXXSbYtg9d+/lw5gqfUTqud+aoT2nqJrD2ZPguWxRXSxKG+KOXHcmKc9ugwkctOqTXQ3GH38bsAPmQDKGgdwwxmG8fjh+23W6K/Mbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=BFXBAUzT; arc=none smtp.client-ip=209.85.210.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="BFXBAUzT" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-71e111248a2so254768a34.0 for ; Thu, 23 Jan 2025 21:33:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1737696804; x=1738301604; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tKI6M3Ga2oIUgZFOTflqzcS/S7V7PY/8wm6k/uUZ8oI=; b=BFXBAUzTx2f3k1K6SNB9JtJ1a4FZmUU3werNUcgFiXhCJp00tdkMbRaYe0/ALZfbc9 x1FrEpFLgQM3FVJP0pEQH2fSEU4IbI9somC8w3PSFRUOpiZ39Swy3mZPVKfCdeYM3LcL KyHKe0wT2OIiwOlW2PkmzGHiCiFpFgMWNvyDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737696804; x=1738301604; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tKI6M3Ga2oIUgZFOTflqzcS/S7V7PY/8wm6k/uUZ8oI=; b=oqjC75vzdGyQChSu7NCHgaTDxHDEN8iht87BsGoAH48sbmoUhVIKz5Un/jKcGYeek2 ptjikXtoc+yv2UwAY/nawYJwZfZQ/KSSzMrZxu4Sn1pDJpilAvU508lwE40v8qf9zvKD lYkz6bkjemmnLje+PjhFW2qa+rZmPN+gVHZKML7RZcqPLjvip6CKkUryHcHFkn6D40L7 zYW+NjScFZ1eGbfAZLPVFAjfHSbuJxAnc3rLUdH05REoP2FujCdhk+O4Z6WJkMecBWAf Wt5hRAWbYbtwYtKwgxQWK04F/dynNf3tO+XGBzFKn1DPRL5EHUhybGPip06HU1lQbh40 CdtA== X-Forwarded-Encrypted: i=1; AJvYcCXiiil0pjn3oLKAF44gotkIcdy5LNCh4j9yE3ah9wIsH4ddvfaVuRY+Cs6j6Ife/FcUrilksxXqECwHpUg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp8q51obvTaog5GcO17qgGZ83iBBi3cYVwoJUhvMIeHXaanUD/ pV2hVJcnllWtnqwZmC6uNe/3GZEBMwKq72/jL8YIHXh3rHmbITsGg2ujNAEzJg== X-Gm-Gg: ASbGncsRGXdXV+WplOXRvi/Oy3CiR3xDKylaA36R1TiE1VK3sVfM6RtQqo5rnz3jukH W+xpTI1L6LtJodDHVaHR8mzyn3DXIflZbWT4DAh7HF3/h0yhe+V64PqjGHfWP/VWvpDBpnMsRQY TV2olBF83SGy4mJn8ST27mhdiBHVEfla2Cntbd0UzS87GnMfAXPKscp9RFhtbyw/COo2I1H+dEA ksG+9HgC/yx3pK9bgfK74FUKZ4NXK6l9icQE/MlhbUmoFqWGaM+6Y1mboHG/syYegXQsjuGzsat d7fmsK/Bvl3gia8ibJ0iIn9EArA6X83IZk9XDkskNDngPk/Jdb+cn3TZ8/U= X-Google-Smtp-Source: AGHT+IHhOD/kMjWyZMdu2nA2GSmKabRzevDKzcDq4NyCBezacU4HqyWOL9aAedfSaePPiXOJQvlzVg== X-Received: by 2002:a05:6808:1896:b0:3eb:45de:8ab5 with SMTP id 5614622812f47-3f19fd4c5ddmr7038027b6e.4.1737696804592; Thu, 23 Jan 2025 21:33:24 -0800 (PST) Received: from kk-ph5.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f1f09810f7sm270795b6e.37.2025.01.23.21.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 21:33:23 -0800 (PST) From: Keerthana K To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, davem@davemloft.net, kuba@kernel.org, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ajay.kaher@broadcom.com, alexey.makhalov@broadcom.com, vasavi.sirnapalli@broadcom.com, Luiz Augusto von Dentz , syzbot , Eric Dumazet , Sasha Levin , Keerthana K Subject: [PATCH v2 v5.15.y 2/2] Bluetooth: RFCOMM: Fix not validating setsockopt user input Date: Fri, 24 Jan 2025 05:33:06 +0000 Message-Id: <20250124053306.5028-3-keerthana.kalyanasundaram@broadcom.com> X-Mailer: git-send-email 2.39.4 In-Reply-To: <20250124053306.5028-1-keerthana.kalyanasundaram@broadcom.com> References: <20250124053306.5028-1-keerthana.kalyanasundaram@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 lev= el") Fixes: bb23c0ab8246 ("Bluetooth: Add support for deferring RFCOMM connectio= n setup") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin Signed-off-by: Keerthana K --- 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 2c95bb58f901..47e2fd38b2e3 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -657,7 +657,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *so= ck, int optname, =20 switch (optname) { case RFCOMM_LM: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { + if (bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen)) { err =3D -EFAULT; break; } @@ -692,7 +692,6 @@ static int rfcomm_sock_setsockopt(struct socket *sock, = int level, int optname, struct sock *sk =3D sock->sk; struct bt_security sec; int err =3D 0; - size_t len; u32 opt; =20 BT_DBG("sk %p", sk); @@ -714,11 +713,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock,= int level, int optname, =20 sec.level =3D BT_SECURITY_LOW; =20 - len =3D min_t(unsigned int, sizeof(sec), optlen); - if (copy_from_sockptr(&sec, optval, len)) { - err =3D -EFAULT; + err =3D bt_copy_from_sockptr(&sec, sizeof(sec), optval, optlen); + if (err) break; - } =20 if (sec.level > BT_SECURITY_HIGH) { err =3D -EINVAL; @@ -734,10 +731,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock,= int level, int optname, break; } =20 - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err =3D -EFAULT; + err =3D bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } =20 if (opt) set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); --=20 2.39.4