Skip to content

Commit e77762e

Browse files
Hongbo Lihsiangkao
authored andcommitted
erofs: using domain_id in the safer way
Either the existing fscache usecase or the upcoming page cache sharing case, the `domain_id` should be protected as sensitive information, so we use the safer helpers to allocate, free and display domain_id. Signed-off-by: Hongbo Li <lihongbo22@huawei.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 7833181 commit e77762e

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

Documentation/filesystems/erofs.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ device=%s Specify a path to an extra device to be used together.
128128
directio (For file-backed mounts) Use direct I/O to access backing
129129
files, and asynchronous I/O will be enabled if supported.
130130
fsid=%s Specify a filesystem image ID for Fscache back-end.
131-
domain_id=%s Specify a domain ID in fscache mode so that different images
132-
with the same blobs under a given domain ID can share storage.
131+
domain_id=%s Specify a trusted domain ID for fscache mode so that
132+
different images with the same blobs, identified by blob IDs,
133+
can share storage within the same trusted domain.
133134
fsoffset=%llu Specify block-aligned filesystem offset for the primary device.
134135
=================== =========================================================
135136

fs/erofs/fscache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain)
379379
}
380380
fscache_relinquish_volume(domain->volume, NULL, false);
381381
mutex_unlock(&erofs_domain_list_lock);
382-
kfree(domain->domain_id);
382+
kfree_sensitive(domain->domain_id);
383383
kfree(domain);
384384
return;
385385
}
@@ -446,7 +446,7 @@ static int erofs_fscache_init_domain(struct super_block *sb)
446446
sbi->domain = domain;
447447
return 0;
448448
out:
449-
kfree(domain->domain_id);
449+
kfree_sensitive(domain->domain_id);
450450
kfree(domain);
451451
return err;
452452
}

fs/erofs/super.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,8 @@ static int erofs_fc_parse_param(struct fs_context *fc,
527527
return -ENOMEM;
528528
break;
529529
case Opt_domain_id:
530-
kfree(sbi->domain_id);
531-
sbi->domain_id = kstrdup(param->string, GFP_KERNEL);
532-
if (!sbi->domain_id)
533-
return -ENOMEM;
530+
kfree_sensitive(sbi->domain_id);
531+
sbi->domain_id = no_free_ptr(param->string);
534532
break;
535533
#else
536534
case Opt_fsid:
@@ -626,7 +624,7 @@ static void erofs_set_sysfs_name(struct super_block *sb)
626624
{
627625
struct erofs_sb_info *sbi = EROFS_SB(sb);
628626

629-
if (sbi->domain_id)
627+
if (sbi->domain_id && sbi->fsid)
630628
super_set_sysfs_name_generic(sb, "%s,%s", sbi->domain_id,
631629
sbi->fsid);
632630
else if (sbi->fsid)
@@ -861,7 +859,7 @@ static void erofs_sb_free(struct erofs_sb_info *sbi)
861859
{
862860
erofs_free_dev_context(sbi->devs);
863861
kfree(sbi->fsid);
864-
kfree(sbi->domain_id);
862+
kfree_sensitive(sbi->domain_id);
865863
if (sbi->dif0.file)
866864
fput(sbi->dif0.file);
867865
kfree(sbi->volume_name);

0 commit comments

Comments
 (0)