Article View: linux.kernel.netdev
Article #21586Re: [PATCH iproute2] seg6local: fix crash when next-csid ends the command
From: Frank Dressler
Date: Tue, 24 Nov 2026 07:56
Date: Tue, 24 Nov 2026 07:56
65 lines
10764 bytes
10764 bytes
> ip crashes when "flavors next-csid" ends the command, with or without
> "lblen N":
>
> ip -6 route add 2001:db8:2::/64 dev lo encap seg6local action End \
> flavors next-csid
>
> seg6local_parse_flavors() steps past the last argument and passes the
> NULL terminator to strcmp(). Check argc first.
>
> Fixes: 04a6b456bf74 ("seg6: add support for flavors in SRv6 End* behaviors")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
> ---
> ip/iproute_lwtunnel.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
> index 9a1e747c..53004b5f 100644
> --- a/ip/iproute_lwtunnel.c
> +++ b/ip/iproute_lwtunnel.c
> @@ -1434,7 +1434,7 @@ static int seg6local_parse_flavors(struct rtattr *rta, size_t len,
>
> if (flavors & (1 << SEG6_LOCAL_FLV_OP_NEXT_CSID)) {
> NEXT_ARG_FWD();
> - if (strcmp(*argv, "lblen") == 0){
> + if (argc > 0 && strcmp(*argv, "lblen") == 0) {
> NEXT_ARG();
> if (lbl_ok++)
> duparg2("lblen", *argv);
> @@ -1444,7 +1444,7 @@ static int seg6local_parse_flavors(struct rtattr *rta, size_t len,
> NEXT_ARG_FWD();
> }
>
> - if (strcmp(*argv, "nflen") == 0){
> + if (argc > 0 && strcmp(*argv, "nflen") == 0) {
> NEXT_ARG();
> if (nfl_ok++)
> duparg2("nflen", *argv);
Good find, and your change fixes the segfault.
But I think the way you fix it is a bit uncommon in the code base that
seems to instead prefer a pattern like
while (NEXT_ARG_OK()) {
NEXT_ARG_FWD();
if (strcmp(...) == 0) {
...
} else if (strcmp(...) == 0) {
...
} else {
PREV_ARG();
break;
}
}
for parsing a list of optional arguments in any order.
With that style, you would also fix another bug which is that it
currently expects lblen and nflen in that specific order which
contradicts the man page that allows them in any order.
The presence of the if (lbl_ok++) and if (nfl_ok++) also seem to
indicate that the code was originally intended to run in a loop.
Technical Details
Message-ID:
<a5b77684-1041-49ed-8fd6-567e6896476d@dressler.pro>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370087-linux-kernel-netdev=dewy.ruReferences:
<20261124055551.3390282-1-dave.seddon.ca@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370087-linux-kernel-netdev=dewy.ru From: frank@dressler.pro (Frank Dressler) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH iproute2] seg6local: fix crash when next-csid ends the command Date: Tue, 24 Nov 2026 07:56:52 +0000 Organization: Usenet Network Message-ID: <a5b77684-1041-49ed-8fd6-567e6896476d@dressler.pro> References: <20261124055551.3390282-1-dave.seddon.ca@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="4083218"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:b2PbfJbeuq8LFQfXpw4b4pTfKek= sha256:71NOvC6bpPsL5VkAv91Qlm3Vz89Wwo8q6VRkqLIEl2Y= sha1:TkBxndx0EKJh9jjCOO0wTFvwixU= sha256:kNnD76XAliWQZXcrNjGr8C7c1pmREL7rJ4JhL7hxrrc= Content-Language: en-US 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 07EDF125DDC; Tue, 24 Nov 2026 10:57:18 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.05 X-Spam-Status: No, score=-2.05 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, MAILING_LIST_MULTI=-1, PDS_PRO_TLD=1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=dressler.pro 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 UZDIstaNMlZZ; Tue, 24 Nov 2026 10:57:14 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370087-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=dressler.pro X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 30C4B125DD7; Tue, 24 Nov 2026 10:57:06 +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 DA4B932CFD; Tue, 24 Nov 2026 07:57:03 +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=1795507023; b=w3xYzBtv5ZxTwOGeJavAVJ+yKtqMG6IPFbR6WRWR95+KR5iuexrRF8tQ4whJ/xC7LwGO e066z257961QJamdtFvJD/PNpgodDFFsPcI/5M/QhP5X8g1jbvUPfZCpIcOK8qrCsZrDK Auxc4pLIpeaxfQWq1nRAS5WMePimxgo86zUeczPd1BpTNGur/lxwuh1NSU7ofnRg10hbf WO7QzGNlERZhiAwrgkG3LBf9RFm/WsBVoSZlp24wcvup13TSEHl5tBCUQ/Bugx40Vb5ue ThrLE5/z8Eb3IxZJYzq+IZn4xPzEZ1XtfWS+67Oa80sXalo6YwrhhOArTl9TBhc0B6w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795507023; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: 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:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=v8qY578zeHnJhveG6usYiBXRuMFtPQLfHFwkDhYx4U4=; b=yhMIoTS5UkeE7ObUzAyejPVqK2A7Qe9WlDe2QCkh4CXU4RyueGgLl/iaRC2S0RUbkjhW f7HhHaorCRyeKiWHVY9Pi7V5dcj0HfuYoar37H9hsAKjesqH5kpmUwNI0BHuQP4QN6SkX i4AR6AoMyYlccl/mrdC1+e6mivjyKoVieFeNWeWBW3KHovPsWZqylnUF0aLhJeQFJoet8 +CVSzvciGLXKtTX+AkG8Je9OesnGtgRileuxRtTULWMQG6RoqwcU8NOeB3usc4ajfDvWs T7LuPMiy64rTs11FNF+m5+A6xA9c4eDeCWrjnSZ1DpRuNmIzbcpq2c0KnGl1osd2TGw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=dressler.pro header.i=@dressler.pro header.a=rsa-sha256 header.s=uddkim-202310 header.b="cKLw/W0z"; dmarc=pass header.from=dressler.pro; spf=pass smtp.mailfrom=dressler.pro; 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 AE629606A330; Tue, 24 Nov 2026 07:57:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dressler.pro header.i=@dressler.pro header.a=rsa-sha256 header.s=uddkim-202310 header.b=cKLw/W0z X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.146.106.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795507022; b=ClCxNjMA3GcgO9COjIdGEHLmSdgh/Hg+ZCFClSFDHpNCbjwMLwMSMA8oU+RJqfjKp7E8 w0GgWX5K02BI9caNQPtjcmBvwVbIM0nQm4AO7/iOChDcCy5zkZQ9ow6qoOpFRAlIEWtC6 /Kkuq2y8mFqnlSW6teSi+yzuihohTkqV8b+I0G9LL+GEcvG/36MKWB1QoAHWBSFQoiu+H uhmTngGHZYTQxwY9Uk3ghgEcmKO19aQ1S1cHaZDzSPHZiJAA+MkRbL/getxkNFMi4xqG/ 9BHv3GT7uZlTaiVLLVC7Z8CUcCL52xN6a0XSoSqEQIJtlXPDf7aXqdHB3aXyxtNaArA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795507022; h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=v8qY578zeHnJhveG6usYiBXRuMFtPQLfHFwkDhYx4U4=; b=NBKb+Uu2odOYHo3ELgsUrfeeS8pNfo3OAVRU2/DHNaQuC+8hJk+QWZAr1adF/cl7wY/Y k1Tp8KbJxcIo1Hy/68QYF36aEcmNvlVWGAB5Uof2Az9TPRCsd3dEheKUnYgAa8RuRYphu OQOi6SkG+OwHIor58472smBaVn3PyVnjbyNiJ58HArPPo1yYGxl6U+9UYWPd9/McRsbkg +GIU1HqgVXLTMA6+K76emEwCJjhsh87aTU4pIfN4UFMs3ADRmQNe/YJZG42j639fzzw6O ra6sCzY8u+vE5haonJRXLwhiodH0gQN9JZPXrOXInua3tsnL3prj3Qp76o1hVT7UNGQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=dressler.pro; spf=pass smtp.mailfrom=dressler.pro; dkim=pass header.d=dressler.pro header.i=@dressler.pro header.a=rsa-sha256 header.s=uddkim-202310 header.b="cKLw/W0z"; arc=none smtp.remote-ip=62.146.106.18 X-Received: from smtp01-ext2.udag.de (smtp01-ext2.udag.de [62.146.106.18]) (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 DBE61606A321 for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 07:57:01 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DBE61606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dressler.pro X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dressler.pro X-Received: from [192.168.0.40] (unknown [37.228.226.218]) by smtp01-ext2.udag.de (Postfix) with ESMTPA id 71055E0BCF; Tue, 24 Nov 2026 08:56:53 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dressler.pro; s=uddkim-202310; t=1795507014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v8qY578zeHnJhveG6usYiBXRuMFtPQLfHFwkDhYx4U4=; b=cKLw/W0zcVljvMbpPchpl57ScKROc3/RCtjn1lHaIVyyMqslRbEpNSaDhXRtoOCPwxzjnv mjZ7x2fKukcOr0pzreKrAp9PjetifYlEhaYuaWi/xJGdx77jqMADmzOpJm7Bop2Y4wxBMK J4/5bYpe3VrAnSZC0sCFFoCukn3PRCNkdCBPmhvdU7khdh8rJ5Lyti+XGV96Lcn+ZILoEm bUylhcWu4BUOcF+of6Ac9o91rS7RsIrcEIxTzOzBOoCPnZarJEG2UOgKe7MMSAOVMK7jZG RA1Pq+a13t3oAofIRT38VBMnN93mJ3mgLbdklsqjfnmcij6jNZgdILmYa9Dmew== X-Authentication-Results: smtp01-ext2.udag.de; auth=pass smtp.auth=dressler-pro-0001 smtp.mailfrom=frank@dressler.pro 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: Stephen Hemminger <stephen@networkplumber.org>, David Ahern <dsahern@kernel.org>, Paolo Lungaroni <paolo.lungaroni@uniroma2.it> X-In-Reply-To: <20261124055551.3390282-1-dave.seddon.ca@gmail.com>