Article View: linux.kernel
Article #63Re: [PATCH v2 03/11] kconfig-audit: Add the configuration checker code
From: sashiko-bot
Date: Fri, 04 Dec 2026 23:10
Date: Fri, 04 Dec 2026 23:10
167 lines
9330 bytes
9330 bytes
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
Technical Details
Message-ID:
<O6KzD-g1p2-13@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!bofh.it!news.nic.it!robomodReferences:
<O6o65-fPfD-3@gated-at.bofh.it> <O6KzD-g1p2-15@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!bofh.it!news.nic.it!robomod From: sashiko-bot@kernel.org Newsgroups: linux.debian.kernel,linux.kernel Subject: Re: [PATCH v2 03/11] kconfig-audit: Add the configuration checker code Date: Sat, 05 Dec 2026 00:10:01 +0100 Message-ID: <O6KzD-g1p2-13@gated-at.bofh.it> References: <O6o65-fPfD-3@gated-at.bofh.it> <O6KzD-g1p2-15@gated-at.bofh.it> X-Original-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> X-Mailbox-Line: From debian-kernel-request@lists.debian.org Fri Dec 4 23:06:20 2026 Old-Return-Path: <sashiko-bot@kernel.org> X-Amavis-Spam-Status: No, score=-4.401 tagged_above=-10000 required=5.3 tests=[BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham autolearn_force=no X-Policyd-Weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .kernel. - helo: .sea.source.kernel. - helo-domain: .kernel.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -5.5 Reply-To: sashiko-reviews@lists.linux.dev Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Mailing-List: <debian-kernel@lists.debian.org> archive/latest/158750 List-ID: <debian-kernel.lists.debian.org> List-URL: <https://lists.debian.org/debian-kernel/> List-Archive: https://lists.debian.org/msgid-search/sashiko-outbox-250775@kernel.org Approved: robomod@news.nic.it Lines: 167 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-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 X-Original-Date: Fri, 04 Dec 2026 22:50:10 +0000 X-Original-Message-ID: <sashiko-outbox-250775@kernel.org> X-Original-References: <20261203224916.118064-1-darwi@linutronix.de> <20261203224916.118064-4-darwi@linutronix.de>