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

Disable private mounts in chroot'ed operation in the unshare plugin #3228

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions docs/man/rpm-plugin-unshare.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ This plugin implements the following configurables:
execution. Typical examples would be `/tmp` to protect against
insecure temporary file usage inside scriptlets, and `/home` to
prevent scriptlets from accessing user home directories.
When path unsharing is enabled, any mounts made from scriptlets
are also private to the scriptlet (and vice versa, mount changes
on the host are not visible to the scriptlet).

Private mounts in chroot-operations is unimplemented.

`%__transaction_unshare_nonet`

Expand Down
21 changes: 16 additions & 5 deletions plugins/unshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ static rpmRC unshare_init(rpmPlugin plugin, rpmts ts)
{
char *paths = rpmExpand("%{?__transaction_unshare_paths}", NULL);
private_mounts = argvSplitString(paths, ":", ARGV_SKIPEMPTY);
if (private_mounts)
unshare_flags |= CLONE_NEWNS;
if (private_mounts) {
/*
* Changing mount propagation from inside a chroot fails if the root
* is not also a mount point, disable for now.
*/
if (strcmp(rpmtsRootDir(ts), "/")) {
rpmlog(RPMLOG_WARNING,
"private mounts in chroot not implemented\n");
} else {
unshare_flags |= CLONE_NEWNS;
}
}
free(paths);

if (rpmExpandNumeric("%{?__transaction_unshare_nonet}"))
Expand All @@ -47,9 +57,10 @@ static rpmRC unshare_scriptlet_fork_post(rpmPlugin plugin,
goto exit;
}

if (private_mounts) {
if (mount("/", "/", NULL, MS_REC | MS_PRIVATE, NULL) == -1) {
rpmlog(RPMLOG_ERR, _("failed to mount private %s: %s\n"),
if (unshare_flags & CLONE_NEWNS) {
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == -1) {
rpmlog(RPMLOG_ERR,
_("failed to change mount propagation %s: %s\n"),
"/", strerror(errno));
goto exit;
}
Expand Down
Loading