Re: [PATCH v2 03/11] kconfig-audit: Add the configuration checker code

From: sashiko-bot

Date: Fri Dec 04 2026 - 17:50:20 EST


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@xxxxxxxxxxxxx>

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@xxxxxxxxxxxxx?part=3