Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: define ActKillThread equal to ActKill #85

Closed
wants to merge 1 commit into from

Conversation

tonistiigi
Copy link
Contributor

These constants are equal in libseccomp seccomp/libseccomp@b2f15f3#diff-26b243770fb00079467cda2a0d84f4d3d4158e565eac4570f12b08cbfe172be2R255 (with ActKillThread being a more precise name for the previous behavior) but Go definitions were defined separately in 24f2937.

This resulted in dead code that never executed due to identical case statements in switch. Go can usually detect these error cases and refuses to build but for some reason this detection doesn’t work with cgo+gcc.

Clang detects the equal constants correctly and therefore libseccomp-golang builds with clang broke after ActKillThread was added making it impossible for us to build the latest runc. https://gist.github.com/tonistiigi/ab6ef71781b7e3c5cabcb71a286a9243 is a simple example showing this condition where builds with clang fail.

In order to fix the clang build only removal of the switch case is needed. But I assumed that the setter/getter
logic
is supposed to work for ActKillThread as well and the only way to ensure that is to set them equal like they
are in C.

@kolyshkin @pjbgf

Signed-off-by: Tonis Tiigi tonistiigi@gmail.com

These constants are equal in libseccomp but Go definitions
were defined separately. This resulted in dead code that
never executed due to identical case statements in switch.
Go can usually detect these error cases and refuses to build
but for some reason this detection doesn’t work with cgo+gcc.
Clang detects the equal constants correctly and therefore
libseccomp-golang builds with clang broke after ActKillThread
was added.

In order to fix the clang build only removal of the
switch case is needed. But I assumed that the setter/getter
logic is supposed to work for ActKillThread as well
and only way to ensure that is to set them equal like they
are in C.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@thaJeztah
Copy link
Contributor

@kolyshkin ptal 🤗

Copy link
Contributor

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Nice catch @tonistiigi. LGTM

@pcmoore pcmoore changed the title Define ActKillThread equal to ActKill BUG: define ActKillThread equal to ActKill Feb 2, 2022
@pcmoore pcmoore added this to the v0.9.2 milestone Feb 2, 2022
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM.

I think it also makes sense to mark ActKill as deprecated, asking to use ActKillThread instead (and changing the code accordingly, i.e. s/ActKill/ActKillThread/). Surely this can be done separately.

@thaJeztah
Copy link
Contributor

@pcmoore this LGTY?

Copy link
Member

@drakenclimber drakenclimber left a comment

Choose a reason for hiding this comment

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

Acked-by: Tom Hromatka <tom.hromatka@oracle.com>

// ActKillProcess kills the process that violated the rule.
// All threads in the thread group are also terminated.
// This action is only usable when libseccomp API level 3 or higher is
// supported.
ActKillProcess
// ActKillThread kills the thread that violated the rule. It is the same as ActKill.
// All other threads from the same thread group will continue to execute.
ActKillThread = ActKill
Copy link
Member

Choose a reason for hiding this comment

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

This may be very nitpicky, but if we are trying to be similar to the core libseccomp library it may be better to do:

ActKill = ActKillThread

... or would that still cause problems with clang?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is outside the scope of the bugfix. If libseccomp-golang wants to deprecate ActKill as well in favor or ActKillThread that SGTM but I think it is a separate decision. It would also mean reworking the current tests and some helper methods that currently use ActKill.

Copy link
Member

Choose a reason for hiding this comment

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

I tend to think it is in scope, if we are changing how we define ActKillThread let's go ahead and do things properly so we are better in sync with the core library. A quick grep of the libseccomp-golang sources shows approximately two dozen places in the code that might be affected; that's not bad as far as I'm concerned.

I'm fine if you want to do this work in a separate patch, but please keep it in this PR.

@thaJeztah
Copy link
Contributor

To address #85 (comment), I opened #90 which swaps ActKillThread and ActKill, and marks ActKill as deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: unable to compile on Archlinux
6 participants