Skip to content

Commit

Permalink
module: add zfs_snapshot_no_setuid parameter
Browse files Browse the repository at this point in the history
to control wheter automatically mounted snapshots have the setuid mount
option set or not.

this could be considered a partial fix for one of the scenarios
mentioned in desired.

Signed-off-by: Fabian Grünbichler <[email protected]>
  • Loading branch information
Fabian-Gruenbichler committed Mar 6, 2024
1 parent 548e418 commit b5ba501
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 9 additions & 0 deletions man/man4/zfs.4
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,15 @@ which have the
.Em no_root_squash
option set.
.
.It Sy zfs_snapshot_no_setuid Ns = Ns Sy 0 Ns | Ns 1 Pq int
Whether to disable
.Em setuid/setgid
support for snapshot mounts triggered by access to the
.Sy .zfs/snapshot
directory by setting the
.Em nosuid
mount option.
.
.It Sy zfs_flags Ns = Ns Sy 0 Pq int
Set additional debugging flags.
The following flags may be bitwise-ored together:
Expand Down
20 changes: 15 additions & 5 deletions module/os/linux/zfs/zfs_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ static krwlock_t zfs_snapshot_lock;
*/
int zfs_expire_snapshot = ZFSCTL_EXPIRE_SNAPSHOT;
static int zfs_admin_snapshot = 0;
static int zfs_snapshot_no_setuid = 0;

typedef struct {
char *se_name; /* full snapshot name */
Expand Down Expand Up @@ -1102,9 +1103,9 @@ zfsctl_snapshot_mount(struct path *path, int flags)
zfsvfs_t *zfsvfs;
zfsvfs_t *snap_zfsvfs;
zfs_snapentry_t *se;
char *full_name, *full_path;
char *argv[] = { "/usr/bin/env", "mount", "-t", "zfs", "-n", NULL, NULL,
NULL };
char *full_name, *full_path, *options;
char *argv[] = { "/usr/bin/env", "mount", "-t", "zfs", "-n", "-o", NULL,
NULL, NULL, NULL };
char *envp[] = { NULL };
int error;
struct path spath;
Expand All @@ -1118,6 +1119,7 @@ zfsctl_snapshot_mount(struct path *path, int flags)

full_name = kmem_zalloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);
full_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
options = kmem_zalloc(7, KM_SLEEP);

error = zfsctl_snapshot_name(zfsvfs, dname(dentry),
ZFS_MAX_DATASET_NAME_LEN, full_name);
Expand All @@ -1133,6 +1135,9 @@ zfsctl_snapshot_mount(struct path *path, int flags)
zfsvfs->z_vfs->vfs_mntpoint ? zfsvfs->z_vfs->vfs_mntpoint : "",
dname(dentry));

snprintf(options, 7, "%s",
zfs_snapshot_no_setuid ? "nosuid" : "suid");

/*
* Multiple concurrent automounts of a snapshot are never allowed.
* The snapshot may be manually mounted as many times as desired.
Expand All @@ -1155,8 +1160,9 @@ zfsctl_snapshot_mount(struct path *path, int flags)
* value from call_usermodehelper() will be (exitcode << 8 + signal).
*/
dprintf("mount; name=%s path=%s\n", full_name, full_path);
argv[5] = full_name;
argv[6] = full_path;
argv[6] = options;
argv[7] = full_name;
argv[8] = full_path;
error = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
if (error) {
if (!(error & MOUNT_BUSY << 8)) {
Expand Down Expand Up @@ -1317,3 +1323,7 @@ MODULE_PARM_DESC(zfs_admin_snapshot, "Enable mkdir/rmdir/mv in .zfs/snapshot");

module_param(zfs_expire_snapshot, int, 0644);
MODULE_PARM_DESC(zfs_expire_snapshot, "Seconds to expire .zfs/snapshot");

module_param(zfs_snapshot_no_setuid, int, 0644);
MODULE_PARM_DESC(zfs_snapshot_no_setuid,
"Disable setuid/setgid for automounts in .zfs/snapshot");

0 comments on commit b5ba501

Please sign in to comment.