@@ -601,9 +601,16 @@ EXPORT_SYMBOL(bpf_prog_get_type_path);
601
601
static int bpf_show_options (struct seq_file * m , struct dentry * root )
602
602
{
603
603
struct bpf_mount_opts * opts = root -> d_sb -> s_fs_info ;
604
- umode_t mode = d_inode (root )-> i_mode & S_IALLUGO & ~S_ISVTX ;
604
+ struct inode * inode = d_inode (root );
605
+ umode_t mode = inode -> i_mode & S_IALLUGO & ~S_ISVTX ;
605
606
u64 mask ;
606
607
608
+ if (!uid_eq (inode -> i_uid , GLOBAL_ROOT_UID ))
609
+ seq_printf (m , ",uid=%u" ,
610
+ from_kuid_munged (& init_user_ns , inode -> i_uid ));
611
+ if (!gid_eq (inode -> i_gid , GLOBAL_ROOT_GID ))
612
+ seq_printf (m , ",gid=%u" ,
613
+ from_kgid_munged (& init_user_ns , inode -> i_gid ));
607
614
if (mode != S_IRWXUGO )
608
615
seq_printf (m , ",mode=%o" , mode );
609
616
@@ -652,6 +659,8 @@ const struct super_operations bpf_super_ops = {
652
659
};
653
660
654
661
enum {
662
+ OPT_UID ,
663
+ OPT_GID ,
655
664
OPT_MODE ,
656
665
OPT_DELEGATE_CMDS ,
657
666
OPT_DELEGATE_MAPS ,
@@ -660,6 +669,8 @@ enum {
660
669
};
661
670
662
671
static const struct fs_parameter_spec bpf_fs_parameters [] = {
672
+ fsparam_u32 ("uid" , OPT_UID ),
673
+ fsparam_u32 ("gid" , OPT_GID ),
663
674
fsparam_u32oct ("mode" , OPT_MODE ),
664
675
fsparam_string ("delegate_cmds" , OPT_DELEGATE_CMDS ),
665
676
fsparam_string ("delegate_maps" , OPT_DELEGATE_MAPS ),
@@ -672,6 +683,8 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
672
683
{
673
684
struct bpf_mount_opts * opts = fc -> s_fs_info ;
674
685
struct fs_parse_result result ;
686
+ kuid_t uid ;
687
+ kgid_t gid ;
675
688
int opt , err ;
676
689
u64 msk ;
677
690
@@ -694,6 +707,34 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
694
707
}
695
708
696
709
switch (opt ) {
710
+ case OPT_UID :
711
+ uid = make_kuid (current_user_ns (), result .uint_32 );
712
+ if (!uid_valid (uid ))
713
+ goto bad_value ;
714
+
715
+ /*
716
+ * The requested uid must be representable in the
717
+ * filesystem's idmapping.
718
+ */
719
+ if (!kuid_has_mapping (fc -> user_ns , uid ))
720
+ goto bad_value ;
721
+
722
+ opts -> uid = uid ;
723
+ break ;
724
+ case OPT_GID :
725
+ gid = make_kgid (current_user_ns (), result .uint_32 );
726
+ if (!gid_valid (gid ))
727
+ goto bad_value ;
728
+
729
+ /*
730
+ * The requested gid must be representable in the
731
+ * filesystem's idmapping.
732
+ */
733
+ if (!kgid_has_mapping (fc -> user_ns , gid ))
734
+ goto bad_value ;
735
+
736
+ opts -> gid = gid ;
737
+ break ;
697
738
case OPT_MODE :
698
739
opts -> mode = result .uint_32 & S_IALLUGO ;
699
740
break ;
@@ -722,6 +763,9 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
722
763
}
723
764
724
765
return 0 ;
766
+
767
+ bad_value :
768
+ return invalfc (fc , "Bad value for '%s'" , param -> key );
725
769
}
726
770
727
771
struct bpf_preload_ops * bpf_preload_ops ;
@@ -808,6 +852,8 @@ static int bpf_fill_super(struct super_block *sb, struct fs_context *fc)
808
852
sb -> s_op = & bpf_super_ops ;
809
853
810
854
inode = sb -> s_root -> d_inode ;
855
+ inode -> i_uid = opts -> uid ;
856
+ inode -> i_gid = opts -> gid ;
811
857
inode -> i_op = & bpf_dir_iops ;
812
858
inode -> i_mode &= ~S_IALLUGO ;
813
859
populate_bpffs (sb -> s_root );
@@ -843,6 +889,8 @@ static int bpf_init_fs_context(struct fs_context *fc)
843
889
return - ENOMEM ;
844
890
845
891
opts -> mode = S_IRWXUGO ;
892
+ opts -> uid = current_fsuid ();
893
+ opts -> gid = current_fsgid ();
846
894
847
895
/* start out with no BPF token delegation enabled */
848
896
opts -> delegate_cmds = 0 ;
0 commit comments