All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ahmed S. Darwish" <darwi@linutronix.de>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Julian Braha" <julianbraha@gmail.com>,
	"Emanuele Rocca" <ema@debian.org>,
	"Clark Williams" <clrkwllms@kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ingo Molnar" <mingo@redhat.com>
Cc: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"John Ogness" <john.ogness@linutronix.de>,
	"Derek Barbosa" <debarbos@redhat.com>,
	"Zbigniew Jędrzejewski-Szmek" <zbyszek@amutable.com>,
	"Daan De Meyer" <daan.j.demeyer@gmail.com>,
	"Luca Boccassi" <luca.boccassi@gmail.com>,
	linux-rt-devel@lists.linux.dev, debian-kernel@lists.debian.org,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/11] kconfig-audit: Add the configuration checker code
Date: Fri, 04 Dec 2026 22:50:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-250775@kernel.org> (raw)
In-Reply-To: <20261203224916.118064-4-darwi@linutronix.de>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] kconfig-audit: KernelConfigFile.parse() rejects unprefixed
  hex values
- [Medium] kconfig-audit: _find_pattern_rule_issues() suppresses
  missing-match errors
- [Medium] kconfig-audit: _map_pattern_rules() aborts on overridden
  pattern conflicts
- [Low] kconfig-audit: main() resolve() breaks /dev/stdin and pipe
  .config inputs
--

commit 0d8e21444fcb5c1a080849e8db605e829f900e3e
Author: Ahmed S. Darwish <darwi@linutronix.de>

kconfig-audit: Add the configuration checker code

This commit introduces tools/kconfig-audit/audit.py to parse kernel .config
files and YAML policies into an internal data model and report policy
violations by severity.

> diff --git a/tools/kconfig-audit/audit.py b/tools/kconfig-audit/audit.py
> new file mode 100755
> index 0000000000000..6ff4a56281ad2
> --- /dev/null
> +++ b/tools/kconfig-audit/audit.py

[ ... ]

> +            if val in ('y', 'm'):
> +                config.add_bool_symbol(name, True)
> +            elif re.fullmatch(r'0[xX][0-9a-fA-F]+', val):
> +                config.add_hex_symbol(name, int(val, 16))
> +            elif re.fullmatch(r'-?[0-9]+', val):
> +                config.add_int_symbol(name, int(val))
> +            elif len(val) >= 2 and val[0] == '"' and val[-1] == '"':
> +                config.add_str_symbol(name, val[1:-1])
> +            else:
> +                error(f'Invalid .config assignment: {line}', os.EX_DATAERR)

[Severity: Medium]
Does KernelConfigFile.parse() reject valid Kconfig hex values that omit the
0x prefix?

Kconfig's sym_string_valid() treats the 0x/0X prefix as optional for S_HEX
symbols, and print_symbol_for_dotconfig() writes them verbatim to .config.
An in-tree option like CONFIG_RADIO_GEMTEK_PORT=34c (from
drivers/media/radio/Kconfig) will fail to parse and abort with
os.EX_DATAERR.

Explicit disabled boolean assignments (CONFIG_FOO=n) are also rejected with
os.EX_DATAERR instead of being parsed as BooleanSymbol(name, False).

[ ... ]

> +    def _map_pattern_rules(self) -> PatternRuleMap:
> +        """Map each .config symbol to highest-priority matching pattern rule, if any"""
> +        pattern_map: dict[Symbol, PatternRule] = {}
> +
> +        for symbol in self.kconfig.symbols.values():
> +
> +            # No matching pattern rules for symbol
> +            rules = self.policy.get_pattern_rules_for(symbol.name)
> +            if not rules:
> +                continue
> +
> +            highest_prio = max(rule.pattern_prio for rule in rules)
> +            highest_prio_rules = [
> +                rule for rule in rules if rule.pattern_prio == highest_prio
> +            ]
> +
> +            if len(highest_prio_rules) > 1:
> +                patterns = '\n\t'.join(
> +                    rule.regex.pattern for rule in highest_prio_rules
> +                )
> +                error(
> +                    f'{symbol.name} is covered by multiple pattern rules with '
> +                    f'priority {highest_prio}:\n\t{patterns}',
> +                    os.EX_DATAERR,
> +                )

[Severity: Medium]
Should _map_pattern_rules() skip symbols that already have an exact
SymbolRule?

_find_pattern_rule_issues() gives exact symbol rules precedence over all
pattern rules and never consults pattern_rules_map for them.  Without
skipping those symbols here, a policy that resolves an overlap between two
equal-priority pattern rules via an exact SymbolRule still aborts with
os.EX_DATAERR.

[ ... ]

> +    def _find_pattern_rule_issues(self, rule: PatternRule) -> list[Issue]:
> +        """Check .config against a pattern rule and return any issues"""
> +        wrong_type_symbols: list[str] = []
> +        wrong_value_symbols: list[str] = []
> +
> +        matched_symbols = False
> +
> +        for symbol in self.kconfig.get_matching_symbols(rule.regex):
> +            # Record the regex symbol match before applying overrides
> +            matched_symbols = True
> +
> +            # An exact rule for symbol overrides all pattern rules
> +            if self.policy.get_symbol_rule(symbol.name):
> +                continue
> +
> +            # Higher-priority patterns overrides us
> +            if self.pattern_rules_map.get(symbol) is not rule:
> +                continue
> +
> +            if not isinstance(symbol, BooleanSymbol):
> +                wrong_type_symbols.append(symbol.name)
> +                continue
> +
> +            if Checker._expected_enabled(rule) != symbol.value:
> +                wrong_value_symbols.append(symbol.name)
> +                continue
> +
> +        issues: list[Issue] = []
> +
> +        if Checker._expected_enabled(rule) and not matched_symbols:
> +            if not self.policy.get_symbol_rule_matching(rule.regex):
> +                msg = 'does not match any enabled kconfig symbol'
> +                issues.append(self._make_regex_issue(rule, msg))

[Severity: Medium]
Can _find_pattern_rule_issues() silently pass an expected: enabled
PatternRule when zero matching symbols are enabled in .config?

matched_symbols is set to True before skipping symbols overridden by an
exact SymbolRule or a higher-priority PatternRule.  If .config only has
disabled entries that are overridden by a neutral or disabled rule, every
symbol is skipped and neither a PatternIssue nor a RegexIssue is reported.

Likewise, when no symbols in .config match rule.regex,
get_symbol_rule_matching() suppresses the RegexIssue if any matching
SymbolRule exists, even when that rule is expected: neutral or disabled.

[ ... ]

> +    kconfig_f = args.config.resolve()
> +    kconfig = KernelConfigFile(kconfig_f).parse()

[Severity: Low]
Will args.config.resolve() break piped inputs such as /dev/stdin or shell
process substitution like <(zcat /proc/config.gz)?

On Linux, /dev/fd/N for a pipe is a magic symlink whose readlink() target is
a pseudo-name like pipe:[123456], which Path.resolve() turns into a
nonexistent /proc/<pid>/fd/pipe:[...] path and makes
KernelConfigFile.__init__() fail with ENOENT.

Calling resolve() outside KernelConfigFile.__init__()'s OSError handler also
leaves symlink-loop errors uncaught instead of exiting with os.EX_NOINPUT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203224916.118064-1-darwi@linutronix.de?part=3

  reply	other threads:[~2026-12-04 22:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 22:49 [PATCH v2 00/11] tools: Introduce a kernel configuration checker Ahmed S. Darwish
2026-12-03 22:49 ` [PATCH v2 01/11] kconfig-audit: Add schema for policy files Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 02/11] kconfig-audit: Introduce a PREEMPT_RT configuration policy Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 03/11] kconfig-audit: Add the configuration checker code Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot [this message]
2026-12-03 22:49 ` [PATCH v2 04/11] Documentation: Describe kconfig-audit usage and design Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 05/11] kconfig-audit: Split policy schema for component reuse Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 06/11] kconfig-audit: Introduce policy overlays schema Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 07/11] kconfig-audit: Add support for policy overlays Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 08/11] Documentation: kconfig-audit: Describe " Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 09/11] MAINTAINERS: Add entry for kernel configuration audit Ahmed S. Darwish
2026-12-03 22:49 ` [PATCH v2 10/11] kconfig: Introduce auditconfig target Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot
2026-12-03 22:49 ` [PATCH v2 11/11] Documentation: Describe auditconfig build target Ahmed S. Darwish
2026-12-04 22:50   ` sashiko-bot

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=sashiko-outbox-250775@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=clrkwllms@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=darwi@linutronix.de \
    --cc=debarbos@redhat.com \
    --cc=debian-kernel@lists.debian.org \
    --cc=ema@debian.org \
    --cc=frederic@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=julianbraha@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=luca.boccassi@gmail.com \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zbyszek@amutable.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.