🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10783

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

#10783
From: Jiayuan Chen
Date: Wed, 04 Nov 2026 04:15
69 lines
10954 bytes
On 11/3/26 7:01 PM, Breno Leitao wrote:
> 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>


Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>


> ---
>  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())
>
Technical Details
Message-ID: <ea399c85-c775-47a7-b42a-80a645ae16b9@linux.dev>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356180-linux-kernel-netdev=dewy.ru
References: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org> <20261103-sockopt_expand_out_v2-v4-1-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-356180-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v4 1/7] ipv6: treat a negative optlen as 4 in
 do_ipv6_getsockopt()
Date: Wed, 4 Nov 2026 12:15:08 +0800
Organization: Usenet Network
Message-ID: <ea399c85-c775-47a7-b42a-80a645ae16b9@linux.dev>
References: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org>
 <20261103-sockopt_expand_out_v2-v4-1-2d36da923578@debian.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3323402"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HtciHZ50mI6dLRtjOx3I4BBOmwE= sha256:Oper0tsHxWOjDDTS6SHD44dm1wu+cgSpdOlXya0NpzE=
	sha1:ZoOTMFArJsUMjI0atLOFkwMbyHw= sha256:3jF78bHKp3vZiJDrHZqwOIsUeN8CyZLZiLOPtGW37n0=
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 36B58112AD8; Wed,  4 Nov 2026 07:16:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.051
X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	HK_RANDOM_FROM=1, 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 (1024-bit key)
	header.d=linux.dev
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 aw2HwX7FdacB;
	Wed,  4 Nov 2026 07:16:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356180-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id D8EA6112ACA; Wed,  4 Nov 2026 07:16:16 +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 66B912C0A1; Wed,  4 Nov 2026 04:15:46 +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=1793765746;
	b=DMcbQOW8K/YHYjYre4AVkXT/0Y3hAjQbOltafclSaOP+78TBySKX6LqX9YRVG2eEmtxF
	 pADTJgM0GP0//3E/8wvehLCO1FJMKu0PteEG7UIv2pSHxQyQyIE/77VSrADNoq8hFl7Jt
	 2sNe2xCPCJyyL/aBkpLYfaw7dbNn4VNtUlBAfZEHCK8K41rF0LPkKY4zlaN4Z4SswUeON
	 TsQAC0uLxXNzJ6nN6sWL4rsVZewGRQR2XO1a6w8TN1qhQYwDvbIOyLzyQtgGrWfJn343Q
	 7peynQypfLpYmzVYmMmu8nli3tpA54fR7vSf5IpKfOwEANqV8qr3jodTVBXSOGdkk0Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793765746;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=t33hTerwq+aQ3mBUBeIWL6pRcgQAoxI6zsMD8gzG6mU=;
	b=2H2jq0ersn2TozJvMLzBlwiuqAdro6N8CChDjiFNZvNpNWbkUDUKjWxt/CD82oJEomIq
	 CbaaEf/N1xDqy36jKg25nJ4hizJjw12L1fl+i+7QdUlhFFDG1uME561fcTIo1ABA3tkuc
	 t0borb6EZm2mQa6bTkbJetj9pC0j+vAbA98o2dsjEj/BjUIFneTzQQ89WWD2Qc1R/51gR
	 NiF3+6p2hmC9loTpBV2sHWtAuPL/DSvu339P3bUNhhOthtXg+c4D1UswMUEjK36iKEkhG
	 MbqA3U6RsDsCryp6UoJ6fP3/ByOBFbSV5GOQBuJ3eOn3VnBUiRd0FEAApcwft9Q4TIQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nm5tWPga;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 3EB41606A332;
	Wed,  4 Nov 2026 04:15:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nm5tWPga
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.199
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793765740;
	b=rpEG1mVk8lm2LwbmA2QZOaTb1crSCx69+6kv/33RDh2yS728A6zJGRFDfuRDz81q+PGJ
	 BtdjOfqXBFiYdXiAj6+3YmupaYTm95XClEuTlyIQ8a6R59gfeq8RUZAlh1V+JqyqrPV9l
	 eERWrW17hSZHEuHnIjpTeJuZ5bj4v8l2iFrnA9yzzP/+EHCGqXfnuAnU8h1Rewbg0Jhuq
	 wtacD5Yh0QGMShVXD3nGSVlTeU1DxpWLRlWy8K/5y1dt6LNwE18lJr6NgnvSmy5lpybqG
	 AuVWWgJx21pmno49x+33VuZfS3N7ZyFK/AzWSTlXZu4b4hJShG6QHSPmzK6GM2bWXAQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793765740;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=t33hTerwq+aQ3mBUBeIWL6pRcgQAoxI6zsMD8gzG6mU=;
	b=36xGL7PgcgzQgV6rH6hUmCDsJ95YJ/a296JbcJ0Gm6vRIWp5fPX4GB+WQrDBCLu4KQbt
	 F4tQTfdCv89xKgAcOahFpQTfi2mKnulIxM2HvDYdPYOWX+dLyNmEs1QI1Z2oKWOhRUbIj
	 46laEpdWC6aLGFx/EGZZR6FTd2PCSHwnjoDLsELHy7YyLkDeXqxVJYsmClhYv5eLKNGQD
	 zgVKTPPZXdrJL9XLucsFcXVGzIcoi1YaKhnIpCuLUci0EBaF/BxO3rTCR19xiDDKN4Lib
	 avHpqvOD8T1M8FPHeX5SOo47B1cNoINZxRvinRylmwna7XfMDdY2FsyDANms4iz+CAw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Nm5tWPga;
	arc=none smtp.remote-ip=91.218.175.199
X-Received: from mta0.migadu.com (out-199.mta0.migadu.com [91.218.175.199])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2650E606A328
	for <netdev@vger.kernel.org>; Wed,  4 Nov 2026 04:15:37 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2650E606A328
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=NxfwJu25c702HsG2QS65lReEnsmm0Rh4tGfKZ6I/Ny4=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793765736; v=1; x=1794370536;
 b=Nm5tWPgalX68xFEfNNc38YSABIskZs6IG3VHTQJSocIT9xy+bmmlyDrpey5dO0uaTtE3Dxg2
 FlByApCrm5HoyBCjsWmgB3rQSOmlqx8bwsHCmfr5IN1jMcByvHN5l+GVTlUDRCh840ayfel0S83
 2LguG0x76ctHm9JLCq0RQ8t4=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 4202d724f29ea87b;
	Wed, 04 Nov 2026 04:15:23 +0000
X-Mizu-Trace-ID: 4202d724f29ea87b
X-Migadu-Flow: FLOW_OUT
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-User-Agent: Mozilla Thunderbird
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, kernel-team@meta.com
X-In-Reply-To: <20261103-sockopt_expand_out_v2-v4-1-2d36da923578@debian.org>