🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10334

[PATCH net-next v4 1/7] ipv6: treat a negative optlen as 4 in do_ipv6_getsockopt()

#10334
From: Breno Leitao
Date: Tue, 03 Nov 2026 11:01
64 lines
12221 bytes
do_ipv6_getsockopt() reads optlen into an int and never checks its
sign. Most of what consumes len compares it as unsigned, so a negative
optlen reads as a huge buffer, and the reply depends on the option.

The int options clamp it to their own size:

	len = min_t(unsigned int, sizeof(int), len);

so getsockopt(fd, SOL_IPV6, IPV6_TCLASS, buf, &len) with len set to -1
answers 4 bytes and reports 4, rather than failing.

The other options see a huge buffer. The sticky options reply with
their whole header, IPV6_2292PKTOPTIONS writes every pending control
message without a limit, and IPV6_PATHMTU and IPV6_FLOWLABEL_MGR pass
their length check.

do_ip_getsockopt() rejects a negative optlen, but doing that here would
turn a call that works today into an error for a caller that passes an
uninitialized length. Answer it as 4, as the int options do, for every
option this function handles itself.

That leaves the int options as they are. The sticky headers are cut to
4 bytes, IPV6_2292PKTOPTIONS gets a 4 byte control buffer, and
IPV6_PATHMTU and IPV6_FLOWLABEL_MGR fail with -EINVAL, as they do for
any other undersized buffer.

MRT6_* is dispatched earlier and keeps rejecting a negative optlen, and
the netfilter fallback still sees the caller's value.

This changes what callers that pass a negative length see. It is a
behaviour change, not a fix, so there is no Fixes: tag.

The conversion of this function to sockopt_t builds its buffers from
optlen, which the standard helpers reject when negative, so the answer
has to be settled before that.

Suggested-by: David Laight <david.laight.linux@gmail.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Acked-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/ipv6/ipv6_sockglue.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 4b3536571c9804..700133e2fd11c2 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1002,6 +1002,11 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
 
 	if (copy_from_sockptr(&len, optlen, sizeof(int)))
 		return -EFAULT;
+	/* Historic bug compatibility: take a negative optlen as 4, as the
+	 * int options always did.
+	 */
+	if (len < 0)
+		len = 4;
 	switch (optname) {
 	case MCAST_MSFILTER:
 		if (in_compat_syscall())

-- 
2.53.0-Meta
Technical Details
Message-ID: <20261103-sockopt_expand_out_v2-v4-1-2d36da923578@debian.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355502-linux-kernel-netdev=dewy.ru
References: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355502-linux-kernel-netdev=dewy.ru
From: leitao@debian.org (Breno Leitao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 1/7] ipv6: treat a negative optlen as 4 in
 do_ipv6_getsockopt()
Date: Tue, 03 Nov 2026 03:01:00 -0800
Organization: Usenet Network
Message-ID: <20261103-sockopt_expand_out_v2-v4-1-2d36da923578@debian.org>
References: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3164305"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AWv5TyOD2doayQEtJTDNOGotO30= sha256:VWSv/tgeW53IiULS8MkWumg/hJNRnieu5IYL6Aq3qpg=
	sha1:cyTXlyLMAgcfqe0h8FiqX8xUcKY= sha256:fqhrofkT0RZkHC+roAk6QS5Xwvfplfx/nVRlx6JK92Q=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 66B59112876; Tue,  3 Nov 2026 15:24:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.052
X-Spam-Status: No, score=-3.052 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=debian.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id XAy878WJhWvs;
	Tue,  3 Nov 2026 15:24:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-355502-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=debian.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 39083112874; Tue,  3 Nov 2026 15:24:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id C3C412D3A4; Tue,  3 Nov 2026 11:11:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793704011;
	b=xHr5wu7EXaXOinjBJqdHlKdsY86rUFcH3DzQS2D9IiAWeiyggPZJb0Ms7FGW55zm/sAF
	 yt139dqi21XrxIopQM6Y4tKNKqY5PAtth6kLFiThHxpfRqVpoy6w+PmDDz4VEQw+QjS8e
	 MFF/O6NfFC65MT6Nd8ev5DWJMMVAWc5KacscfK3X32OyQr1YLpFxIgyib3H/h0h8H9zpn
	 yFh/Fk3c9cwaYDOvdePGo00lfoy4zUI3liO1rU6B8tr5O6K5tbHdDuL0WFBJSihc/UDad
	 4q41JftHx23nWJZ2HkAZSgA7A5Ezty9ccYT7Q6SZwze8uQ3YaQ/tYtAD+qijUC8joqA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793704011;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:
	 Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:
	 X-Debian-User;
	bh=d5Z9wG+EVu9kY+hFLz3UoxaHzvTb8LC6qwfAF10+NBw=;
	b=fVwLVmBHod1QKBZO9oBb6OCG3YY6uYyv1HRQmJknb5/oOe4T7RjLkJfg5UTgYj09s6Jl
	 qlbSiln+E82bk2HooJji2QOiXeAWVKsmCLZ2o/e3kiQWjvf9Djo+ec9xhAoxXe2Je7UX/
	 83qsUtcV1s/opduekxMzfnvpZHG5t4lCu4gnpFWxt/26h7uUKIzlZGxOQgCKyni/IOyVb
	 1pPP2ECqQfEXqvwTWzdwK2h/Tl+RsaaOAOB9ddHauZL4nCmDOGP+9W55WE0cqSPAR6jhv
	 rjGFYe9u+P9avtq4TOEL605lWOclh3CA9CvPCHRn2pFKvtfmaQ2SeVyB4mQ5n/v5DQA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=reMgaxj+;
	dmarc=pass header.from=debian.org;
	spf=pass smtp.mailfrom=debian.org;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A6B6606C580;
	Tue,  3 Nov 2026 11:06:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=reMgaxj+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=82.195.75.108
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793704000;
	b=I2e7WXzeNrm0LdlktVEG5nOk/eKdp7jsy1LXBnJvLVApV3Ek2f39tVjHKzAI4POHFPZC
	 94Gxnc+PtiWa0Ozh+6Kmp9mOWMb6lxctjBy2bylg328M2P3eBhAgEt/GgX3XGqwSBN5re
	 UzqMCyT8+KSkesp24YxVviJ9XkeuLtby+1WZCy2jz+Bi0KO5/Vzh3LW+28+RKUDzQ+3x1
	 zSiuaclQToeopnH6GwEguyj0rUJu/FPfw66u8wLz3UMb06nQamb7cQTaH5cw0yaV0Y2YV
	 FOyWphDF4cSG9P1PEujbce8MzUNv6xzlyILUzm5kDt3PwyeoKI82/BlR1t/KOZWHIoQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793704000;
	h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:
	 X-Debian-User;
	bh=d5Z9wG+EVu9kY+hFLz3UoxaHzvTb8LC6qwfAF10+NBw=;
	b=lUokldruqQYwQ3V8HLuIQB/E9Mt07hKGLWZjk/+nvp+sSWV5s4qdsp1jmYY5VkUtT39i
	 t1MxdCgGYKrNHmik25UzrF7zsni0vc/KnjKQVfvEtNl6/2zWPRY57/I3LULarHoCnlS46
	 lwv+gy76Q1ZT9M4T+D59Cfg4KDqK6rgfrjhPlPq/SgxnYqoMHNOWAXbkCou25iTQWy/xK
	 uv7BCJfChGJAPfenxtPybrFhckjuD/vIJbQstW+oAT2GF4WJkj4dNcnQIXPLCM8j9JgP+
	 FvJluJE7Xe3jU8znS1ktNodXK62MzjHr77jbJrAHL/MedGmKU4lZPXEcPhqaEgFpZmg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=debian.org;
	spf=pass smtp.mailfrom=debian.org;
	dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=reMgaxj+;
	arc=none smtp.remote-ip=82.195.75.108
X-Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1DFE606F7C2;
	Tue,  3 Nov 2026 11:06:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1DFE606F7C2
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org;
	s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References:
	Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:
	From:Reply-To:Content-ID:Content-Description;
	bh=d5Z9wG+EVu9kY+hFLz3UoxaHzvTb8LC6qwfAF10+NBw=; b=reMgaxj+DRua4X65pjHbGjieoV
	ee1LPp/r4JIAzLFuIRajFlgCIgSP9czYZd+MV8XL20rlVWyKMtZwaPaxVyfiswrKx4gaA10wSJPH/
	hGbZM0rpqkt5+H6qoH2fLrSfUljGdfqjW08V64VB34fP5DP+sQmwbIU04d11DW3GVkKiHRFLNQmmY
	PEbOQHTxTBuGCUvwbpdKCEqwpaHGYiqHMy//ZSHmPrRJxY1woXNwEl1vhr6TwWVREtU40rFXV0t1j
	OSG0JnYeik7/LcHAO4O+zKcDO+/djkcbfEZICrph210eZZqC6DNRRWXiXi8PV+za1eehhySB7EcLl
	5rVpXdeA==;
X-Received: from authenticated-user
	by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)
	(Exim 4.96)
	(envelope-from <leitao@debian.org>)
	id 1xOCLc-006tCW-0O;
	Tue, 03 Nov 2026 11:06:36 +0000
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org>
X-Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, 
 bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, 
 david.laight.linux@gmail.com, Breno Leitao <leitao@debian.org>, 
 kernel-team@meta.com
