Skip to content

Commit 9fd1bf0

Browse files
allanjudeshodanshok
authored andcommitted
Avoid null pointer dereference in dsl_fs_ss_limit_check()
Check for cr == NULL before dereferencing it in dsl_enforce_ds_ss_limits() to lookup the zone/jail ID. Reported-by: Coverity (CID 1210459) Reviewed-by: Richard Yao <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Allan Jude <[email protected]> Closes openzfs#14103
1 parent 1279202 commit 9fd1bf0

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

module/zfs/dsl_dir.c

+12-13
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,18 @@ dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
815815
ASSERT(prop == ZFS_PROP_FILESYSTEM_LIMIT ||
816816
prop == ZFS_PROP_SNAPSHOT_LIMIT);
817817

818+
if (prop == ZFS_PROP_SNAPSHOT_LIMIT) {
819+
/*
820+
* We don't enforce the limit for temporary snapshots. This is
821+
* indicated by a NULL cred_t argument.
822+
*/
823+
if (cr == NULL)
824+
return (0);
825+
826+
count_prop = DD_FIELD_SNAPSHOT_COUNT;
827+
} else {
828+
count_prop = DD_FIELD_FILESYSTEM_COUNT;
829+
}
818830
/*
819831
* If we're allowed to change the limit, don't enforce the limit
820832
* e.g. this can happen if a snapshot is taken by an administrative
@@ -834,19 +846,6 @@ dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
834846
if (delta == 0)
835847
return (0);
836848

837-
if (prop == ZFS_PROP_SNAPSHOT_LIMIT) {
838-
/*
839-
* We don't enforce the limit for temporary snapshots. This is
840-
* indicated by a NULL cred_t argument.
841-
*/
842-
if (cr == NULL)
843-
return (0);
844-
845-
count_prop = DD_FIELD_SNAPSHOT_COUNT;
846-
} else {
847-
count_prop = DD_FIELD_FILESYSTEM_COUNT;
848-
}
849-
850849
/*
851850
* If an ancestor has been provided, stop checking the limit once we
852851
* hit that dir. We need this during rename so that we don't overcount

0 commit comments

Comments
 (0)