Skip to content

Commit 30edc15

Browse files
committed
require rollback permission when force receive
Force receive (zfs receive -F) can rollback or destroy snapshots and file systems that do not exist on the sending side (see zfs-receive man page). This means an user having the receive permission can effectively delete data on receiving side, even if such user does not have explicit rollback or destroy permissions. This patch add the rollback permission requirement for force receive. To avoid changing current default behavior, a new tunable zfs_recv_force_needs_perm is introduced. When set to 0 (default) the new permission check is disabled. When set to 1 rollback permission requirement is enabled. Fixes #16943 Signed-off-by: Gionatan Danti <[email protected]>
1 parent 3420571 commit 30edc15

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

man/man4/zfs.4

+3
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,9 @@ If there is an error during healing, the healing receive is not
21882188
terminated instead it moves on to the next record.
21892189
.El
21902190
.
2191+
.It Sy zfs_recv_perm Ns = Ns Sy 0 Pq int
2192+
When not zero, force receive (zfs recv -F) requires rollback permission.
2193+
.
21912194
.It Sy zfs_override_estimate_recordsize Ns = Ns Sy 0 Ns | Ns 1 Pq uint
21922195
Setting this variable overrides the default logic for estimating block
21932196
sizes when doing a

man/man8/zfs-allow.8

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ load-key subcommand Allows loading and unloading of encryption key (see \fBzfs l
207207
change-key subcommand Allows changing an encryption key via \fBzfs change-key\fR.
208208
mount subcommand Allows mounting/umounting ZFS datasets
209209
promote subcommand Must also have the \fBmount\fR and \fBpromote\fR ability in the origin file system
210-
receive subcommand Must also have the \fBmount\fR and \fBcreate\fR ability
210+
receive subcommand Must also have the \fBmount\fR and \fBcreate\fR ability; must also have the \fBrollback\fR ability if \fBzfs receive -F\fR (force receive) is used and \fBzfs_recv_perm\fR is set to 1.
211211
release subcommand Allows releasing a user hold which might destroy the snapshot
212212
rename subcommand Must also have the \fBmount\fR and \fBcreate\fR ability in the new parent
213213
rollback subcommand Must also have the \fBmount\fR ability

module/zfs/zfs_ioctl.c

+14
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ uint64_t zfs_max_nvlist_src_size = 0;
238238
*/
239239
static uint64_t zfs_history_output_max = 1024 * 1024;
240240

241+
/*
242+
* zfs_recv_force_needs_perm: if true, force receive (-F) requires rollback permission
243+
*/
244+
static int zfs_recv_force_needs_perm = 0;
245+
241246
uint_t zfs_allow_log_key;
242247

243248
/* DATA_TYPE_ANY is used when zkey_type can vary. */
@@ -908,6 +913,12 @@ zfs_secpolicy_recv(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
908913
ZFS_DELEG_PERM_MOUNT, cr)) != 0)
909914
return (error);
910915

916+
/* Forced receive can rollback or destroy snapshots */
917+
if (zfs_recv_force_needs_perm && zc->zc_guid &&
918+
(error = zfs_secpolicy_write_perms(zc->zc_name,
919+
ZFS_DELEG_PERM_ROLLBACK, cr)) != 0)
920+
return (error);
921+
911922
return (zfs_secpolicy_write_perms(zc->zc_name,
912923
ZFS_DELEG_PERM_CREATE, cr));
913924
}
@@ -8177,3 +8188,6 @@ ZFS_MODULE_PARAM(zfs, zfs_, max_nvlist_src_size, U64, ZMOD_RW,
81778188

81788189
ZFS_MODULE_PARAM(zfs, zfs_, history_output_max, U64, ZMOD_RW,
81798190
"Maximum size in bytes of ZFS ioctl output that will be logged");
8191+
8192+
ZFS_MODULE_PARAM(zfs, zfs_, recv_force_needs_perm, INT, ZMOD_RW,
8193+
"Force receive (-F) requires rollback permission");

0 commit comments

Comments
 (0)