X-Mailer: b4 0.17-dev-ce4c1
X-Developer-Signature: v=1; a=openpgp-sha256; l=2443; i=leitao@debian.org;
 h=from:subject:message-id; bh=oB/f2JpXdqBpX3duFOcpr87zR35sk8trgG1TCFAjf8k=;
 b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBq6cAuX0649qpXHECEQ3+3dfugqYwG+0TotbMBq
 coYFGyUg8mJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaunALgAKCRA1o5Of/Hh3
 bVZVD/9zRKL+8ozqwUKJqHzWcmiYLGlEIyZ5GkqrzsmckwpcsuN5Z8ytdZCqIOoGD3DCfIDkKuo
 bgOnTqG5wMy8Jw+SU8U8SWLkqaCMqCpSBL52h4rUdeoVGANjHOVC89qo1dmVx2KlDzqvGNwUH1v
 3shECH67etIKkojbPVM9jQrdXhv6UMlgstLLoADCobME2Y7+RCFAsy15OHWAuDRkNX+Z1s5NlEu
 9Z46K2wJOK4wbljDTxI3qMEDAhzQ7Sx6N9jTO39Npl3obSRrKSII+E+W7lHk7Q9DuWC1xkTdWxp
 LBjLC1h2nUUs6B1M/Ufrokr5yh2OXmrRmCSdhOGA7RzOJXsFIEDCSeKW785SyJdoZ2FDDlqrQrF
 V96Xo8wa4kQMgpF3Bw1OWU/gOYoHpxFu0oD3mktQDcQa861pwZlHIsETd5M9tCyqSSqvzytVEoH
 sjcKkD/rQ4MU29ZAxDRLA9wNO6IQ/ZS+phF8ugwLInKFUy1zvz5P7EgbKcEsEMWxf1AjbNE9bxa
 U+7f+uGKi3RB8WcLJHrC8KecnVnjWH4rqmaDfHRRnDF8l9RcIeg5W1R4PrcMmfVUoERjcVyEFpU
 A9jcoZQkMDDqiumujLfrryYcJ3pCntisRcQ7QHpuXSi9n9aGp2WTyAKK9pcgcAqZz+k0yizWB+X
 PYeHMpPblG5yYSg==
X-Developer-Key: i=leitao@debian.org; a=openpgp;
 fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D
X-Debian-User: leitao