Skip to content

refactor: ignore other return values when an error occurs - #5369

Closed
lifubang wants to merge 1 commit into
opencontainers:mainfrom
lifubang:refactor-5347
Closed

lifubang wants to merge 1 commit into
opencontainers:mainfrom
lifubang:refactor-5347

Conversation

@lifubang

Copy link
Copy Markdown
Member

we shouldn't trust waitKill when we got the error EINVAL.

Ref:
#5367 (comment)
#5367 (comment)

we shouldn't trust `waitKill` when we got the error `EINVAL`.

Suggested-by: Sebastiaan van Stijn <github@gone.nl>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: lifubang <lifubang@acmcoder.com>
@lifubang lifubang added the kind/refactor refactoring label Jul 11, 2026
Comment on lines +676 to 682
if waitKill, err := filter.GetWaitKill(); err != nil {
if !errors.Is(err, unix.EINVAL) {
return 0, false, fmt.Errorf("unable to fetch SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV bit: %w", err)
}
} else if waitKill {
flags |= uint(C.C_FILTER_FLAG_WAIT_KILLABLE_RECV)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really want to switch it over, I think better describes what we are doing, but I don't really mind too much either way.

Suggested change
if waitKill, err := filter.GetWaitKill(); err != nil {
if !errors.Is(err, unix.EINVAL) {
return 0, false, fmt.Errorf("unable to fetch SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV bit: %w", err)
}
} else if waitKill {
flags |= uint(C.C_FILTER_FLAG_WAIT_KILLABLE_RECV)
}
waitKill, err := filter.GetWaitKill()
if errors.Is(err, unix.EINVAL) {
waitKill, err = false, nil
}
if err != nil {
return 0, false, fmt.Errorf("unable to fetch SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV bit: %w", err)
}
if waitKill {
flags |= uint(C.C_FILTER_FLAG_WAIT_KILLABLE_RECV)
}

@kolyshkin

Copy link
Copy Markdown
Contributor

First of all I want to find out why we're getting EINVAL at all. See #5347 (comment)

@kolyshkin

Copy link
Copy Markdown
Contributor

First of all I want to find out why we're getting EINVAL at all. See #5347 (comment)

Proposed libseccomp-golang fix: seccomp/libseccomp-golang#127

With that, we won't have to add a special case for EINVAL

@rata rata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine this or what @cyphar proposes. But the problem of returning EINVAL doesn't affect theoretically the other options too?

What about making this a helper function and calling it for each option we need. It could make filterFlags() simpler to read, and whenever we add a new filter flag, we will handle it correctly by using the helper.

What do you think?

@rata

rata commented Jul 30, 2026

Copy link
Copy Markdown
Member

Proposed libseccomp-golang fix: seccomp/libseccomp-golang#127

With that, we won't have to add a special case for EINVAL

Oh, I missed that. If the PR to handle that is merged, then it might be fine to just do this here. Sorry :-D

@kolyshkin

Copy link
Copy Markdown
Contributor

My bad; still working on seccomp/libseccomp-golang#129; once it's in I will release a new libseccomp-golang version.

@kolyshkin

Copy link
Copy Markdown
Contributor

Better late than never, https://github.com/seccomp/libseccomp-golang/releases/tag/v0.12.0 is out so we can just want for dependabot PR to bump it.

Once it's there, we no longer need this PR not #5347 / #5354 I belive.

@kolyshkin kolyshkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, GetWaitKill can return

  • libseccomp-golang's errBadFilter ("filter is invalid or uninitialized")
  • anything that seccomp_attr_get() can return (EACCES, EEXIST, EINVAL, EOPNOTSUPP)
  • libseccomp-golang's VersionError

I think this particular code should just ignore ALL errors, and only set the attribute if true, nil is returned.

OTOH, with libseccomp-golang v0.12, if libseccomp.GetAPI returns a level 7 or greater, it means that filter.GetWaitKill works and should not return an error. Meaning, the current code (after commit 177f385) is just fine.

@kolyshkin

Copy link
Copy Markdown
Contributor

closing this as the workaround was removed and any error is a real error.

@kolyshkin kolyshkin closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants