Article View: linux.kernel.netdev
Article #12955Re: [PATCH iproute2] ip route: check return value of addraw_l() when adding encap
From: Stephen Hemminger
Date: Mon, 09 Nov 2026 02:54
Date: Mon, 09 Nov 2026 02:54
95 lines
14690 bytes
14690 bytes
On Mon, 2 Nov 2026 17:05:34 +0800
Fang Jiabao <kaquoin@163.com> wrote:
> iproute_modify() ignores the return value of addraw_l() when it adds
> the encap attribute. If the attribute does not fit into the request,
> for example a seg6 encap with 60 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 route without encap is then installed silently.
>
> Return an error instead of sending the incomplete request.
>
> Fixes: 1e5293056a02 ("lwtunnel: Add encapsulation support to ip route")
> Assisted-by: Claude:claude-sonnet-5-5
> Signed-off-by: Fang Jiabao <kaquoin@163.com>
> ---
> Tested on current main (e4cd9f1d, "json_writer: fix pretty printing of
> arrays"), in a network namespace with a dummy device:
>
> ip -6 route add fc00:ff::60/128 encap seg6 mode encap segs <60 SIDs> dev d0
>
> Before: "addraw_l ERROR: message exceeded bound of 1024", exit status 0,
> and a route without encap was installed.
> After: same message, exit status 1, no route installed.
> With 59 segments the route is still added with encap, exit status 0.
>
> With 63 or more segments the failure happens earlier, in the encap
> parsing, with a different error. That is not addressed here. The same
> addraw_l() pattern exists in ip/ipnexthop.c and is not changed here.
>
> ip/iproute.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
I agree with AI review here:
The bug is real and worth fixing - thanks. I reproduced the
error-then-send behavior: with 60 segments the unpatched ip prints the
addraw_l error and still hands the request to the kernel (the reply
proves the send). Exit 0 follows from the ignored return value, matching
your test. Silently installing a route without the requested encap is
the worst possible outcome here.
But please fix the cause rather than the symptom.
> - 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, 1024, RTA_DATA(rta),
> + RTA_PAYLOAD(rta)) < 0)
> + return -1;
The request buffer is 4096 bytes:
struct {
struct nlmsghdr n;
struct rtmsg r;
char buf[4096];
} req = { ... };
so the hardcoded 1024 is simply wrong - it is a leftover that bears no
relation to the actual buffer. Every other attribute in this function
passes sizeof(req); this call site is the only one using a magic number.
That matters because the 60-segment case you hit is not actually too
big for the message. It only exceeds the bogus 1024 limit. Using the
correct bound:
if (rta->rta_len > RTA_LENGTH(0) &&
addraw_l(&req.n, sizeof(req), RTA_DATA(rta),
RTA_PAYLOAD(rta)) < 0)
return -1;
I tested this and the 60-segment route is accepted and passed to the
kernel instead of being rejected. Segment counts up to 62 work; at 63
the 1024-byte rta buffer in iproute_modify becomes the limiting factor
and it fails there with a clear error - which is the earlier failure you
noted.
So your patch makes a working command fail loudly, while fixing the
bound makes it work. Keep the return-value check - it is correct and
still needed for genuinely oversized attributes - but combine it with
sizeof(req).
> The same addraw_l() pattern exists in ip/ipnexthop.c and is not
> changed here.
Please fix it in the same series; it is the identical bug with the
identical 1024, and leaving one copy behind just means someone
rediscovers it later. Two small patches are fine.
Otherwise the patch is well formed - builds clean, the Fixes tag
resolves correctly, and the commit message states the problem and the
reproducer clearly. Please respin.
Technical Details
Message-ID:
<20261108185420.1d3dba55@phoenix.local>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358988-linux-kernel-netdev=dewy.ruReferences:
<20261102090535.226168-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-358988-linux-kernel-netdev=dewy.ru
From: stephen@networkplumber.org (Stephen Hemminger)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH iproute2] ip route: check return value of addraw_l()
when adding encap
Date: Sun, 8 Nov 2026 18:54:20 -0800
Organization: Usenet Network
Message-ID: <20261108185420.1d3dba55@phoenix.local>
References: <20261102090535.226168-1-kaquoin@163.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="256921"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uUM6ek+uhC6qwDNK8OYvCMt37EI= sha256:eL7YQVz6ehTnoXtIZKU8r5ki4v/cQ9PKNtM2/AeFU/Y=
sha1:oYAbDn/ps5zORgFM/fv0dM0cwHk= sha256:RGDnBn6pazNCafGBRA9qWgZM4Cn6Xb5NZNyAxVLgQ08=
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 399441136AF; Mon, 9 Nov 2026 05:54:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-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=networkplumber-org.20260707.gappssmtp.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 9vaoQa0BnC6g;
Mon, 9 Nov 2026 05:54:42 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358988-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=quarantine dis=none) header.from=networkplumber.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 5F792113671; Mon, 9 Nov 2026 05:54:34 +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 523E3C4E58; Mon, 9 Nov 2026 02:54:25 +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=1794192865;
b=ntcheBEmmoVwh0DxwGTIy9dyf8FNaPIeAI27WbaoIS9snAT395seiAj0ydu3GhwNJ5jX
ysPw1rn4Cc/gkG/d7sSUuIu96/xP2eaReHxJCFvnHNZU+DMVEDV1Dnc1Hvwjn2Z33xrIu
UfKiHM5Q9bdXR9Lk6I3evlpL3kRoJT0KcCt5RQP1kCEfLz7ixuv3QuM+JelFo3DedNtVt
XZ1HpSiaSFQXG4Y1tqydNyG49qdCFQ9eE5Cxxzw2b+9sWg+6nvsdaXh0lsz/LKkc71RXO
fKu4xN7sPCw8+T1d4tbowFSgI11Tc+oujJKiZGil4tKbJuPrOXG8A6iqQLD1sDLnE9g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794192865;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=YFiFvM32hOcR5Y90zApzECJ7RVHYz69VRXl9qwib/qo=;
b=xgF76bVTxc6M1XeDBgt+hQoWb/ecxODWGgKxtBfBfVQniMzUD5E/kDFl+1Z/JtDKIOcr
/szJ5tgv7jP/E1NGNcsrm9rK4YCo4i4XRnICvePS1zQWBSmwP+52Yh0Bn9CZyYPNatPQT
hTZWTAj5Y8phPQOffOqmc3KVhFcbrP8+ojZUYeCUQuMQF5uLr9cOIpvqQQi+4iVtcc6Th
ulp2h/9dSunbpNUeIB6zXYrUuXlKfP38FW6iEaQM7m5AyhDIAP/CGyyVhtBojjNUSYq2I
ERadnHSVWAnH5GBOQgqFASinqJVWVeKWxFGvi+Vwg8Liccv6ZahiU1vYWjtM53M/IQw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=gMh86AzT;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.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 29CFA606A326;
Mon, 9 Nov 2026 02:54:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=gMh86AzT
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.174
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794192864;
b=q9GppLDzIRwf6oih955xRPsPL9TswWoRV5crNlwFcD8mkLnxLzp34cL/ITHnS/F0Mwgc
sOe2yzr8pRCsALKOCy+SdR94+2P+AGNsvXBqkKPe1K6pUdyUGvsvg4mcaTZsyYirzSn35
OZHSfbD/zpW5zQ9Ti25mGILsXwGJAvKk0Qjn/0ByLLOdTWsLTnvdvHFwShBaAEVMBY/gv
jChpcSrBoHEG2b6aCEEFm8PDdx8JS7OXBVDMX1ujloGzI14EHCNjyMScg3mAVnMxc5+By
8I/AaNwmp+MZHEnH7W9X9I0jY+JBADTV0jgszoODismCRCQfBvKOfwkrDu9mlOu6rHQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794192864;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Subject:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=YFiFvM32hOcR5Y90zApzECJ7RVHYz69VRXl9qwib/qo=;
b=EpUrpDC6I3fWgDNgEBLenHlG6itNnQz2lJIdx7VHFgBvglZildsBSbJd7QMRhgdw/PaK
GUMCZTVTLG9AFssdWDM89aEzhxJE3aAxmdGvKIbQGpBJFiiXM7HbiTIlHGy01rhQkOF9N
bY/12uOUGpOQcB4dmHDhoUtTL+k6No0CQeGFvHxcSdVUHAquIlDc+xZBEEUNYbMT3ma3m
5nqOt18mNTugfnpRhJ72/LPMv88OTcJgzPheTAlcQGzLnFla5bDwOgb8JlWF5rgllgRHS
1L9+EQ7/fxakdpkQmyNrypO27bvN01ulueMdr9DtXPAlgO/Qw+/k9TyNIotnGhQqLtw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=gMh86AzT;
arc=none smtp.remote-ip=209.85.210.174
X-Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174])
(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 8D648606A31C
for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 02:54:23 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8D648606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org
X-Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8a052aff9e9so294931b3a.0
for <netdev@vger.kernel.org>; Sun, 08 Nov 2026 18:54:23 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1794192863; x=1794797663; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=YFiFvM32hOcR5Y90zApzECJ7RVHYz69VRXl9qwib/qo=;
b=gMh86AzTUxJsjktaXCiWQhVjfcIZq34kh9cg7PRORFrBK0/f4OWqfeQY/Uthvvb8VT
oBsyotvQS4Ukkt+mTLCQ6ff25GUR5oBWKvQiiBkdC3LFG4OFr3cVarUvOCbAaEwLPAPq
0ZbTUdxo1TGIkkxsQBScdYjYciBWP4RO5PHn2prt12a05D/IblRxUYIQyGk+wwCQNSho
LPJLVOOCd9MaTqpMo8ahQ+oMIyDXtXvjSu+OPb6KOAu0t881srQ4iDhUwlTWm8J2SaFR
3qSfznAvoW1XdDRKITQIgs154Q5WLnI+FGmFSoxkmEJm/UOpr3VqMwq3a317gDaXlQST
4nWQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794192863; x=1794797663;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date: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gWgbaWGMiHySjpTpH7K68NAeJifvSfeN0IuWLWw3
Q4Az3ov5u1a1/Hj38KrE4674MuTl3rM2YCSBJJktip2h1PuN35REQ35kWtMvhAIdA3DAYvwxKSq
ecLNo44j2341gXIK0AQF8vRw+VlGc2l9GItUSm7ot32np9DYJLePSMPz7wzVde3FJRG/SOkY
X-Received: by 2002:a05:6a00:3289:b0:8a0:58c3:8ceb with SMTP id d2e1a72fcca58-8b67026524dmr2442507b3a.45.1794192862733;
Sun, 08 Nov 2026 18:54:22 -0800 (PST)
X-Received: from phoenix.local (204-195-112-43.wavecable.com. [204.195.112.43])
by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b649b0d50fsm883376b3a.40.2026.11.08.18.54.22
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 08 Nov 2026 18:54:22 -0800 (PST)
X-Cc: netdev@vger.kernel.org
X-In-Reply-To: <20261102090535.226168-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