@@ -322,7 +322,7 @@ static void inode_free_security(struct inode *inode)
322
322
323
323
if (!isec )
324
324
return ;
325
- sbsec = inode -> i_sb -> s_security ;
325
+ sbsec = selinux_superblock ( inode -> i_sb ) ;
326
326
/*
327
327
* As not all inode security structures are in a list, we check for
328
328
* empty list outside of the lock to make sure that we won't waste
@@ -340,13 +340,6 @@ static void inode_free_security(struct inode *inode)
340
340
}
341
341
}
342
342
343
- static void superblock_free_security (struct super_block * sb )
344
- {
345
- struct superblock_security_struct * sbsec = sb -> s_security ;
346
- sb -> s_security = NULL ;
347
- kfree (sbsec );
348
- }
349
-
350
343
struct selinux_mnt_opts {
351
344
const char * fscontext , * context , * rootcontext , * defcontext ;
352
345
};
@@ -458,7 +451,7 @@ static int selinux_is_genfs_special_handling(struct super_block *sb)
458
451
459
452
static int selinux_is_sblabel_mnt (struct super_block * sb )
460
453
{
461
- struct superblock_security_struct * sbsec = sb -> s_security ;
454
+ struct superblock_security_struct * sbsec = selinux_superblock ( sb ) ;
462
455
463
456
/*
464
457
* IMPORTANT: Double-check logic in this function when adding a new
@@ -535,7 +528,7 @@ static int sb_check_xattr_support(struct super_block *sb)
535
528
536
529
static int sb_finish_set_opts (struct super_block * sb )
537
530
{
538
- struct superblock_security_struct * sbsec = sb -> s_security ;
531
+ struct superblock_security_struct * sbsec = selinux_superblock ( sb ) ;
539
532
struct dentry * root = sb -> s_root ;
540
533
struct inode * root_inode = d_backing_inode (root );
541
534
int rc = 0 ;
@@ -626,7 +619,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
626
619
unsigned long * set_kern_flags )
627
620
{
628
621
const struct cred * cred = current_cred ();
629
- struct superblock_security_struct * sbsec = sb -> s_security ;
622
+ struct superblock_security_struct * sbsec = selinux_superblock ( sb ) ;
630
623
struct dentry * root = sb -> s_root ;
631
624
struct selinux_mnt_opts * opts = mnt_opts ;
632
625
struct inode_security_struct * root_isec ;
@@ -863,8 +856,8 @@ static int selinux_set_mnt_opts(struct super_block *sb,
863
856
static int selinux_cmp_sb_context (const struct super_block * oldsb ,
864
857
const struct super_block * newsb )
865
858
{
866
- struct superblock_security_struct * old = oldsb -> s_security ;
867
- struct superblock_security_struct * new = newsb -> s_security ;
859
+ struct superblock_security_struct * old = selinux_superblock ( oldsb ) ;
860
+ struct superblock_security_struct * new = selinux_superblock ( newsb ) ;
868
861
char oldflags = old -> flags & SE_MNTMASK ;
869
862
char newflags = new -> flags & SE_MNTMASK ;
870
863
@@ -896,8 +889,9 @@ static int selinux_sb_clone_mnt_opts(const struct super_block *oldsb,
896
889
unsigned long * set_kern_flags )
897
890
{
898
891
int rc = 0 ;
899
- const struct superblock_security_struct * oldsbsec = oldsb -> s_security ;
900
- struct superblock_security_struct * newsbsec = newsb -> s_security ;
892
+ const struct superblock_security_struct * oldsbsec =
893
+ selinux_superblock (oldsb );
894
+ struct superblock_security_struct * newsbsec = selinux_superblock (newsb );
901
895
902
896
int set_fscontext = (oldsbsec -> flags & FSCONTEXT_MNT );
903
897
int set_context = (oldsbsec -> flags & CONTEXT_MNT );
@@ -1076,7 +1070,7 @@ static int show_sid(struct seq_file *m, u32 sid)
1076
1070
1077
1071
static int selinux_sb_show_options (struct seq_file * m , struct super_block * sb )
1078
1072
{
1079
- struct superblock_security_struct * sbsec = sb -> s_security ;
1073
+ struct superblock_security_struct * sbsec = selinux_superblock ( sb ) ;
1080
1074
int rc ;
1081
1075
1082
1076
if (!(sbsec -> flags & SE_SBINITIALIZED ))
@@ -1427,7 +1421,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
1427
1421
if (isec -> sclass == SECCLASS_FILE )
1428
1422
isec -> sclass = inode_mode_to_security_class (inode -> i_mode );
1429
1423
1430
- sbsec = inode -> i_sb -> s_security ;
1424
+ sbsec = selinux_superblock ( inode -> i_sb ) ;
1431
1425
if (!(sbsec -> flags & SE_SBINITIALIZED )) {
1432
1426
/* Defer initialization until selinux_complete_init,
1433
1427
after the initial policy is loaded and the security
@@ -1778,7 +1772,8 @@ selinux_determine_inode_label(const struct task_security_struct *tsec,
1778
1772
const struct qstr * name , u16 tclass ,
1779
1773
u32 * _new_isid )
1780
1774
{
1781
- const struct superblock_security_struct * sbsec = dir -> i_sb -> s_security ;
1775
+ const struct superblock_security_struct * sbsec =
1776
+ selinux_superblock (dir -> i_sb );
1782
1777
1783
1778
if ((sbsec -> flags & SE_SBINITIALIZED ) &&
1784
1779
(sbsec -> behavior == SECURITY_FS_USE_MNTPOINT )) {
@@ -1809,7 +1804,7 @@ static int may_create(struct inode *dir,
1809
1804
int rc ;
1810
1805
1811
1806
dsec = inode_security (dir );
1812
- sbsec = dir -> i_sb -> s_security ;
1807
+ sbsec = selinux_superblock ( dir -> i_sb ) ;
1813
1808
1814
1809
sid = tsec -> sid ;
1815
1810
@@ -1958,7 +1953,7 @@ static int superblock_has_perm(const struct cred *cred,
1958
1953
struct superblock_security_struct * sbsec ;
1959
1954
u32 sid = cred_sid (cred );
1960
1955
1961
- sbsec = sb -> s_security ;
1956
+ sbsec = selinux_superblock ( sb ) ;
1962
1957
return avc_has_perm (& selinux_state ,
1963
1958
sid , sbsec -> sid , SECCLASS_FILESYSTEM , perms , ad );
1964
1959
}
@@ -2587,28 +2582,18 @@ static void selinux_bprm_committed_creds(struct linux_binprm *bprm)
2587
2582
2588
2583
static int selinux_sb_alloc_security (struct super_block * sb )
2589
2584
{
2590
- struct superblock_security_struct * sbsec ;
2591
-
2592
- sbsec = kzalloc (sizeof (struct superblock_security_struct ), GFP_KERNEL );
2593
- if (!sbsec )
2594
- return - ENOMEM ;
2585
+ struct superblock_security_struct * sbsec = selinux_superblock (sb );
2595
2586
2596
2587
mutex_init (& sbsec -> lock );
2597
2588
INIT_LIST_HEAD (& sbsec -> isec_head );
2598
2589
spin_lock_init (& sbsec -> isec_lock );
2599
2590
sbsec -> sid = SECINITSID_UNLABELED ;
2600
2591
sbsec -> def_sid = SECINITSID_FILE ;
2601
2592
sbsec -> mntpoint_sid = SECINITSID_UNLABELED ;
2602
- sb -> s_security = sbsec ;
2603
2593
2604
2594
return 0 ;
2605
2595
}
2606
2596
2607
- static void selinux_sb_free_security (struct super_block * sb )
2608
- {
2609
- superblock_free_security (sb );
2610
- }
2611
-
2612
2597
static inline int opt_len (const char * s )
2613
2598
{
2614
2599
bool open_quote = false;
@@ -2687,7 +2672,7 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
2687
2672
static int selinux_sb_remount (struct super_block * sb , void * mnt_opts )
2688
2673
{
2689
2674
struct selinux_mnt_opts * opts = mnt_opts ;
2690
- struct superblock_security_struct * sbsec = sb -> s_security ;
2675
+ struct superblock_security_struct * sbsec = selinux_superblock ( sb ) ;
2691
2676
u32 sid ;
2692
2677
int rc ;
2693
2678
@@ -2925,7 +2910,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
2925
2910
int rc ;
2926
2911
char * context ;
2927
2912
2928
- sbsec = dir -> i_sb -> s_security ;
2913
+ sbsec = selinux_superblock ( dir -> i_sb ) ;
2929
2914
2930
2915
newsid = tsec -> create_sid ;
2931
2916
@@ -3227,7 +3212,7 @@ static int selinux_inode_setxattr(struct user_namespace *mnt_userns,
3227
3212
if (!selinux_initialized (& selinux_state ))
3228
3213
return (inode_owner_or_capable (mnt_userns , inode ) ? 0 : - EPERM );
3229
3214
3230
- sbsec = inode -> i_sb -> s_security ;
3215
+ sbsec = selinux_superblock ( inode -> i_sb ) ;
3231
3216
if (!(sbsec -> flags & SBLABEL_MNT ))
3232
3217
return - EOPNOTSUPP ;
3233
3218
@@ -3472,13 +3457,14 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,
3472
3457
const void * value , size_t size , int flags )
3473
3458
{
3474
3459
struct inode_security_struct * isec = inode_security_novalidate (inode );
3475
- struct superblock_security_struct * sbsec = inode -> i_sb -> s_security ;
3460
+ struct superblock_security_struct * sbsec ;
3476
3461
u32 newsid ;
3477
3462
int rc ;
3478
3463
3479
3464
if (strcmp (name , XATTR_SELINUX_SUFFIX ))
3480
3465
return - EOPNOTSUPP ;
3481
3466
3467
+ sbsec = selinux_superblock (inode -> i_sb );
3482
3468
if (!(sbsec -> flags & SBLABEL_MNT ))
3483
3469
return - EOPNOTSUPP ;
3484
3470
@@ -6975,6 +6961,7 @@ struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = {
6975
6961
.lbs_inode = sizeof (struct inode_security_struct ),
6976
6962
.lbs_ipc = sizeof (struct ipc_security_struct ),
6977
6963
.lbs_msg_msg = sizeof (struct msg_security_struct ),
6964
+ .lbs_superblock = sizeof (struct superblock_security_struct ),
6978
6965
};
6979
6966
6980
6967
#ifdef CONFIG_PERF_EVENTS
@@ -7075,7 +7062,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
7075
7062
LSM_HOOK_INIT (bprm_committing_creds , selinux_bprm_committing_creds ),
7076
7063
LSM_HOOK_INIT (bprm_committed_creds , selinux_bprm_committed_creds ),
7077
7064
7078
- LSM_HOOK_INIT (sb_free_security , selinux_sb_free_security ),
7079
7065
LSM_HOOK_INIT (sb_free_mnt_opts , selinux_free_mnt_opts ),
7080
7066
LSM_HOOK_INIT (sb_remount , selinux_sb_remount ),
7081
7067
LSM_HOOK_INIT (sb_kern_mount , selinux_sb_kern_mount ),
0 commit comments