fix: correct errors.Is argument order in unloadProfile#66
Open
tuxerrante wants to merge 1 commit into
Open
Conversation
The arguments to errors.Is() were swapped: errors.Is(os.ErrNotExist, err) instead of errors.Is(err, os.ErrNotExist). This caused the file-existence guard to never trigger, making unloadProfile always proceed even when the profile file does not exist on disk. This is security-relevant: during graceful shutdown, apparmor_parser --remove was invoked on non-existent files, potentially leaving stale profiles loaded in the kernel. Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a logic bug in unloadProfile() where errors.Is() was called with swapped arguments, preventing the “file does not exist” guard from ever triggering during profile unload.
Changes:
- Correct
errors.Is(os.ErrNotExist, err)toerrors.Is(err, os.ErrNotExist)inunloadProfile(). - Ensure
unloadProfile()properly no-ops when the profile file is missing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+297
to
300
| if _, err := os.Stat(filePath); errors.Is(err, os.ErrNotExist) { | ||
| slog.Default().Info("Profile file does not exist, skipping unload", slog.String("profile", filePath)) | ||
|
|
||
| return nil // Nothing to do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
errors.Is()arguments inunloadProfile():errors.Is(os.ErrNotExist, err)→errors.Is(err, os.ErrNotExist)unloadProfilealways proceed even when the profile file doesn't exist on diskSecurity Impact
Severity: Medium-High — In a privileged DaemonSet managing kernel AppArmor profiles:
apparmor_parser --removewas invoked on non-existent filesTest plan
errors.Is(os.Err*, err)pattern)errors.Iscalls use the correct argument orderTestUnloadProfiletests cover the corrected pathMade with Cursor