From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2388D31F9B1; Sat, 12 Sep 2026 16:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789231265; cv=none; b=Io0Q/CL/y/9o51jMSwWs461Sz0DncnF1Jz4TDd/J1qkG4Hu79dmKelKVkUUjusMgcmdTkEPSYXUX2CHVe495xPobLrmJ87Zc6Vv2XvnE+Sl0Rkl+x7dddTC9XccSPY1UpkoP9yasbFUrPb8QaTApo8ObRxWkasBWKOZwwnuFKZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789231265; c=relaxed/simple; bh=LDiaCg7gdmXy9jn/o8ZddtMsmn+yupuxi+ipgxqxozw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kw2sJrIMOC1t8hqS+f5oQzdO5Kk85CanK0L+O4aT2/c/7HtQufHZ6Fq1v9IKyck00dSxXR6ok6zXT8Yavi39uQU4YT/UFlpJp0KlJVtz374Zez3yiI8Oq5ErJWwiCMu6WRnsL/MxIYGyS9oStTp0PtwQDxmet+tV9jUXK4MHZts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LpmboP4r; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LpmboP4r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D900F1F000FF; Sat, 12 Sep 2026 16:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789231263; bh=b7oLmG1Yb0kjoRpSXvR/khFngcYXpZcmoD6DHMsu0XU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LpmboP4rD+OUMaqoBPuk1/JqGRA6yEpS5dsgEydPSjAR6iSSn5ohXNOY8JX5qCmud qfNnvKdJLYoxHlgamd3ACHVAl3oTQIqPkpsHw2nn62g5h8QqpnRSvmM3zO8nqxs/1g ath2UrWVpD3baeqnMWyZswX7rrna5vloJ/zb+mGQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Breno Leitao , Simon Horman , David Heidelberg , Sasha Levin Subject: [PATCH 6.1 0961/1191] nfc: llcp: avoid userspace overflow on invalid optlen Date: Sat, 12 Sep 2026 09:01:29 +0200 Message-ID: <20260912065609.804468724@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao [ Upstream commit 99985bfa8336fadcc69190ba2dcbd5386af3d661 ] nfc_llcp_getsockopt() casts optval to (u32 __user *) for put_user(), so the kernel always stores 4 bytes regardless of the caller-supplied optlen. The existing min_t(u32, len, sizeof(u32)) only clamps the length reported back to userspace; it does not constrain the store. A call with optlen < 4 therefore writes past the user buffer, violating the getsockopt(2) contract for all five supported optnames. Reject any call with optlen < sizeof(u32) up front. 'len' is int, so a plain size comparison would promote a negative optlen to size_t and slip past the check; an explicit 'len < 0' test is added first to catch negative values before the size compare. Fixes: 26fd76cab2e6 ("NFC: llcp: Implement socket options") Signed-off-by: Breno Leitao Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260521-fix_llc-v2-1-ab44cc09179c@debian.org Signed-off-by: David Heidelberg Signed-off-by: Sasha Levin --- net/nfc/llcp_sock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 6cdcc49a58bcd..a2c3d876c7d85 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -319,6 +319,12 @@ static int nfc_llcp_getsockopt(struct socket *sock, int level, int optname, if (get_user(len, optlen)) return -EFAULT; + if (len < 0) + return -EINVAL; + + if (len < sizeof(u32)) + return -EINVAL; + local = llcp_sock->local; if (!local) return -ENODEV; -- 2.53.0