From patchwork Fri Jan 24 07:20:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keerthana K X-Patchwork-Id: 13949012 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 D8CBD10FD for ; Fri, 24 Jan 2025 07:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737703255; cv=none; b=mQcO2N921vKcqhnCPESi3DFbFrTVXp8laaEKIt5LHoKxKbsNuAGc9Kl7mAwBqBdPOnr4cepGcHVzB0ay3vezyO8EGzi0hfpMEeVDTNHBt9Z9Zjzxstk15kp5x9/DgOwL5sBUcizkhGCH7xUZN2Q7iVRDSBcLIKlHSXdzQ1WCXvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737703255; c=relaxed/simple; bh=sPH5XD4Ql4nTiFx2aUIrFzEBL8VQs0STJlcMk0WQEC8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PjZn3lju8Mle8DgOgXhRDJqojr/w0dkCoecroWtH9IcvWPCwlDYkFDuHBc/QbO8QPU3OZ1kTR/mMCEn0AN4Jt0GB9q6qgjLw0N5AQeQFWy54NnZ1liPxmHiDIBZQxw2sCrjnqEtOoPKl4DCxvMi3AxHZypxjPX5zGWFxr+YLAaI= 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=ZdtWuQAi; arc=none smtp.client-ip=209.85.161.53 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="ZdtWuQAi" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5f2d8e590e2so211024eaf.3 for ; Thu, 23 Jan 2025 23:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1737703253; x=1738308053; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1o1K/JB2XR1f5n0h8797pNwCCNLrErJQ179f5P2ssZ0=; b=ZdtWuQAiZCzy6a6m6j8Lj+7Jq5umG3qO9klBBS5qwmZhvC/McSeTQ0HGcmHpOeIUa7 m/ebaR+Tm4gAdOWGBWDBNA94/1abuhYw1cMc1AdEPJwkCZo/Ezhb26CzkTB2ptSQyUYk uoGzb8i4osrwaFVIQt/h/ZaeWG+HipdpkOm4U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737703253; x=1738308053; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1o1K/JB2XR1f5n0h8797pNwCCNLrErJQ179f5P2ssZ0=; b=OrnYY5eWFfdeqwTylL666TZEh8yXUVBjmlxR61EK1kR/iA7dH3n6PrEs/HQAjpELGF eemjsuM6b0eh5Siz3DRAZdwQkWkhl69mWe6Lf1O/0wpPdf8gKHH3wFkWeiYY22PtDIal 7VzIglIL4GYASy3J4OZEVhb0yARZRxtiRs2xLmQAqKQms52JZlTYL0nmnUZzkGH9N3mA Qbbt8P9Ta7zJ9nPIFEpT8rKbSFgr7eGgapXfMtk4D7sl4fgcflVXrbiZJrLDsWdix+B1 LgQop3IMpcgDgEX13J4RGYlrg2+KCUfCjtIjY/HNsD2LjOK+qOJTmug2mkCkd6j92pfP KKaw== X-Forwarded-Encrypted: i=1; AJvYcCW1OzX25MF0do+AjXBuoI5bLkhAWLL2GRF9iC9D4pGejkcpbtm9vN8cSK1XXuT2dVdPQhe/VBE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5tfBeW7vjqr+iJepp/7FW8NFJD+kFG1jpT70pZvyeU04rAzTO AjWo+Ob6Wt2N0sgcSBMAMqTQxcu/5KzhFHrN1dyOkjTkjlmOXDNHtzZT3t1Elw== X-Gm-Gg: ASbGncvoFQyCyvSv4ncXZR19OvWPGVzt5d5X1AoMV/0nKHTTCA/XRAZoDQLPVIo7pw2 VFOP/Yn/BibKAIwSnQvMaIIsFtiWOuzQKvaSm5fM2qAy2XbmDYWjpzxrtlf1VBWdfTmycxaCqLW ir+4ShD7JELRH9LkXenMi7RDE6vVJ568D79jGuzsycryq+mA7y1nOF+Nv9Cy0mgZtgt+JjGzygh T66DG09455vm7MDISQfm6Ic5XdMTfurM0MsBdqpIMgMVOXrJtzyTqSmgD3PCv0/B1I9ptVC5BWn isaJP+sLdVfbbH+WD0DttcCw/XArmVtppoKo5mARbaazLAC6 X-Google-Smtp-Source: AGHT+IHZldH01kYElNZnAI13F6z/szWcYyFhNGzqChJnu6ui+DTeuDlFA51IAVpPEsPU+wsGO26fsA== X-Received: by 2002:a05:6871:339c:b0:29e:51ca:68ae with SMTP id 586e51a60fabf-2b1c0616e24mr5207177fac.0.1737703252872; Thu, 23 Jan 2025 23:20:52 -0800 (PST) Received: from kk-ph5.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2b28f0fad54sm432960fac.3.2025.01.23.23.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 23:20:51 -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.10.y] Bluetooth: RFCOMM: Fix not validating setsockopt user input Date: Fri, 24 Jan 2025 07:20:47 +0000 Message-Id: <20250124072047.5320-1-keerthana.kalyanasundaram@broadcom.com> X-Mailer: git-send-email 2.39.4 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 [Keerthana: No changes from v1 link to v1: https://lore.kernel.org/stable/2025012010-manager-dreamlike-b5c1@gregkh/] 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 ae6f80730561..56360da0827c 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 *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; } @@ -692,7 +692,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); @@ -714,11 +713,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; @@ -734,10 +731,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);