aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--security/smack/smack_lsm.c197
1 files changed, 58 insertions, 139 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index d960c2ea8d79..0735b8db158b 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2945,25 +2945,24 @@ static void smack_msg_msg_free_security(struct msg_msg *msg)
2945} 2945}
2946 2946
2947/** 2947/**
2948 * smack_of_shm - the smack pointer for the shm 2948 * smack_of_ipc - the smack pointer for the ipc
2949 * @shp: the object 2949 * @isp: the object
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 kern_ipc_perm *shp) 2953static struct smack_known *smack_of_ipc(struct kern_ipc_perm *isp)
2954{ 2954{
2955 return (struct smack_known *)shp->security; 2955 return (struct smack_known *)isp->security;
2956} 2956}
2957 2957
2958/** 2958/**
2959 * smack_shm_alloc_security - Set the security blob for shm 2959 * smack_ipc_alloc_security - Set the security blob for ipc
2960 * @shp: the object 2960 * @isp: the object
2961 * 2961 *
2962 * Returns 0 2962 * Returns 0
2963 */ 2963 */
2964static int smack_shm_alloc_security(struct kern_ipc_perm *shp) 2964static int smack_ipc_alloc_security(struct kern_ipc_perm *isp)
2965{ 2965{
2966 struct kern_ipc_perm *isp = shp;
2967 struct smack_known *skp = smk_of_current(); 2966 struct smack_known *skp = smk_of_current();
2968 2967
2969 isp->security = skp; 2968 isp->security = skp;
@@ -2971,34 +2970,32 @@ static int smack_shm_alloc_security(struct kern_ipc_perm *shp)
2971} 2970}
2972 2971
2973/** 2972/**
2974 * smack_shm_free_security - Clear the security blob for shm 2973 * smack_ipc_free_security - Clear the security blob for ipc
2975 * @shp: the object 2974 * @isp: the object
2976 * 2975 *
2977 * Clears the blob pointer 2976 * Clears the blob pointer
2978 */ 2977 */
2979static void smack_shm_free_security(struct kern_ipc_perm *shp) 2978static void smack_ipc_free_security(struct kern_ipc_perm *isp)
2980{ 2979{
2981 struct kern_ipc_perm *isp = shp;
2982
2983 isp->security = NULL; 2980 isp->security = NULL;
2984} 2981}
2985 2982
2986/** 2983/**
2987 * smk_curacc_shm : check if current has access on shm 2984 * smk_curacc_shm : check if current has access on shm
2988 * @shp : the object 2985 * @isp : the object
2989 * @access : access requested 2986 * @access : access requested
2990 * 2987 *
2991 * Returns 0 if current has the requested access, error code otherwise 2988 * Returns 0 if current has the requested access, error code otherwise
2992 */ 2989 */
2993static int smk_curacc_shm(struct kern_ipc_perm *shp, int access) 2990static int smk_curacc_shm(struct kern_ipc_perm *isp, int access)
2994{ 2991{
2995 struct smack_known *ssp = smack_of_shm(shp); 2992 struct smack_known *ssp = smack_of_ipc(isp);
2996 struct smk_audit_info ad; 2993 struct smk_audit_info ad;
2997 int rc; 2994 int rc;
2998 2995
2999#ifdef CONFIG_AUDIT 2996#ifdef CONFIG_AUDIT
3000 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC); 2997 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
3001 ad.a.u.ipc_id = shp->id; 2998 ad.a.u.ipc_id = isp->id;
3002#endif 2999#endif
3003 rc = smk_curacc(ssp, access, &ad); 3000 rc = smk_curacc(ssp, access, &ad);
3004 rc = smk_bu_current("shm", ssp, access, rc); 3001 rc = smk_bu_current("shm", ssp, access, rc);
@@ -3007,27 +3004,27 @@ static int smk_curacc_shm(struct kern_ipc_perm *shp, int access)
3007 3004
3008/** 3005/**
3009 * smack_shm_associate - Smack access check for shm 3006 * smack_shm_associate - Smack access check for shm
3010 * @shp: the object 3007 * @isp: the object
3011 * @shmflg: access requested 3008 * @shmflg: access requested
3012 * 3009 *
3013 * Returns 0 if current has the requested access, error code otherwise 3010 * Returns 0 if current has the requested access, error code otherwise
3014 */ 3011 */
3015static int smack_shm_associate(struct kern_ipc_perm *shp, int shmflg) 3012static int smack_shm_associate(struct kern_ipc_perm *isp, int shmflg)
3016{ 3013{
3017 int may; 3014 int may;
3018 3015
3019 may = smack_flags_to_may(shmflg); 3016 may = smack_flags_to_may(shmflg);
3020 return smk_curacc_shm(shp, may); 3017 return smk_curacc_shm(isp, may);
3021} 3018}
3022 3019
3023/** 3020/**
3024 * smack_shm_shmctl - Smack access check for shm 3021 * smack_shm_shmctl - Smack access check for shm
3025 * @shp: the object 3022 * @isp: the object
3026 * @cmd: what it wants to do 3023 * @cmd: what it wants to do
3027 * 3024 *
3028 * Returns 0 if current has the requested access, error code otherwise 3025 * Returns 0 if current has the requested access, error code otherwise
3029 */ 3026 */
3030static int smack_shm_shmctl(struct kern_ipc_perm *shp, int cmd) 3027static int smack_shm_shmctl(struct kern_ipc_perm *isp, int cmd)
3031{ 3028{
3032 int may; 3029 int may;
3033 3030
@@ -3051,81 +3048,42 @@ static int smack_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
3051 default: 3048 default:
3052 return -EINVAL; 3049 return -EINVAL;
3053 } 3050 }
3054 return smk_curacc_shm(shp, may); 3051 return smk_curacc_shm(isp, may);
3055} 3052}
3056 3053
3057/** 3054/**
3058 * smack_shm_shmat - Smack access for shmat 3055 * smack_shm_shmat - Smack access for shmat
3059 * @shp: the object 3056 * @isp: the object
3060 * @shmaddr: unused 3057 * @shmaddr: unused
3061 * @shmflg: access requested 3058 * @shmflg: access requested
3062 * 3059 *
3063 * Returns 0 if current has the requested access, error code otherwise 3060 * Returns 0 if current has the requested access, error code otherwise
3064 */ 3061 */
3065static int smack_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, 3062static int smack_shm_shmat(struct kern_ipc_perm *ipc, char __user *shmaddr,
3066 int shmflg) 3063 int shmflg)
3067{ 3064{
3068 int may; 3065 int may;
3069 3066
3070 may = smack_flags_to_may(shmflg); 3067 may = smack_flags_to_may(shmflg);
3071 return smk_curacc_shm(shp, may); 3068 return smk_curacc_shm(ipc, may);
3072}
3073
3074/**
3075 * smack_of_sem - the smack pointer for the sem
3076 * @sma: the object
3077 *
3078 * Returns a pointer to the smack value
3079 */
3080static struct smack_known *smack_of_sem(struct kern_ipc_perm *sma)
3081{
3082 return (struct smack_known *)sma->security;
3083}
3084
3085/**
3086 * smack_sem_alloc_security - Set the security blob for sem
3087 * @sma: the object
3088 *
3089 * Returns 0
3090 */
3091static int smack_sem_alloc_security(struct kern_ipc_perm *sma)
3092{
3093 struct kern_ipc_perm *isp = sma;
3094 struct smack_known *skp = smk_of_current();
3095
3096 isp->security = skp;
3097 return 0;
3098}
3099
3100/**
3101 * smack_sem_free_security - Clear the security blob for sem
3102 * @sma: the object
3103 *
3104 * Clears the blob pointer
3105 */
3106static void smack_sem_free_security(struct kern_ipc_perm *sma)
3107{
3108 struct kern_ipc_perm *isp = sma;
3109
3110 isp->security = NULL;
3111} 3069}
3112 3070
3113/** 3071/**
3114 * smk_curacc_sem : check if current has access on sem 3072 * smk_curacc_sem : check if current has access on sem
3115 * @sma : the object 3073 * @isp : the object
3116 * @access : access requested 3074 * @access : access requested
3117 * 3075 *
3118 * Returns 0 if current has the requested access, error code otherwise 3076 * Returns 0 if current has the requested access, error code otherwise
3119 */ 3077 */
3120static int smk_curacc_sem(struct kern_ipc_perm *sma, int access) 3078static int smk_curacc_sem(struct kern_ipc_perm *isp, int access)
3121{ 3079{
3122 struct smack_known *ssp = smack_of_sem(sma); 3080 struct smack_known *ssp = smack_of_ipc(isp);
3123 struct smk_audit_info ad; 3081 struct smk_audit_info ad;
3124 int rc; 3082 int rc;
3125 3083
3126#ifdef CONFIG_AUDIT 3084#ifdef CONFIG_AUDIT
3127 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC); 3085 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
3128 ad.a.u.ipc_id = sma->id; 3086 ad.a.u.ipc_id = isp->id;
3129#endif 3087#endif
3130 rc = smk_curacc(ssp, access, &ad); 3088 rc = smk_curacc(ssp, access, &ad);
3131 rc = smk_bu_current("sem", ssp, access, rc); 3089 rc = smk_bu_current("sem", ssp, access, rc);
@@ -3134,27 +3092,27 @@ static int smk_curacc_sem(struct kern_ipc_perm *sma, int access)
3134 3092
3135/** 3093/**
3136 * smack_sem_associate - Smack access check for sem 3094 * smack_sem_associate - Smack access check for sem
3137 * @sma: the object 3095 * @isp: the object
3138 * @semflg: access requested 3096 * @semflg: access requested
3139 * 3097 *
3140 * Returns 0 if current has the requested access, error code otherwise 3098 * Returns 0 if current has the requested access, error code otherwise
3141 */ 3099 */
3142static int smack_sem_associate(struct kern_ipc_perm *sma, int semflg) 3100static int smack_sem_associate(struct kern_ipc_perm *isp, int semflg)
3143{ 3101{
3144 int may; 3102 int may;
3145 3103
3146 may = smack_flags_to_may(semflg); 3104 may = smack_flags_to_may(semflg);
3147 return smk_curacc_sem(sma, may); 3105 return smk_curacc_sem(isp, may);
3148} 3106}
3149 3107
3150/** 3108/**
3151 * smack_sem_shmctl - Smack access check for sem 3109 * smack_sem_shmctl - Smack access check for sem
3152 * @sma: the object 3110 * @isp: the object
3153 * @cmd: what it wants to do 3111 * @cmd: what it wants to do
3154 * 3112 *
3155 * Returns 0 if current has the requested access, error code otherwise 3113 * Returns 0 if current has the requested access, error code otherwise
3156 */ 3114 */
3157static int smack_sem_semctl(struct kern_ipc_perm *sma, int cmd) 3115static int smack_sem_semctl(struct kern_ipc_perm *isp, int cmd)
3158{ 3116{
3159 int may; 3117 int may;
3160 3118
@@ -3184,12 +3142,12 @@ static int smack_sem_semctl(struct kern_ipc_perm *sma, int cmd)
3184 return -EINVAL; 3142 return -EINVAL;
3185 } 3143 }
3186 3144
3187 return smk_curacc_sem(sma, may); 3145 return smk_curacc_sem(isp, may);
3188} 3146}
3189 3147
3190/** 3148/**
3191 * smack_sem_semop - Smack checks of semaphore operations 3149 * smack_sem_semop - Smack checks of semaphore operations
3192 * @sma: the object 3150 * @isp: the object
3193 * @sops: unused 3151 * @sops: unused
3194 * @nsops: unused 3152 * @nsops: unused
3195 * @alter: unused 3153 * @alter: unused
@@ -3198,67 +3156,28 @@ static int smack_sem_semctl(struct kern_ipc_perm *sma, int cmd)
3198 * 3156 *
3199 * Returns 0 if access is allowed, error code otherwise 3157 * Returns 0 if access is allowed, error code otherwise
3200 */ 3158 */
3201static int smack_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, 3159static int smack_sem_semop(struct kern_ipc_perm *isp, struct sembuf *sops,
3202 unsigned nsops, int alter) 3160 unsigned nsops, int alter)
3203{ 3161{
3204 return smk_curacc_sem(sma, MAY_READWRITE); 3162 return smk_curacc_sem(isp, MAY_READWRITE);
3205}
3206
3207/**
3208 * smack_msg_alloc_security - Set the security blob for msg
3209 * @msq: the object
3210 *
3211 * Returns 0
3212 */
3213static int smack_msg_queue_alloc_security(struct kern_ipc_perm *msq)
3214{
3215 struct kern_ipc_perm *kisp = msq;
3216 struct smack_known *skp = smk_of_current();
3217
3218 kisp->security = skp;
3219 return 0;
3220}
3221
3222/**
3223 * smack_msg_free_security - Clear the security blob for msg
3224 * @msq: the object
3225 *
3226 * Clears the blob pointer
3227 */
3228static void smack_msg_queue_free_security(struct kern_ipc_perm *msq)
3229{
3230 struct kern_ipc_perm *kisp = msq;
3231
3232 kisp->security = NULL;
3233}
3234
3235/**
3236 * smack_of_msq - the smack pointer for the msq
3237 * @msq: the object
3238 *
3239 * Returns a pointer to the smack label entry
3240 */
3241static struct smack_known *smack_of_msq(struct kern_ipc_perm *msq)
3242{
3243 return (struct smack_known *)msq->security;
3244} 3163}
3245 3164
3246/** 3165/**
3247 * smk_curacc_msq : helper to check if current has access on msq 3166 * smk_curacc_msq : helper to check if current has access on msq
3248 * @msq : the msq 3167 * @isp : the msq
3249 * @access : access requested 3168 * @access : access requested
3250 * 3169 *
3251 * return 0 if current has access, error otherwise 3170 * return 0 if current has access, error otherwise
3252 */ 3171 */
3253static int smk_curacc_msq(struct kern_ipc_perm *msq, int access) 3172static int smk_curacc_msq(struct kern_ipc_perm *isp, int access)
3254{ 3173{
3255 struct smack_known *msp = smack_of_msq(msq); 3174 struct smack_known *msp = smack_of_ipc(isp);
3256 struct smk_audit_info ad; 3175 struct smk_audit_info ad;
3257 int rc; 3176 int rc;
3258 3177
3259#ifdef CONFIG_AUDIT 3178#ifdef CONFIG_AUDIT
3260 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC); 3179 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
3261 ad.a.u.ipc_id = msq->id; 3180 ad.a.u.ipc_id = isp->id;
3262#endif 3181#endif
3263 rc = smk_curacc(msp, access, &ad); 3182 rc = smk_curacc(msp, access, &ad);
3264 rc = smk_bu_current("msq", msp, access, rc); 3183 rc = smk_bu_current("msq", msp, access, rc);
@@ -3267,27 +3186,27 @@ static int smk_curacc_msq(struct kern_ipc_perm *msq, int access)
3267 3186
3268/** 3187/**
3269 * smack_msg_queue_associate - Smack access check for msg_queue 3188 * smack_msg_queue_associate - Smack access check for msg_queue
3270 * @msq: the object 3189 * @isp: the object
3271 * @msqflg: access requested 3190 * @msqflg: access requested
3272 * 3191 *
3273 * Returns 0 if current has the requested access, error code otherwise 3192 * Returns 0 if current has the requested access, error code otherwise
3274 */ 3193 */
3275static int smack_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg) 3194static int smack_msg_queue_associate(struct kern_ipc_perm *isp, int msqflg)
3276{ 3195{
3277 int may; 3196 int may;
3278 3197
3279 may = smack_flags_to_may(msqflg); 3198 may = smack_flags_to_may(msqflg);
3280 return smk_curacc_msq(msq, may); 3199 return smk_curacc_msq(isp, may);
3281} 3200}
3282 3201
3283/** 3202/**
3284 * smack_msg_queue_msgctl - Smack access check for msg_queue 3203 * smack_msg_queue_msgctl - Smack access check for msg_queue
3285 * @msq: the object 3204 * @isp: the object
3286 * @cmd: what it wants to do 3205 * @cmd: what it wants to do
3287 * 3206 *
3288 * Returns 0 if current has the requested access, error code otherwise 3207 * Returns 0 if current has the requested access, error code otherwise
3289 */ 3208 */
3290static int smack_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd) 3209static int smack_msg_queue_msgctl(struct kern_ipc_perm *isp, int cmd)
3291{ 3210{
3292 int may; 3211 int may;
3293 3212
@@ -3310,29 +3229,29 @@ static int smack_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
3310 return -EINVAL; 3229 return -EINVAL;
3311 } 3230 }
3312 3231
3313 return smk_curacc_msq(msq, may); 3232 return smk_curacc_msq(isp, may);
3314} 3233}
3315 3234
3316/** 3235/**
3317 * smack_msg_queue_msgsnd - Smack access check for msg_queue 3236 * smack_msg_queue_msgsnd - Smack access check for msg_queue
3318 * @msq: the object 3237 * @isp: the object
3319 * @msg: unused 3238 * @msg: unused
3320 * @msqflg: access requested 3239 * @msqflg: access requested
3321 * 3240 *
3322 * Returns 0 if current has the requested access, error code otherwise 3241 * Returns 0 if current has the requested access, error code otherwise
3323 */ 3242 */
3324static int smack_msg_queue_msgsnd(struct kern_ipc_perm *msq, struct msg_msg *msg, 3243static int smack_msg_queue_msgsnd(struct kern_ipc_perm *isp, struct msg_msg *msg,
3325 int msqflg) 3244 int msqflg)
3326{ 3245{
3327 int may; 3246 int may;
3328 3247
3329 may = smack_flags_to_may(msqflg); 3248 may = smack_flags_to_may(msqflg);
3330 return smk_curacc_msq(msq, may); 3249 return smk_curacc_msq(isp, may);
3331} 3250}
3332 3251
3333/** 3252/**
3334 * smack_msg_queue_msgsnd - Smack access check for msg_queue 3253 * smack_msg_queue_msgsnd - Smack access check for msg_queue
3335 * @msq: the object 3254 * @isp: the object
3336 * @msg: unused 3255 * @msg: unused
3337 * @target: unused 3256 * @target: unused
3338 * @type: unused 3257 * @type: unused
@@ -3340,10 +3259,10 @@ static int smack_msg_queue_msgsnd(struct kern_ipc_perm *msq, struct msg_msg *msg
3340 * 3259 *
3341 * Returns 0 if current has read and write access, error code otherwise 3260 * Returns 0 if current has read and write access, error code otherwise
3342 */ 3261 */
3343static int smack_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg, 3262static int smack_msg_queue_msgrcv(struct kern_ipc_perm *isp, struct msg_msg *msg,
3344 struct task_struct *target, long type, int mode) 3263 struct task_struct *target, long type, int mode)
3345{ 3264{
3346 return smk_curacc_msq(msq, MAY_READWRITE); 3265 return smk_curacc_msq(isp, MAY_READWRITE);
3347} 3266}
3348 3267
3349/** 3268/**
@@ -4756,21 +4675,21 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
4756 LSM_HOOK_INIT(msg_msg_alloc_security, smack_msg_msg_alloc_security), 4675 LSM_HOOK_INIT(msg_msg_alloc_security, smack_msg_msg_alloc_security),
4757 LSM_HOOK_INIT(msg_msg_free_security, smack_msg_msg_free_security), 4676 LSM_HOOK_INIT(msg_msg_free_security, smack_msg_msg_free_security),
4758 4677
4759 LSM_HOOK_INIT(msg_queue_alloc_security, smack_msg_queue_alloc_security), 4678 LSM_HOOK_INIT(msg_queue_alloc_security, smack_ipc_alloc_security),
4760 LSM_HOOK_INIT(msg_queue_free_security, smack_msg_queue_free_security), 4679 LSM_HOOK_INIT(msg_queue_free_security, smack_ipc_free_security),
4761 LSM_HOOK_INIT(msg_queue_associate, smack_msg_queue_associate), 4680 LSM_HOOK_INIT(msg_queue_associate, smack_msg_queue_associate),
4762 LSM_HOOK_INIT(msg_queue_msgctl, smack_msg_queue_msgctl), 4681 LSM_HOOK_INIT(msg_queue_msgctl, smack_msg_queue_msgctl),
4763 LSM_HOOK_INIT(msg_queue_msgsnd, smack_msg_queue_msgsnd), 4682 LSM_HOOK_INIT(msg_queue_msgsnd, smack_msg_queue_msgsnd),
4764 LSM_HOOK_INIT(msg_queue_msgrcv, smack_msg_queue_msgrcv), 4683 LSM_HOOK_INIT(msg_queue_msgrcv, smack_msg_queue_msgrcv),
4765 4684
4766 LSM_HOOK_INIT(shm_alloc_security, smack_shm_alloc_security), 4685 LSM_HOOK_INIT(shm_alloc_security, smack_ipc_alloc_security),
4767 LSM_HOOK_INIT(shm_free_security, smack_shm_free_security), 4686 LSM_HOOK_INIT(shm_free_security, smack_ipc_free_security),
4768 LSM_HOOK_INIT(shm_associate, smack_shm_associate), 4687 LSM_HOOK_INIT(shm_associate, smack_shm_associate),
4769 LSM_HOOK_INIT(shm_shmctl, smack_shm_shmctl), 4688 LSM_HOOK_INIT(shm_shmctl, smack_shm_shmctl),
4770 LSM_HOOK_INIT(shm_shmat, smack_shm_shmat), 4689 LSM_HOOK_INIT(shm_shmat, smack_shm_shmat),
4771 4690
4772 LSM_HOOK_INIT(sem_alloc_security, smack_sem_alloc_security), 4691 LSM_HOOK_INIT(sem_alloc_security, smack_ipc_alloc_security),
4773 LSM_HOOK_INIT(sem_free_security, smack_sem_free_security), 4692 LSM_HOOK_INIT(sem_free_security, smack_ipc_free_security),
4774 LSM_HOOK_INIT(sem_associate, smack_sem_associate), 4693 LSM_HOOK_INIT(sem_associate, smack_sem_associate),
4775 LSM_HOOK_INIT(sem_semctl, smack_sem_semctl), 4694 LSM_HOOK_INIT(sem_semctl, smack_sem_semctl),
4776 LSM_HOOK_INIT(sem_semop, smack_sem_semop), 4695 LSM_HOOK_INIT(sem_semop, smack_sem_semop),