BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hangbin Liu" <hangbin.liu@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v3 2/6] tools: ynl: convert enum selector to string for sub-message parsing
Date: Thu, 01 Oct 2026 01:51:34 +0000	[thread overview]
Message-ID: <20261001015134.963061F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260930-ynl_rt_encap-v3-2-4106c21b9ee7@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ynl: early return 0 aborts entire parsing loop on unknown sub-message
- [Medium] ynl: invalid C code generated for external enum selectors
--

commit f2c434cd3f008807f1723585dcbfd634aa3f28b7
Author: Hangbin Liu <liuhangbin@kylinos.cn>

tools: ynl: convert enum selector to string for sub-message parsing

YNL sub-message parsing expects a string selector for strcmp(). So for
non-external enum selectors, convert the integer value to its string form
via the family's {enum}_str() helper. This enables correct decoding of
sub-messages keyed by enum values.

> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index 15c79849c6096..783242537fe48 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -951,13 +951,31 @@ class TypeSubMessage(TypeNest):
>              sel_var = f"_sel_{sel}"
>          else:
>              sel_var = f"{var}->{sel}"
> -        get_lines = [f'if (!{sel_var})',
> -                     f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");',
> -                     f"if ({self.nested_render_name}_parse(&parg, {sel_var}, attr))",
> -                     "return YNL_PARSE_CB_ERROR;"]
> +
> +        local_vars = None
> +
> +        if self.selector.is_enum_val():
            ^^^^

[Severity: Medium]
Will this generate invalid C code for external enum selectors?

The condition doesn't check if the selector is external. If a YAML spec
defines a sub-message with an external enum selector, it appears this will
generate a non-existent structure member access for the presence variable:

    pres_var = f"{var}->_present.{sel}"

and try to pass the string pointer to the enum string helper, which expects
an integer. Should this check include `and not self.selector.is_external()`?

> +            enum = self.family.consts[self.selector.get_enum_name()]
> +            pres_var = f"{var}->_present.{sel}"
> +            parse_sel = f"{sel}_str"
> +            local_vars = [f'const char *{parse_sel};']
> +
> +            get_lines = [
> +                f'if (!{pres_var})',
> +                f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");',
> +                f'{parse_sel} = {enum.render_name}_str({sel_var});',
> +                f'if (!{parse_sel})',
> +                'return 0;']
                 ^^^^

[Severity: High]
Does returning 0 here abort the entire parsing loop?

If a generated YNL parser encounters an unrecognized sub-message enum
selector (for example, sent by a newer kernel), it looks like `return 0;`
executes directly inside the attribute loop of the parsing function.

This would silently abort processing the remainder of the Netlink message and
drop all trailing attributes without returning an error. Is it possible to
skip the attribute and continue parsing instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930-ynl_rt_encap-v3-0-4106c21b9ee7@kylinos.cn?part=2

  reply	other threads:[~2026-10-01  1:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  1:50 [PATCH net-next v3 0/6] netlink: add lwtunnel encap sub-message support to rt-route Hangbin Liu
2026-09-30  1:50 ` [PATCH net-next v3 1/6] net: lwtunnel: change encap fill order Hangbin Liu
2026-10-01 14:09   ` Ido Schimmel
2026-09-30  1:50 ` [PATCH net-next v3 2/6] tools: ynl: convert enum selector to string for sub-message parsing Hangbin Liu
2026-10-01  1:51   ` sashiko-bot [this message]
2026-10-03  6:23     ` Hangbin Liu
2026-10-05 22:33       ` Jakub Kicinski
2026-09-30  1:50 ` [PATCH net-next v3 3/6] netlink: specs: rt-route: add lwtunnel encap sub-message support Hangbin Liu
2026-09-30  1:50 ` [PATCH net-next v3 4/6] netlink: specs: rt-route: describe lwtunnel IP options Hangbin Liu
2026-09-30  1:50 ` [PATCH net-next v3 5/6] netlink: specs: rt-route: describe lwt BPF program options Hangbin Liu
2026-10-01  1:51   ` sashiko-bot
2026-10-03  6:09     ` Hangbin Liu
2026-09-30  1:50 ` [PATCH net-next v3 6/6] netlink: specs: rt-route: describe seg6-local attrs Hangbin Liu
2026-10-01  1:51   ` sashiko-bot
2026-10-03  6:17     ` Hangbin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001015134.963061F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hangbin.liu@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox