Skip to content

Conversation

@ningmingxiao
Copy link
Contributor

@ningmingxiao ningmingxiao commented Jul 19, 2024

when compare to crun runc will open "/proc/filesystems" even process_label is null
when I try to make runc exec faster
#3181

@ningmingxiao ningmingxiao changed the title skip read /proc/filesystems if process_label is null DRAFT: skip read /proc/filesystems if process_label is null Jul 19, 2024
@lifubang
Copy link
Member

Good news, thanks. Did you have a benchmark to test how faster than before? For example, you can run 1000 times ’runc exec’.

@ningmingxiao
Copy link
Contributor Author

ningmingxiao commented Jul 20, 2024

Good news, thanks. Did you have a benchmark to test how faster than before? For example, you can run 1000 times ’runc exec’.
runc 1.1.12
old

[root@localhost runc]#  time for ((i=0; i<1000;i++)); do runc exec nmx002 true; done
real    0m46.434s
user    0m9.970s
sys     0m19.874s

after this pr

[root@localhost runc]#  time for ((i=0; i<1000;i++)); do runc exec nmx001 true; done

real    0m44.850s
user    0m9.953s
sys     0m19.343s

will improve little.

@ningmingxiao ningmingxiao changed the title DRAFT: skip read /proc/filesystems if process_label is null skip read /proc/filesystems if process_label is null Jul 29, 2024
Comment on lines +41 to -39
defer selinux.SetKeyLabel("") //nolint: errcheck
}
defer selinux.SetKeyLabel("") //nolint: errcheck
Copy link
Member

Choose a reason for hiding this comment

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

Do we know what the intent was for these empty selinux.SetKeyLabel("") ? See my comment on opencontainers/selinux#214 (comment)

Copy link
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 used to clear the label for the next keyring created by the current process once we got an error when we start/exec the container. Because this label can't be inherited by sub-process, so the initial value should be "", so we can set it to an empty string directly to clear it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we use unix.KeyctlString() set keylabel ? @lifubang

Copy link
Member

Choose a reason for hiding this comment

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

can we use unix.KeyctlString() set keylabel ?

I think no.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know what the intent was for these empty selinux.SetKeyLabel("") ? See my comment on opencontainers/selinux#214 (comment)

Some are added by commit cd96170, and some are by aa3fee6, which provides an explanation:

should also call SetProcessLabel("") after the container starts
to go back to the default SELinux behaviour.

Given the fact that Init() never returns unless there's an error (because it ends with exec), those defers are only called in case of an error.

@kolyshkin
Copy link
Contributor

I think the performance overhead is negligible (as the /proc/filesystems is only read once per binary invocation).

As to whether we can skip SetKeyLabel and SetExecLabel calls (and defers) if config.ProcessLabel is empty, I assume this is a valid approach, but perhaps @rhatdan can shed some light.

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.

I re-reviewed this and the approach seems totally correct to me.


func (l *linuxSetnsInit) Init() error {
if !l.config.Config.NoNewKeyring {
if err := selinux.SetKeyLabel(l.config.ProcessLabel); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Another think, do you think this is intend to clear the key label of the process if l.config.ProcessLabel == ""?

Copy link
Contributor

Choose a reason for hiding this comment

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

That was my worry as well. As far as I understand, by default the the context of the creating process is used, and when you write an empty string to /proc/self/attr/keycreate it means the same thing ("use the current context").

So, to my best understanding, writing an empty string and not writing anything is the same thing here.

Maybe @rhatdan will correct me here.

@kolyshkin
Copy link
Contributor

@ningmingxiao please use "rebase" rather than "merge", and remove the merge commit.

@ningmingxiao
Copy link
Contributor Author

@ningmingxiao please use "rebase" rather than "merge", and remove the merge commit.

done

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.

@opencontainers/runc-maintainers PTAL

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

LGTM. If this ends up causing a regression, it would be great to add tests

@rata
Copy link
Member

rata commented Mar 10, 2025

@lifubang do you want to have a last review or shall I merge?

@lifubang
Copy link
Member

@lifubang do you want to have a last review or shall I merge?

What do you think about this one?
#4354 (comment)

@rata
Copy link
Member

rata commented Mar 20, 2025

@lifubang Is @kolyshkin answer not enough. Wanna verify that or what do you propose?

@lifubang
Copy link
Member

@lifubang Is @kolyshkin answer not enough. Wanna verify that or what do you propose?

As @kolyshkin said: "So, to my best understanding, writing an empty string and not writing anything is the same thing here."
I has verified it, for this PR, I think it's correct, writing an empty string means using the default selinux security context.
But there may be a bug for runc exec --process-label="", we have no opportunity to use the default process label to exec into a container now.

@kolyshkin kolyshkin merged commit 8598f6e into opencontainers:main Mar 24, 2025
40 checks passed
@ningmingxiao ningmingxiao deleted the dev3 branch March 24, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants