* [PATCH iproute2] seg6local: fix crash when next-csid ends the command
@ 2026-11-24 5:55 Dave Seddon
2026-11-24 7:56 ` Frank Dressler
[not found] ` <a5b77684-1041-49ed-8fd6-567e68964476@dressler.pro>
0 siblings, 2 replies; 3+ messages in thread
From: Dave Seddon @ 2026-11-24 5:55 UTC (permalink / raw)
To: netdev; +Cc: Dave Seddon, Stephen Hemminger, David Ahern, Paolo Lungaroni
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);
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH iproute2] seg6local: fix crash when next-csid ends the command
2026-11-24 5:55 [PATCH iproute2] seg6local: fix crash when next-csid ends the command Dave Seddon
@ 2026-11-24 7:56 ` Frank Dressler
[not found] ` <a5b77684-1041-49ed-8fd6-567e68964476@dressler.pro>
1 sibling, 0 replies; 3+ messages in thread
From: Frank Dressler @ 2026-11-24 7:56 UTC (permalink / raw)
To: Dave Seddon, netdev; +Cc: Stephen Hemminger, David Ahern, Paolo Lungaroni
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread[parent not found: <a5b77684-1041-49ed-8fd6-567e68964476@dressler.pro>]
* Re: [PATCH iproute2] seg6local: fix crash when next-csid ends the command
[not found] ` <a5b77684-1041-49ed-8fd6-567e68964476@dressler.pro>
@ 2026-11-24 15:57 ` Dave Seddon
0 siblings, 0 replies; 3+ messages in thread
From: Dave Seddon @ 2026-11-24 15:57 UTC (permalink / raw)
To: Frank Dressler; +Cc: netdev, Stephen Hemminger, David Ahern, Paolo Lungaroni
On Tue, 24 Nov 2026 07:56:52 +0000, Frank Dressler wrote:
> 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()) {
[...]
> 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.
Thanks for the review, Frank.
You're right about the ordering: "flavors next-csid nflen 16 lblen 32"
fails with '"lblen" is garbage', and the man page allows either order.
I'd like to keep this patch as the minimal crash fix, and send the loop
conversion as a separate patch on top, since it changes what the parser
accepts. I'll post that as a follow-up. If people would prefer a single
patch, I'm happy to send a v2 instead.
Thanks,
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 15:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 5:55 [PATCH iproute2] seg6local: fix crash when next-csid ends the command Dave Seddon
2026-11-24 7:56 ` Frank Dressler
[not found] ` <a5b77684-1041-49ed-8fd6-567e68964476@dressler.pro>
2026-11-24 15:57 ` Dave Seddon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox