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

util/misc: support kernels where MFD_NOEXEC_SEAL does not enable sealing #366

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/util/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* Throw in `MFD_CLOEXEC` or `F_SEAL_SEAL` as required.
*
* * If `MFD_NOEXEC_SEAL` is used without `MFD_ALLOW_SEALING`, sealing will
* be disabled (even though the kernel implicitly enables it).
* be disabled (even though some kernel versions implicitly enable it).
*
* * An initial set of seals is applied to the memfd, if specified in
* @seals. Note that this is not allowed if sealing was not enabled.
Expand Down Expand Up @@ -111,7 +111,7 @@ int misc_memfd(const char *name, unsigned int uflags, unsigned int useals) {
}

/*
* If we ended up passing `MFG_NOEXEC_SEAL` to the kernel, the kernel
* If we ended up passing `MFG_NOEXEC_SEAL` to the kernel, some kernel versions
* will implicitly enable sealing. This is very unfortunate, so we
* revert this if the caller did not explicitly allow it. To disable
* sealing, simply set `F_SEAL_SEAL`, which is also what the kernel
Expand All @@ -126,9 +126,15 @@ int misc_memfd(const char *name, unsigned int uflags, unsigned int useals) {
* into the kernel again.
*/
if (seals) {
r = misc_memfd_add_seals(fd, seals);
if (r)
return error_fold(r);
r = fcntl(fd, MISC_F_GET_SEALS);
if (r < 0)
return error_origin(-errno);

if (seals & ~r) {
r = misc_memfd_add_seals(fd, seals);
if (r)
return error_fold(r);
}
}

r = fd;
Expand Down
Loading