Now that we do the sanity checks directly on the data copied from user, we can also constify the fsmap data while the checks are in progress. Do the validation checks on constified data, it imposes that the fsmap data is not updated during validation and assures readers that nothing strange happens during the validation sequence of calls. Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxx> --- v2: new patch fs/ext4/fsmap.c | 8 ++++---- fs/ext4/fsmap.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 463e8165b1e9..655379c96fcf 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -572,7 +572,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb, /* Do we recognize the device? */ static bool ext4_getfsmap_is_valid_device(struct super_block *sb, - struct fsmap *fm) + const struct fsmap *fm) { if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX || fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev)) @@ -584,8 +584,8 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb, } /* Ensure that the low key is less than the high key. */ -static bool ext4_getfsmap_check_keys(struct fsmap *low_key, - struct fsmap *high_key) +static bool ext4_getfsmap_check_keys(const struct fsmap *low_key, + const struct fsmap *high_key) { u64 l_fmr_phys = low_key->fmr_physical + low_key->fmr_length; @@ -607,7 +607,7 @@ static bool ext4_getfsmap_check_keys(struct fsmap *low_key, return false; } -int ext4_fsmap_check_head(struct super_block *sb, struct fsmap_head *head) +int ext4_fsmap_check_head(struct super_block *sb, const struct fsmap_head *head) { const struct fsmap *l = &head->fmh_keys[0]; const struct fsmap *h = &head->fmh_keys[1]; diff --git a/fs/ext4/fsmap.h b/fs/ext4/fsmap.h index e7c510afd672..8325258def7b 100644 --- a/fs/ext4/fsmap.h +++ b/fs/ext4/fsmap.h @@ -33,7 +33,8 @@ void ext4_fsmap_from_internal(struct super_block *sb, struct fsmap *dest, struct ext4_fsmap *src); void ext4_fsmap_to_internal(struct super_block *sb, struct ext4_fsmap *dest, struct fsmap *src); -int ext4_fsmap_check_head(struct super_block *sb, struct fsmap_head *head); +int ext4_fsmap_check_head(struct super_block *sb, + const struct fsmap_head *head); /* fsmap to userspace formatter - copy to user & advance pointer */ typedef int (*ext4_fsmap_format_t)(struct ext4_fsmap *, void *); -- 2.40.0.rc1.284.g88254d51c5-goog