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

Fix EXEC permission of the volume mount when calling mmap with PROT_EXEC #11358

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Yhinner
Copy link

@Yhinner Yhinner commented Jan 13, 2025

Background

This is Xuzhou (Joe) from Snowflake Inc. We are currently working on utilizing gVisor internally as our secured sandboxing mechanism. We have met in-person with gVisor team last October sharing our use case and experiences with the gVisor team. As part of the meeting, we (Snowflake team) committed to contribute our internal fixes/improvements back to the upstream.

As part of compatibility testing with our previous mechanism, we found some behavior discrepancies between gVisor-emulated kernel and native linux kernel when making mmap system calls. Thus wanted to raise a pull request and see if this makes sense.

Issue we observed

On native linux kernel, when calling mmap syscall with PROT_EXEC on a file, linux kernel checks if the volume/file system backing the file is executable (ie. Has NOEXEC flag or not). If the volume has NOEXEC flag set, the syscall will fail with EPERM.

However, this behavior is not observed when running under gVisor. Instead, gvisor allows this system call to be made without any issue.

Thus this pull request aims to bring the same parity to gvisor implemented mmap syscall.

Copy link

google-cla bot commented Jan 13, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Yhinner
Copy link
Author

Yhinner commented Jan 13, 2025

@nixprime Hey Jamie! Could you please help us review this pull request when you get time? Thank you!

test/runner/main.go Outdated Show resolved Hide resolved
@Yhinner Yhinner requested a review from ayushr2 January 14, 2025 19:50
test/syscalls/linux/mmap.cc Outdated Show resolved Hide resolved
test/syscalls/linux/mmap.cc Outdated Show resolved Hide resolved
test/runner/main.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@ayushr2 ayushr2 left a comment

Choose a reason for hiding this comment

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

LGTM, just nits.

Comment on lines 313 to 315
ASSERT_THAT(
reinterpret_cast<uintptr_t>(mmapRet),
SyscallSucceeds());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the right check here would be EXPECT_NE(mmapRet, MAP_FAILED);

Also, rename mmapRet to addr

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I've updated the code now

@@ -98,6 +98,19 @@ func Mmap(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *
opts.MaxPerms.Write = false
}

// mmap requires the volume mount which includes the requested file to have exec capability if given request
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please wrap these comments to 80 chars as well.

test/syscalls/linux/mmap.cc Outdated Show resolved Hide resolved
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.

4 participants