From f60639990bebd5cf6e642b8e0d08e1d66fc4201a Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 20 May 2025 19:05:39 +0200 Subject: pkg/subsystem: fix dangling entries in the rules list There was a mistake in the Linux subsystem generation rules that led to the exclusion of exfat-related syz_mount_image calls from the resulting subsystem descriptions. Verify the rules before applying them. Fix other problems found by the check. --- pkg/subsystem/linux/subsystems.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'pkg/subsystem/linux/subsystems.go') diff --git a/pkg/subsystem/linux/subsystems.go b/pkg/subsystem/linux/subsystems.go index 9da38d321..ae2c61556 100644 --- a/pkg/subsystem/linux/subsystems.go +++ b/pkg/subsystem/linux/subsystems.go @@ -141,6 +141,15 @@ func (ctx *linuxCtx) applyExtraRules(list []*subsystem.Subsystem) error { if ctx.extraRules == nil { return nil } + if err := noDanglingRules(list, ctx.extraRules.subsystemCalls); err != nil { + return fmt.Errorf("subsystemCalls rules check failed: %w", err) + } + if err := noDanglingRules(list, ctx.extraRules.noReminders); err != nil { + return fmt.Errorf("noReminders rules check failed: %w", err) + } + if err := noDanglingRules(list, ctx.extraRules.noIndirectCc); err != nil { + return fmt.Errorf("noIndirectCc rules check failed: %w", err) + } perName := map[string]*subsystem.Subsystem{} for _, entry := range list { entry.Syscalls = ctx.extraRules.subsystemCalls[entry.Name] @@ -171,6 +180,28 @@ func (ctx *linuxCtx) applyExtraRules(list []*subsystem.Subsystem) error { return nil } +// Check that there are no rules that don't refer to any subsystem from the list. +func noDanglingRules[T any](list []*subsystem.Subsystem, rules map[string]T) error { + usedRule := map[string]struct{}{} + for _, entry := range list { + if _, ok := rules[entry.Name]; !ok { + continue + } + usedRule[entry.Name] = struct{}{} + } + if len(usedRule) == len(rules) { + return nil + } + var dangling []string + for key := range rules { + if _, ok := usedRule[key]; ok { + continue + } + dangling = append(dangling, key) + } + return fmt.Errorf("unused keys: %q", dangling) +} + func mergeRawRecords(records []*maintainersRecord, email string) *subsystem.Subsystem { var lists []string subsystem := &subsystem.Subsystem{} -- cgit mrf-deployment