Skip to content

Commit

Permalink
linux: in an userns bind mount /sys if mounting sysfs fails
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 24, 2018
1 parent ccb8fc1 commit 6785cef
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,22 @@ do_mount (libcrun_container *container,
flags &= ~ALL_PROPAGATIONS;
ret = mount (source, target, fstype, flags, data);
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "mount '%s' to '%s'", source, target);
{
if (strcmp (fstype, "sysfs") == 0)
{
/* If we are running in an user namespace, just bind mount /sys if creating
sysfs failed. */
ret = check_running_in_user_namespace (err);
if (UNLIKELY (ret < 0))
return ret;

ret = mount ("/sys", target, "/sys", MS_BIND | MS_REC | MS_SLAVE, data);
if (ret == 0)
return 0;
}
else
return crun_make_error (err, errno, "mount '%s' to '%s'", source, target);
}
}

if (mountflags & ALL_PROPAGATIONS)
Expand Down

0 comments on commit 6785cef

Please sign in to comment.