aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2018-03-22 22:08:27 -0400
committerEric W. Biederman <ebiederm@xmission.com>2018-03-22 22:08:27 -0400
commit7191adff2a5566efb139c79ea03eda3d0520d44a (patch)
treebfde0d973881cfaa21e9993b290de4ca9c5bbe4b
parentaefad9593ec5ad4aae5346253a8b646364cd7317 (diff)
shm/security: Pass kern_ipc_perm not shmid_kernel into the shm security hooks
All of the implementations of security hooks that take shmid_kernel only access shm_perm the struct kern_ipc_perm member. This means the dependencies of the shm security hooks can be simplified by passing the kern_ipc_perm member of shmid_kernel.. Making this change will allow struct shmid_kernel to become private to ipc/shm.c. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r--include/linux/lsm_hooks.h10
-rw-r--r--include/linux/security.h21
-rw-r--r--ipc/shm.c17
-rw-r--r--security/security.c10
-rw-r--r--security/selinux/hooks.c28
-rw-r--r--security/smack/smack_lsm.c22
6 files changed, 52 insertions, 56 deletions
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index e4a94863a88c..cac7a8082c43 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1585,11 +1585,11 @@ union security_list_options {
1585 struct task_struct *target, long type, 1585 struct task_struct *target, long type,
1586 int mode); 1586 int mode);
1587 1587
1588 int (*shm_alloc_security)(struct shmid_kernel *shp); 1588 int (*shm_alloc_security)(struct kern_ipc_perm *shp);
1589 void (*shm_free_security)(struct shmid_kernel *shp); 1589 void (*shm_free_security)(struct kern_ipc_perm *shp);
1590 int (*shm_associate)(struct shmid_kernel *shp, int shmflg); 1590 int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg);
1591 int (*shm_shmctl)(struct shmid_kernel *shp, int cmd); 1591 int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd);
1592 int (*shm_shmat)(struct shmid_kernel *shp, char __user *shmaddr, 1592 int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr,
1593 int shmflg); 1593 int shmflg);
1594 1594
1595 int (*sem_alloc_security)(struct kern_ipc_perm *sma); 1595 int (*sem_alloc_security)(struct kern_ipc_perm *sma);
diff --git a/include/linux/security.h b/include/linux/security.h
index fa7adac4b99a..f390755808ea 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -49,7 +49,6 @@ struct qstr;
49struct iattr; 49struct iattr;
50struct fown_struct; 50struct fown_struct;
51struct file_operations; 51struct file_operations;
52struct shmid_kernel;
53struct msg_msg; 52struct msg_msg;
54struct msg_queue; 53struct msg_queue;
55struct xattr; 54struct xattr;
@@ -362,11 +361,11 @@ int security_msg_queue_msgsnd(struct msg_queue *msq,
362 struct msg_msg *msg, int msqflg); 361 struct msg_msg *msg, int msqflg);
363int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg, 362int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
364 struct task_struct *target, long type, int mode); 363 struct task_struct *target, long type, int mode);
365int security_shm_alloc(struct shmid_kernel *shp); 364int security_shm_alloc(struct kern_ipc_perm *shp);
366void security_shm_free(struct shmid_kernel *shp); 365void security_shm_free(struct kern_ipc_perm *shp);
367int security_shm_associate(struct shmid_kernel *shp, int shmflg); 366int security_shm_associate(struct kern_ipc_perm *shp, int shmflg);
368int security_shm_shmctl(struct shmid_kernel *shp, int cmd); 367int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd);
369int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg); 368int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg);
370int security_sem_alloc(struct kern_ipc_perm *sma); 369int security_sem_alloc(struct kern_ipc_perm *sma);
371void security_sem_free(struct kern_ipc_perm *sma); 370void security_sem_free(struct kern_ipc_perm *sma);
372int security_sem_associate(struct kern_ipc_perm *sma, int semflg); 371int security_sem_associate(struct kern_ipc_perm *sma, int semflg);
@@ -1077,26 +1076,26 @@ static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
1077 return 0; 1076 return 0;
1078} 1077}
1079 1078
1080static inline int security_shm_alloc(struct shmid_kernel *shp) 1079static inline int security_shm_alloc(struct kern_ipc_perm *shp)
1081{ 1080{
1082 return 0; 1081 return 0;
1083} 1082}
1084 1083
1085static inline void security_shm_free(struct shmid_kernel *shp) 1084static inline void security_shm_free(struct kern_ipc_perm *shp)
1086{ } 1085{ }
1087 1086
1088static inline int security_shm_associate(struct shmid_kernel *shp, 1087static inline int security_shm_associate(struct kern_ipc_perm *shp,
1089 int shmflg) 1088 int shmflg)
1090{ 1089{
1091 return 0; 1090 return 0;
1092} 1091}
1093 1092
1094static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd) 1093static inline int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
1095{ 1094{
1096 return 0; 1095 return 0;
1097} 1096}
1098 1097
1099static inline int security_shm_shmat(struct shmid_kernel *shp, 1098static inline int security_shm_shmat(struct kern_ipc_perm *shp,
1100 char __user *shmaddr, int shmflg) 1099 char __user *shmaddr, int shmflg)
1101{ 1100{
1102 return 0; 1101 return 0;
diff --git a/ipc/shm.c b/ipc/shm.c
index 4643865e9171..387a786e7be1 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -181,7 +181,7 @@ static void shm_rcu_free(struct rcu_head *head)
181 rcu); 181 rcu);
182 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, 182 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel,
183 shm_perm); 183 shm_perm);
184 security_shm_free(shp); 184 security_shm_free(&shp->shm_perm);
185 kvfree(shp); 185 kvfree(shp);
186} 186}
187 187
@@ -554,7 +554,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
554 shp->mlock_user = NULL; 554 shp->mlock_user = NULL;
555 555
556 shp->shm_perm.security = NULL; 556 shp->shm_perm.security = NULL;
557 error = security_shm_alloc(shp); 557 error = security_shm_alloc(&shp->shm_perm);
558 if (error) { 558 if (error) {
559 kvfree(shp); 559 kvfree(shp);
560 return error; 560 return error;
@@ -635,10 +635,7 @@ no_file:
635 */ 635 */
636static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) 636static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg)
637{ 637{
638 struct shmid_kernel *shp; 638 return security_shm_associate(ipcp, shmflg);
639
640 shp = container_of(ipcp, struct shmid_kernel, shm_perm);
641 return security_shm_associate(shp, shmflg);
642} 639}
643 640
644/* 641/*
@@ -835,7 +832,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
835 832
836 shp = container_of(ipcp, struct shmid_kernel, shm_perm); 833 shp = container_of(ipcp, struct shmid_kernel, shm_perm);
837 834
838 err = security_shm_shmctl(shp, cmd); 835 err = security_shm_shmctl(&shp->shm_perm, cmd);
839 if (err) 836 if (err)
840 goto out_unlock1; 837 goto out_unlock1;
841 838
@@ -934,7 +931,7 @@ static int shmctl_stat(struct ipc_namespace *ns, int shmid,
934 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) 931 if (ipcperms(ns, &shp->shm_perm, S_IRUGO))
935 goto out_unlock; 932 goto out_unlock;
936 933
937 err = security_shm_shmctl(shp, cmd); 934 err = security_shm_shmctl(&shp->shm_perm, cmd);
938 if (err) 935 if (err)
939 goto out_unlock; 936 goto out_unlock;
940 937
@@ -978,7 +975,7 @@ static int shmctl_do_lock(struct ipc_namespace *ns, int shmid, int cmd)
978 } 975 }
979 976
980 audit_ipc_obj(&(shp->shm_perm)); 977 audit_ipc_obj(&(shp->shm_perm));
981 err = security_shm_shmctl(shp, cmd); 978 err = security_shm_shmctl(&shp->shm_perm, cmd);
982 if (err) 979 if (err)
983 goto out_unlock1; 980 goto out_unlock1;
984 981
@@ -1348,7 +1345,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
1348 if (ipcperms(ns, &shp->shm_perm, acc_mode)) 1345 if (ipcperms(ns, &shp->shm_perm, acc_mode))
1349 goto out_unlock; 1346 goto out_unlock;
1350 1347
1351 err = security_shm_shmat(shp, shmaddr, shmflg); 1348 err = security_shm_shmat(&shp->shm_perm, shmaddr, shmflg);
1352 if (err) 1349 if (err)
1353 goto out_unlock; 1350 goto out_unlock;
1354 1351
diff --git a/security/security.c b/security/security.c
index d3b9aeb6b73b..77b69bd6f234 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1195,27 +1195,27 @@ int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1195 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode); 1195 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
1196} 1196}
1197 1197
1198int security_shm_alloc(struct shmid_kernel *shp) 1198int security_shm_alloc(struct kern_ipc_perm *shp)
1199{ 1199{
1200 return call_int_hook(shm_alloc_security, 0, shp); 1200 return call_int_hook(shm_alloc_security, 0, shp);
1201} 1201}
1202 1202
1203void security_shm_free(struct shmid_kernel *shp) 1203void security_shm_free(struct kern_ipc_perm *shp)
1204{ 1204{
1205 call_void_hook(shm_free_security, shp); 1205 call_void_hook(shm_free_security, shp);
1206} 1206}
1207 1207
1208int security_shm_associate(struct shmid_kernel *shp, int shmflg) 1208int security_shm_associate(struct kern_ipc_perm *shp, int shmflg)
1209{ 1209{
1210 return call_int_hook(shm_associate, 0, shp, shmflg); 1210 return call_int_hook(shm_associate, 0, shp, shmflg);
1211} 1211}
1212 1212
1213int security_shm_shmctl(struct shmid_kernel *shp, int cmd) 1213int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
1214{ 1214{
1215 return call_int_hook(shm_shmctl, 0, shp, cmd); 1215 return call_int_hook(shm_shmctl, 0, shp, cmd);
1216} 1216}
1217 1217
1218int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg) 1218int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg)
1219{ 1219{
1220 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg); 1220 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
1221} 1221}
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index cce994e9fc0a..14f9e6c08273 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5674,53 +5674,53 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
5674} 5674}
5675 5675
5676/* Shared Memory security operations */ 5676/* Shared Memory security operations */
5677static int selinux_shm_alloc_security(struct shmid_kernel *shp) 5677static int selinux_shm_alloc_security(struct kern_ipc_perm *shp)
5678{ 5678{
5679 struct ipc_security_struct *isec; 5679 struct ipc_security_struct *isec;
5680 struct common_audit_data ad; 5680 struct common_audit_data ad;
5681 u32 sid = current_sid(); 5681 u32 sid = current_sid();
5682 int rc; 5682 int rc;
5683 5683
5684 rc = ipc_alloc_security(&shp->shm_perm, SECCLASS_SHM); 5684 rc = ipc_alloc_security(shp, SECCLASS_SHM);
5685 if (rc) 5685 if (rc)
5686 return rc; 5686 return rc;
5687 5687
5688 isec = shp->shm_perm.security; 5688 isec = shp->security;
5689 5689
5690 ad.type = LSM_AUDIT_DATA_IPC; 5690 ad.type = LSM_AUDIT_DATA_IPC;
5691 ad.u.ipc_id = shp->shm_perm.key; 5691 ad.u.ipc_id = shp->key;
5692 5692
5693 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5693 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
5694 SHM__CREATE, &ad); 5694 SHM__CREATE, &ad);
5695 if (rc) { 5695 if (rc) {
5696 ipc_free_security(&shp->shm_perm); 5696 ipc_free_security(shp);
5697 return rc; 5697 return rc;
5698 } 5698 }
5699 return 0; 5699 return 0;
5700} 5700}
5701 5701
5702static void selinux_shm_free_security(struct shmid_kernel *shp) 5702static void selinux_shm_free_security(struct kern_ipc_perm *shp)
5703{ 5703{
5704 ipc_free_security(&shp->shm_perm); 5704 ipc_free_security(shp);
5705} 5705}
5706 5706
5707static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg) 5707static int selinux_shm_associate(struct kern_ipc_perm *shp, int shmflg)
5708{ 5708{
5709 struct ipc_security_struct *isec; 5709 struct ipc_security_struct *isec;
5710 struct common_audit_data ad; 5710 struct common_audit_data ad;
5711 u32 sid = current_sid(); 5711 u32 sid = current_sid();
5712 5712
5713 isec = shp->shm_perm.security; 5713 isec = shp->security;
5714 5714
5715 ad.type = LSM_AUDIT_DATA_IPC; 5715 ad.type = LSM_AUDIT_DATA_IPC;
5716 ad.u.ipc_id = shp->shm_perm.key; 5716 ad.u.ipc_id = shp->key;
5717 5717
5718 return avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5718 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
5719 SHM__ASSOCIATE, &ad); 5719 SHM__ASSOCIATE, &ad);
5720} 5720}
5721 5721
5722/* Note, at this point, shp is locked down */ 5722/* Note, at this point, shp is locked down */
5723static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd) 5723static int selinux_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
5724{ 5724{
5725 int perms; 5725 int perms;
5726 int err; 5726 int err;
@@ -5749,11 +5749,11 @@ static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd)
5749 return 0; 5749 return 0;
5750 } 5750 }
5751 5751
5752 err = ipc_has_perm(&shp->shm_perm, perms); 5752 err = ipc_has_perm(shp, perms);
5753 return err; 5753 return err;
5754} 5754}
5755 5755
5756static int selinux_shm_shmat(struct shmid_kernel *shp, 5756static int selinux_shm_shmat(struct kern_ipc_perm *shp,
5757 char __user *shmaddr, int shmflg) 5757 char __user *shmaddr, int shmflg)
5758{ 5758{
5759 u32 perms; 5759 u32 perms;
@@ -5763,7 +5763,7 @@ static int selinux_shm_shmat(struct shmid_kernel *shp,
5763 else 5763 else
5764 perms = SHM__READ | SHM__WRITE; 5764 perms = SHM__READ | SHM__WRITE;
5765 5765
5766 return ipc_has_perm(&shp->shm_perm, perms); 5766 return ipc_has_perm(shp, perms);
5767} 5767}
5768 5768
5769/* Semaphore security operations */ 5769/* Semaphore security operations */
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 0402b8c1aec1..a3398c7f32c9 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2950,9 +2950,9 @@ static void smack_msg_msg_free_security(struct msg_msg *msg)
2950 * 2950 *
2951 * Returns a pointer to the smack value 2951 * Returns a pointer to the smack value
2952 */ 2952 */
2953static struct smack_known *smack_of_shm(struct shmid_kernel *shp) 2953static struct smack_known *smack_of_shm(struct kern_ipc_perm *shp)
2954{ 2954{
2955 return (struct smack_known *)shp->shm_perm.security; 2955 return (struct smack_known *)shp->security;
2956} 2956}
2957 2957
2958/** 2958/**
@@ -2961,9 +2961,9 @@ static struct smack_known *smack_of_shm(struct shmid_kernel *shp)
2961 * 2961 *
2962 * Returns 0 2962 * Returns 0
2963 */ 2963 */
2964static int smack_shm_alloc_security(struct shmid_kernel *shp) 2964static int smack_shm_alloc_security(struct kern_ipc_perm *shp)
2965{ 2965{
2966 struct kern_ipc_perm *isp = &shp->shm_perm; 2966 struct kern_ipc_perm *isp = shp;
2967 struct smack_known *skp = smk_of_current(); 2967 struct smack_known *skp = smk_of_current();
2968 2968
2969 isp->security = skp; 2969 isp->security = skp;
@@ -2976,9 +2976,9 @@ static int smack_shm_alloc_security(struct shmid_kernel *shp)
2976 * 2976 *
2977 * Clears the blob pointer 2977 * Clears the blob pointer
2978 */ 2978 */
2979static void smack_shm_free_security(struct shmid_kernel *shp) 2979static void smack_shm_free_security(struct kern_ipc_perm *shp)
2980{ 2980{
2981 struct kern_ipc_perm *isp = &shp->shm_perm; 2981 struct kern_ipc_perm *isp = shp;
2982 2982
2983 isp->security = NULL; 2983 isp->security = NULL;
2984} 2984}
@@ -2990,7 +2990,7 @@ static void smack_shm_free_security(struct shmid_kernel *shp)
2990 * 2990 *
2991 * Returns 0 if current has the requested access, error code otherwise 2991 * Returns 0 if current has the requested access, error code otherwise
2992 */ 2992 */
2993static int smk_curacc_shm(struct shmid_kernel *shp, int access) 2993static int smk_curacc_shm(struct kern_ipc_perm *shp, int access)
2994{ 2994{
2995 struct smack_known *ssp = smack_of_shm(shp); 2995 struct smack_known *ssp = smack_of_shm(shp);
2996 struct smk_audit_info ad; 2996 struct smk_audit_info ad;
@@ -2998,7 +2998,7 @@ static int smk_curacc_shm(struct shmid_kernel *shp, int access)
2998 2998
2999#ifdef CONFIG_AUDIT 2999#ifdef CONFIG_AUDIT
3000 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC); 3000 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
3001 ad.a.u.ipc_id = shp->shm_perm.id; 3001 ad.a.u.ipc_id = shp->id;
3002#endif 3002#endif
3003 rc = smk_curacc(ssp, access, &ad); 3003 rc = smk_curacc(ssp, access, &ad);
3004 rc = smk_bu_current("shm", ssp, access, rc); 3004 rc = smk_bu_current("shm", ssp, access, rc);
@@ -3012,7 +3012,7 @@ static int smk_curacc_shm(struct shmid_kernel *shp, int access)
3012 * 3012 *
3013 * Returns 0 if current has the requested access, error code otherwise 3013 * Returns 0 if current has the requested access, error code otherwise
3014 */ 3014 */
3015static int smack_shm_associate(struct shmid_kernel *shp, int shmflg) 3015static int smack_shm_associate(struct kern_ipc_perm *shp, int shmflg)
3016{ 3016{
3017 int may; 3017 int may;
3018 3018
@@ -3027,7 +3027,7 @@ static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
3027 * 3027 *
3028 * Returns 0 if current has the requested access, error code otherwise 3028 * Returns 0 if current has the requested access, error code otherwise
3029 */ 3029 */
3030static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd) 3030static int smack_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
3031{ 3031{
3032 int may; 3032 int may;
3033 3033
@@ -3062,7 +3062,7 @@ static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
3062 * 3062 *
3063 * Returns 0 if current has the requested access, error code otherwise 3063 * Returns 0 if current has the requested access, error code otherwise
3064 */ 3064 */
3065static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, 3065static int smack_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr,
3066 int shmflg) 3066 int shmflg)
3067{ 3067{
3068 int may; 3068 int may;