Skip to content

Commit 9e6eaf6

Browse files
Added --sys argument for mounting sysfs
1 parent d6180f2 commit 9e6eaf6

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

bubblewrap.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ typedef enum {
130130
SETUP_OVERLAY_SRC,
131131
SETUP_MOUNT_PROC,
132132
SETUP_MOUNT_DEV,
133+
SETUP_MOUNT_SYS,
133134
SETUP_MOUNT_TMPFS,
134135
SETUP_MOUNT_MQUEUE,
135136
SETUP_MAKE_DIR,
@@ -175,6 +176,7 @@ enum {
175176
PRIV_SEP_OP_BIND_MOUNT,
176177
PRIV_SEP_OP_OVERLAY_MOUNT,
177178
PRIV_SEP_OP_PROC_MOUNT,
179+
PRIV_SEP_OP_SYS_MOUNT,
178180
PRIV_SEP_OP_TMPFS_MOUNT,
179181
PRIV_SEP_OP_DEVPTS_MOUNT,
180182
PRIV_SEP_OP_MQUEUE_MOUNT,
@@ -352,6 +354,7 @@ usage (int ecode, FILE *out)
352354
" --file-label LABEL File label for temporary sandbox content\n"
353355
" --proc DEST Mount new procfs on DEST\n"
354356
" --dev DEST Mount new dev on DEST\n"
357+
" --sys DEST Mount new sysfs on DEST\n"
355358
" --tmpfs DEST Mount new tmpfs on DEST\n"
356359
" --mqueue DEST Mount new mqueue on DEST\n"
357360
" --dir DEST Create dir at DEST\n"
@@ -1122,6 +1125,11 @@ privileged_op (int privileged_op_socket,
11221125
die_with_mount_error ("Can't mount proc on %s", arg1);
11231126
break;
11241127

1128+
case PRIV_SEP_OP_SYS_MOUNT:
1129+
if (mount ("sysfs", arg1, "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL) != 0)
1130+
die_with_mount_error ("Can't mount sys on %s", arg1);
1131+
break;
1132+
11251133
case PRIV_SEP_OP_TMPFS_MOUNT:
11261134
{
11271135
cleanup_free char *mode = NULL;
@@ -1443,6 +1451,26 @@ setup_newroot (bool unshare_pid,
14431451

14441452
break;
14451453

1454+
case SETUP_MOUNT_SYS:
1455+
if (ensure_dir (dest, 0755) != 0)
1456+
die_with_error ("Can't mkdir %s", op->dest);
1457+
1458+
if (unshare_pid || opt_pidns_fd != -1)
1459+
{
1460+
/* Our own sysfs */
1461+
privileged_op (privileged_op_socket,
1462+
PRIV_SEP_OP_SYS_MOUNT, 0, 0, 0,
1463+
dest, NULL);
1464+
}
1465+
else
1466+
{
1467+
/* Use system sysfs, as we share pid namespace anyway */
1468+
privileged_op (privileged_op_socket,
1469+
PRIV_SEP_OP_BIND_MOUNT, 0, 0, 0,
1470+
"oldroot/sys", dest);
1471+
}
1472+
break;
1473+
14461474
case SETUP_MOUNT_TMPFS:
14471475
assert (dest != NULL);
14481476
assert (op->perms >= 0);
@@ -1642,6 +1670,7 @@ resolve_symlinks_in_ops (void)
16421670
case SETUP_TMP_OVERLAY_MOUNT:
16431671
case SETUP_MOUNT_PROC:
16441672
case SETUP_MOUNT_DEV:
1673+
case SETUP_MOUNT_SYS:
16451674
case SETUP_MOUNT_TMPFS:
16461675
case SETUP_MOUNT_MQUEUE:
16471676
case SETUP_MAKE_DIR:
@@ -2100,6 +2129,17 @@ parse_args_recurse (int *argcp,
21002129
op = setup_op_new (SETUP_MOUNT_PROC);
21012130
op->dest = argv[1];
21022131

2132+
argv += 1;
2133+
argc -= 1;
2134+
}
2135+
else if (strcmp (arg, "--sys") == 0)
2136+
{
2137+
if (argc < 2)
2138+
die ("--sys takes an argument");
2139+
2140+
op = setup_op_new (SETUP_MOUNT_SYS);
2141+
op->dest = argv[1];
2142+
21032143
argv += 1;
21042144
argc -= 1;
21052145
}

bwrap.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@
405405
<term><option>--dev <arg choice="plain">DEST</arg></option></term>
406406
<listitem><para>Mount new devtmpfs on <arg choice="plain">DEST</arg></para></listitem>
407407
</varlistentry>
408+
<varlistentry>
409+
<term><option>--sys <arg choice="plain">DEST</arg></option></term>
410+
<listitem><para>Mount sysfs on <arg choice="plain">DEST</arg></para></listitem>
411+
</varlistentry>
408412
<varlistentry>
409413
<term><option>--tmpfs <arg choice="plain">DEST</arg></option></term>
410414
<listitem>

completions/bash/bwrap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ _bwrap() {
6363
--size
6464
--symlink
6565
--sync-fd
66+
--sys
6667
--tmp-overlay
6768
--uid
6869
--unsetenv

completions/zsh/_bwrap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ _bwrap_args=(
6565
'--size[Set size in bytes for next action argument]: :->after_size'
6666
'--symlink[Create symlink at DEST with target SRC]:symlink target:_files:symlink to create:_files:'
6767
'--sync-fd[Keep this fd open while sandbox is running]: :_guard "[0-9]#" "file descriptor to keep open"'
68+
'--sys[Mount new sysfs on DEST]:mount point for sysfs:_files -/'
6869
'--uid[Custom uid in the sandbox (requires --unshare-user or --userns)]: :_guard "[0-9]#" "numeric group ID"'
6970
'(--clearenv)--unsetenv[Unset an environment variable]:variable to unset:_parameters -g "*export*"'
7071
'--unshare-all[Unshare every namespace we support by default]'

0 commit comments

Comments
 (0)