Skip to content

Commit 3c07435

Browse files
dangome3mtardy
authored andcommitted
fix: Change kernel config detection failure to info level
Tetragon attempts to read the kernel config by trying a couple of places where it is found. This should be Info instead of Error. detectAuditLoginuid() function was removed and its logic was implemented into detectAuditLoginuidOnce(). Testing was done by mocking getKernelConfig() function, returning error and validating that the new log is of Info level: getKernelConfigMock = sync.OnceValue(func() error { return errors.New("Mocked getKernelConfig function for testing") }) Testing Results: when the function works no log is shown and loginuid is enabled when mocking the function a log with undetected loginuid file is shown Signed-off-by: Daniel Gomez <[email protected]>
1 parent 8700328 commit 3c07435

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pkg/bpf/detect_linux.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,23 @@ func HasUprobeRefCtrOffset() bool {
524524
return uprobeRefCtrOffset.detected
525525
}
526526

527-
func detectAuditLoginuid() bool {
528-
if kernels.MinKernelVersion("5.1") && kernels.DetectConfig(kernels.CONFIG_AUDIT) {
529-
return true
530-
} else if kernels.DetectConfig(kernels.CONFIG_AUDITSYSCALL) {
531-
return true
532-
}
533-
534-
_, err := os.Stat("/proc/self/loginuid")
535-
return err == nil
536-
}
537-
538527
func detectAuditLoginuidOnce() {
539528
auditLoginuid.init.Do(func() {
540-
auditLoginuid.detected = detectAuditLoginuid()
529+
cfg := kernels.CONFIG_AUDITSYSCALL
530+
if kernels.MinKernelVersion("5.1") {
531+
cfg = kernels.CONFIG_AUDIT
532+
}
533+
if ok, errConfig := kernels.DetectConfig(cfg); ok {
534+
auditLoginuid.detected = true
535+
} else if _, errStat := os.Stat("/proc/self/loginuid"); errStat == nil {
536+
auditLoginuid.detected = true
537+
} else {
538+
if errConfig != nil {
539+
logger.GetLogger().Info("failed to detect config and to stat loginuid", "config_error", errConfig, "config", string(cfg), "stat_error", errStat)
540+
} else {
541+
logger.GetLogger().Info("failed to stat loginuid", logfields.Error, errStat)
542+
}
543+
}
541544
})
542545
}
543546

pkg/kernels/config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,21 @@ func initKernelConfig() error {
131131

132132
// DetectConfig checks if a kernel config option is enabled
133133
// It first tries /proc/config.gz, then looks for config file in /boot for the current kernel
134-
func DetectConfig(conf Config) bool {
134+
func DetectConfig(conf Config) (bool, error) {
135135
if err := getKernelConfig(); err != nil {
136-
logger.GetLogger().Error("Detecting kernel config failed", logfields.Error, err)
137-
return false
136+
return false, fmt.Errorf("getting kernel config failed: %w", err)
138137
}
139138

140139
if val, ok := kernelConfigMap[conf]; ok {
141140
// Only check for CONFIG_XXX=y or CONFIG_XXX=m. When the value is a string or number,
142141
// it's mostly treated as a kernel parameter rather than a feature switch,
143142
// so we temporarily filter these out.
144143
if val == "y" || val == "m" {
145-
return true
144+
return true, nil
146145
}
147146
}
148147

149-
return false
148+
return false, nil
150149
}
151150

152151
func LogConfigs() string {

0 commit comments

Comments
 (0)