-
Notifications
You must be signed in to change notification settings - Fork 273
Added --sys argument for mounting sysfs #699
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,7 @@ typedef enum { | |
| SETUP_OVERLAY_SRC, | ||
| SETUP_MOUNT_PROC, | ||
| SETUP_MOUNT_DEV, | ||
| SETUP_MOUNT_SYS, | ||
| SETUP_MOUNT_TMPFS, | ||
| SETUP_MOUNT_MQUEUE, | ||
| SETUP_MAKE_DIR, | ||
|
|
@@ -175,6 +176,7 @@ enum { | |
| PRIV_SEP_OP_BIND_MOUNT, | ||
| PRIV_SEP_OP_OVERLAY_MOUNT, | ||
| PRIV_SEP_OP_PROC_MOUNT, | ||
| PRIV_SEP_OP_SYS_MOUNT, | ||
| PRIV_SEP_OP_TMPFS_MOUNT, | ||
| PRIV_SEP_OP_DEVPTS_MOUNT, | ||
| PRIV_SEP_OP_MQUEUE_MOUNT, | ||
|
|
@@ -352,6 +354,7 @@ usage (int ecode, FILE *out) | |
| " --file-label LABEL File label for temporary sandbox content\n" | ||
| " --proc DEST Mount new procfs on DEST\n" | ||
| " --dev DEST Mount new dev on DEST\n" | ||
| " --sys DEST Mount new sysfs on DEST\n" | ||
| " --tmpfs DEST Mount new tmpfs on DEST\n" | ||
| " --mqueue DEST Mount new mqueue on DEST\n" | ||
| " --dir DEST Create dir at DEST\n" | ||
|
|
@@ -1122,6 +1125,11 @@ privileged_op (int privileged_op_socket, | |
| die_with_mount_error ("Can't mount proc on %s", arg1); | ||
| break; | ||
|
|
||
| case PRIV_SEP_OP_SYS_MOUNT: | ||
| if (mount ("sysfs", arg1, "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL) != 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you on a SELinux system? Because crablock will bind the host
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. If the host sysfs has a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the code over at crablock you are referencing: I guess I will have to spin up Fedora or something to test that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, I have adapted the code to consider /sys/fs/selinux and successfully tested this under the latest Fedora 42 (with SELinux) and Debian (without SELinux), also as unprivileged user. This gets me: Please, if you can, let me know what you think about it. I test this with: bwrap And I generate the roofs with:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is special about On my Debian system I have I think it might be better (and certainly easier to document) for |
||
| die_with_mount_error ("Can't mount sys on %s", arg1); | ||
| break; | ||
|
|
||
| case PRIV_SEP_OP_TMPFS_MOUNT: | ||
| { | ||
| cleanup_free char *mode = NULL; | ||
|
|
@@ -1191,6 +1199,7 @@ setup_newroot (bool unshare_pid, | |
| { | ||
| SetupOp *op; | ||
| int tmp_overlay_idx = 0; | ||
| struct stat sbuf; | ||
|
|
||
| for (op = ops; op != NULL; op = op->next) | ||
| { | ||
|
|
@@ -1443,6 +1452,36 @@ setup_newroot (bool unshare_pid, | |
|
|
||
| break; | ||
|
|
||
| case SETUP_MOUNT_SYS: | ||
| if (ensure_dir (dest, 0755) != 0) | ||
| die_with_error ("Can't mkdir %s", op->dest); | ||
|
|
||
| if (unshare_pid || opt_pidns_fd != -1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sysfs is also about unshare_net. Also check this with your mount is too revealing error. There is a difference between
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like something that should be addressed, particularly if (Of course, if you change |
||
| { | ||
| /* Our own sysfs */ | ||
| privileged_op (privileged_op_socket, | ||
| PRIV_SEP_OP_SYS_MOUNT, 0, 0, 0, | ||
| dest, NULL); | ||
|
|
||
| /* In case the host utilizes SELinux, /sys/fs/selinux should be shared with the sandbox */ | ||
| char *selinux_src_dir = "oldroot/sys/fs/selinux"; | ||
| cleanup_free char *selinux_dest_dir = strconcat (dest, "/fs/selinux"); | ||
| if (stat (selinux_src_dir, &sbuf) == 0 && stat (selinux_dest_dir, &sbuf) == 0) | ||
| { | ||
| privileged_op (privileged_op_socket, | ||
| PRIV_SEP_OP_BIND_MOUNT, 0, 0, 0, | ||
| selinux_src_dir, selinux_dest_dir); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| /* Use system sysfs, as we share pid namespace anyway */ | ||
| privileged_op (privileged_op_socket, | ||
| PRIV_SEP_OP_BIND_MOUNT, 0, 0, 0, | ||
| "oldroot/sys", dest); | ||
| } | ||
|
Comment on lines
+1476
to
+1482
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems quite "do what I mean". I think it would be easier to document this option clearly if it always created a new sysfs instance, and never bind-mounted the existing (Also easier to be sure that it's correct - if the option autodetects whether it needs a new instance or can keep the current instance, then that opens the possibility that the autodetection has bugs.) |
||
| break; | ||
|
|
||
| case SETUP_MOUNT_TMPFS: | ||
| assert (dest != NULL); | ||
| assert (op->perms >= 0); | ||
|
|
@@ -1642,6 +1681,7 @@ resolve_symlinks_in_ops (void) | |
| case SETUP_TMP_OVERLAY_MOUNT: | ||
| case SETUP_MOUNT_PROC: | ||
| case SETUP_MOUNT_DEV: | ||
| case SETUP_MOUNT_SYS: | ||
| case SETUP_MOUNT_TMPFS: | ||
| case SETUP_MOUNT_MQUEUE: | ||
| case SETUP_MAKE_DIR: | ||
|
|
@@ -2100,6 +2140,17 @@ parse_args_recurse (int *argcp, | |
| op = setup_op_new (SETUP_MOUNT_PROC); | ||
| op->dest = argv[1]; | ||
|
|
||
| argv += 1; | ||
| argc -= 1; | ||
| } | ||
| else if (strcmp (arg, "--sys") == 0) | ||
| { | ||
| if (argc < 2) | ||
| die ("--sys takes an argument"); | ||
|
|
||
| op = setup_op_new (SETUP_MOUNT_SYS); | ||
| op->dest = argv[1]; | ||
|
|
||
| argv += 1; | ||
| argc -= 1; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -405,6 +405,10 @@ | |||||||||||||||||||
| <term><option>--dev <arg choice="plain">DEST</arg></option></term> | ||||||||||||||||||||
| <listitem><para>Mount new devtmpfs on <arg choice="plain">DEST</arg></para></listitem> | ||||||||||||||||||||
| </varlistentry> | ||||||||||||||||||||
| <varlistentry> | ||||||||||||||||||||
| <term><option>--sys <arg choice="plain">DEST</arg></option></term> | ||||||||||||||||||||
| <listitem><para>Mount sysfs on <arg choice="plain">DEST</arg></para></listitem> | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely needs to expand on what this option does, and why it isn't just For example perhaps something like
Suggested change
If Conversely, if
|
||||||||||||||||||||
| </varlistentry> | ||||||||||||||||||||
| <varlistentry> | ||||||||||||||||||||
| <term><option>--tmpfs <arg choice="plain">DEST</arg></option></term> | ||||||||||||||||||||
| <listitem> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ _bwrap() { | |
| --size | ||
| --symlink | ||
| --sync-fd | ||
| --sys | ||
| --tmp-overlay | ||
| --uid | ||
| --unsetenv | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,7 @@ _bwrap_args=( | |||||
| '--size[Set size in bytes for next action argument]: :->after_size' | ||||||
| '--symlink[Create symlink at DEST with target SRC]:symlink target:_files:symlink to create:_files:' | ||||||
| '--sync-fd[Keep this fd open while sandbox is running]: :_guard "[0-9]#" "file descriptor to keep open"' | ||||||
| '--sys[Mount new sysfs on DEST]:mount point for sysfs:_files -/' | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
Suggested change
to emphasize that, like |
||||||
| '--uid[Custom uid in the sandbox (requires --unshare-user or --userns)]: :_guard "[0-9]#" "numeric group ID"' | ||||||
| '(--clearenv)--unsetenv[Unset an environment variable]:variable to unset:_parameters -g "*export*"' | ||||||
| '--unshare-all[Unshare every namespace we support by default]' | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.