🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12994

[PATCH iproute2 v2 2/2] ip nexthop: use the request size as the limit when adding encap

#12994
From: Fang Jiabao
Date: Mon, 09 Nov 2026 05:32
58 lines
10785 bytes
ipnh_modify() passes a hardcoded 1024 as the size limit to addraw_l()
when it adds the encap attribute, and ignores the return value. Every
other attribute in this function is bounded by sizeof(req). If the encap
attribute does not fit, for example a seg6 encap with 59 segments,
addraw_l() prints "addraw_l ERROR: message exceeded bound of 1024" and
returns -1, but ip sends the request without the encap attribute and
exits with status 0. A nexthop without encap is then installed silently.

Use sizeof(req) as the limit, like the other attributes, and return an
error if addraw_l() fails instead of sending an incomplete request.

Fixes: 63df8e8543b0 ("Add support for nexthop objects")
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Fang Jiabao <kaquoin@163.com>
---
Changes since v1: new patch, the same problem in ip nexthop, as
requested by Stephen Hemminger.

Tested on current main (d95f6650, "man: ip-neighbour.8: document
protocol keyword"), in a network namespace with a dummy device, with:

  ip nexthop add id N via fc00:ee::1 dev d0 encap seg6 mode encap segs <N SIDs>

Before: with 59 segments or more, addraw_l() prints its error, the exit
status is 0 and the nexthop is installed without encap (observed on
e4cd9f1d, the only commit since then changes a man page). After: 58, 59
and 60 segments are added with encap, exit status 0. With 61 and 62
segments "addraw_l ERROR: message exceeded bound of 1048" is printed,
the exit status is 1 and no nexthop is installed.

The request buffer in ipnh_modify() is only 1024 bytes, so sizeof(req)
is barely larger than the old limit. I did not change the buffer size.

 ip/ipnexthop.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index ad8ad0c0..ae6a28d4 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -1108,10 +1108,10 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
 			lwt_parse_encap(rta, sizeof(buf), &argc, &argv,
 					NHA_ENCAP, NHA_ENCAP_TYPE);
 
-			if (rta->rta_len > RTA_LENGTH(0)) {
-				addraw_l(&req.n, 1024, RTA_DATA(rta),
-					 RTA_PAYLOAD(rta));
-			}
+			if (rta->rta_len > RTA_LENGTH(0) &&
+			    addraw_l(&req.n, sizeof(req), RTA_DATA(rta),
+				     RTA_PAYLOAD(rta)) < 0)
+				return -1;
 		} else if (!strcmp(*argv, "blackhole")) {
 			addattr_l(&req.n, sizeof(req), NHA_BLACKHOLE, NULL, 0);
 			if (req.nhm.nh_family == AF_UNSPEC)
-- 
2.43.0
Technical Details
Message-ID: <20261109053209.65753-2-kaquoin@163.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359035-linux-kernel-netdev=dewy.ru
References: <20261109053209.65753-1-kaquoin@163.com>

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-359035-linux-kernel-netdev=dewy.ru
From: kaquoin@163.com (Fang Jiabao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH iproute2 v2 2/2] ip nexthop: use the request size as the limit when adding encap
Date: Mon,  9 Nov 2026 13:32:09 +0800
Organization: Usenet Network
Message-ID: <20261109053209.65753-2-kaquoin@163.com>
References: <20261109053209.65753-1-kaquoin@163.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="281180"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pZTUhlBfLMV9TKnQIq+sNPfN+lY= sha256:0eyOmU2IMF5Qzy5bOFSMV6d6EdD7n+hgoC2FnLzwF/E=
	sha1:fPmrkcVSYI+jncAbPPQT4eWgLa0= sha256:MnzTeLXbESfH9Gp7emxyLMq6dh8XUEtg9houIHC2Qwk=
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 373241136DE; Mon,  9 Nov 2026 08:33:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, 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, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=163.com
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 R52UH5izvcgl;
	Mon,  9 Nov 2026 08:33:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359035-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 60975113461; Mon,  9 Nov 2026 08:33:36 +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 8E9DDA8058; Mon,  9 Nov 2026 05:33:01 +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=1794202381;
	b=srWTq7cbX7O/TbRcK0KQ7+GNItd76b35rqrURh05PXM5eeXUdfeg9eNbmbugyrE/UAtq
	 +d1Mwhhn7Xu9WybyY+KjDzUWE3qVp7s8tVSqMpF26qfuTbJLlEoP34ac9tVy+ObTxv4jd
	 aJkwlqyp8OsfghGSZsjguT/yugfqLmqvm8WWoELOViqmftzBa7+VI3zFCS3FqiDj/1uaw
	 0uQg2nriFDAims3dPuA8cF6FOAXduLckK7eATDq05Q7R+EdCdrRRJ8/kX0j6miqS5gmoc
	 H2lKP9YFXErUgS+UKgoG48giH1gdt7OgZXFttcwvHdHEGF7/KwIG4zN2lhdY4SHBaOQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794202381;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=M9ZETq7T1R9UCyvYbLAPs+OEJSYPIyDzuF8XiKAv+tI=;
	b=gBde+klAH/2mO6+u7yV/6EIfHfX4te8kpYpf/w+23gd/0tulo7I1YckavZe0w7DUvSzV
	 1IZKj4iMWJWZDFOdCpKAiUMnS0TUeH69LPBGVxMDEWbX0Rvihs9eQ4/w5ntlqv52ZI7DT
	 m60L8cWDjmqMF6n204fjXjhOv79buYXlCi8lyyhDLEhFvabuNqfo9ar5hM9gbveZtvvq3
	 E5fC6507lCExmPrpAA66BgdIeHfb/tz86mT8vfQb1PIfBfd+pZN2fKeBD63AewJFSObCE
	 +XSQpkQZPZrujk/mGHFHu+W8LOj+uVruKHlw4I1Rp4eAQikGf6NSPrqX7B9r4WiluYA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ER1getbt;
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	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 0594D606A331;
	Mon,  9 Nov 2026 05:33:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ER1getbt
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.2
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794202370;
	b=Vi1mNKLaV8ZPOkC2nVqPf118+V8SUtKJWMSCXs22BsnNpKx/KSKnJVEg15ZeLZXD9ShJ
	 3aDmasEjN605NyO8Hhc8N/1vkjZdbiMh31WiJHVSqFe8++y6Wy3pE0hj51uE1aCAK2QzP
	 TA0+37mNTB5fDRpg/7EUoUKJrHnPLTBbY2Bkmlwk2DhbklHnHZj9jvmzxSoaSxp6ps33v
	 Gube8TyF+pXIT60HEuvOdsPuT7uW3RJlDHvRJgUS9j9aRV3dLZfoSGiZFl+xZxvoNDVvu
	 BvHL0hVhvEfmikditGI9VahGpLe1vQMePBkNfZnIWoMyaWR2xYjWanDGDDP6fHOcgTg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794202370;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=M9ZETq7T1R9UCyvYbLAPs+OEJSYPIyDzuF8XiKAv+tI=;
	b=y2tLuUINgzHvWRGsM7t+yVrCKic9/k6kcWS++g4T9c409kf8B8pNx4mKW+O0QFttKcwu
	 qJvTP4d93HnqpFfpCx6WTKtFQaci2Mgz+qu6wgXfFWfqw+jvddLIaYRhfpVg90nuniyGF
	 qsKcak4BxIfGsTwDO3PlsugBZbUvzUHdZjO17RGihhkWV5l2Zp1W9Yku6lIZ4H8SV44tV
	 lyx7EGk+BeaJ99wqKJ7s5vqeuwhpoP9Av0vK1w4hgSD16maGTS4Ohqk4H29VhaResfWBJ
	 PPgIL4tsmhwgFIuGhvdfOKApxWIYqctAxnffvJ5OHrWzk/cQUzHDBdFDZ62YrFkB7Xg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ER1getbt;
	arc=none smtp.remote-ip=220.197.31.2
X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AEFC606A31C
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 05:32:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4AEFC606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
	s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=M9
	ZETq7T1R9UCyvYbLAPs+OEJSYPIyDzuF8XiKAv+tI=; b=ER1getbt7GwEtXuQvH
	GTKsQM1zxnebEWJMQ6BAo4XQqeB4pazDnuuoTd/Qec2bJTtPDNkyTov0HJHil5To
	yaNrlM0sKK7O7uEbUPbrkGUf2gSVfJz313o82io1wNSceMX/ndmuRKOLVjm5EC2a
	iy1X31lf+AgD8goMRyOzibFw4=
X-Received: from device-ubuntu.localdomain (unknown [])
	by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wD3v47gWvFq37XTFw--.24970S3;
	Mon, 09 Nov 2026 13:32:36 +0800 (CST)
X-Cc: netdev@vger.kernel.org,
	Fang Jiabao <kaquoin@163.com>
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261109053209.65753-1-kaquoin@163.com>
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-CM-TRANSID: _____wD3v47gWvFq37XTFw--.24970S3
X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw13Kr13Jw4fJFy8ZrW7CFg_yoW5Jr48pF
	Z3KFWDtrZ5JrWIya9rta1Ik3yUCw4xKayUCF1vk34qyFs8WF1SvFyIyrWYgrWUG397Jw4k
	trZrKw15GFWq93DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRsa9-UUUUU=
X-CM-SenderInfo: 5ndt30llq6il2tof0z/xtbC9RTqX2rxWvTb2QAA3j