diff options
Diffstat (limited to 'ipc/util.c')
-rw-r--r-- | ipc/util.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/ipc/util.c b/ipc/util.c index 361fd1c96fcf..5a1808c774a2 100644 --- a/ipc/util.c +++ b/ipc/util.c | |||
@@ -258,6 +258,8 @@ int ipc_get_maxid(struct ipc_ids *ids) | |||
258 | 258 | ||
259 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) | 259 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) |
260 | { | 260 | { |
261 | uid_t euid; | ||
262 | gid_t egid; | ||
261 | int id, err; | 263 | int id, err; |
262 | 264 | ||
263 | if (size > IPCMNI) | 265 | if (size > IPCMNI) |
@@ -280,8 +282,9 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) | |||
280 | 282 | ||
281 | ids->in_use++; | 283 | ids->in_use++; |
282 | 284 | ||
283 | new->cuid = new->uid = current->euid; | 285 | current_euid_egid(&euid, &egid); |
284 | new->gid = new->cgid = current->egid; | 286 | new->cuid = new->uid = euid; |
287 | new->gid = new->cgid = egid; | ||
285 | 288 | ||
286 | new->seq = ids->seq++; | 289 | new->seq = ids->seq++; |
287 | if(ids->seq > ids->seq_max) | 290 | if(ids->seq > ids->seq_max) |
@@ -620,13 +623,15 @@ void ipc_rcu_putref(void *ptr) | |||
620 | 623 | ||
621 | int ipcperms (struct kern_ipc_perm *ipcp, short flag) | 624 | int ipcperms (struct kern_ipc_perm *ipcp, short flag) |
622 | { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */ | 625 | { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */ |
626 | uid_t euid = current_euid(); | ||
623 | int requested_mode, granted_mode, err; | 627 | int requested_mode, granted_mode, err; |
624 | 628 | ||
625 | if (unlikely((err = audit_ipc_obj(ipcp)))) | 629 | if (unlikely((err = audit_ipc_obj(ipcp)))) |
626 | return err; | 630 | return err; |
627 | requested_mode = (flag >> 6) | (flag >> 3) | flag; | 631 | requested_mode = (flag >> 6) | (flag >> 3) | flag; |
628 | granted_mode = ipcp->mode; | 632 | granted_mode = ipcp->mode; |
629 | if (current->euid == ipcp->cuid || current->euid == ipcp->uid) | 633 | if (euid == ipcp->cuid || |
634 | euid == ipcp->uid) | ||
630 | granted_mode >>= 6; | 635 | granted_mode >>= 6; |
631 | else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid)) | 636 | else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid)) |
632 | granted_mode >>= 3; | 637 | granted_mode >>= 3; |
@@ -788,6 +793,7 @@ struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd, | |||
788 | struct ipc64_perm *perm, int extra_perm) | 793 | struct ipc64_perm *perm, int extra_perm) |
789 | { | 794 | { |
790 | struct kern_ipc_perm *ipcp; | 795 | struct kern_ipc_perm *ipcp; |
796 | uid_t euid; | ||
791 | int err; | 797 | int err; |
792 | 798 | ||
793 | down_write(&ids->rw_mutex); | 799 | down_write(&ids->rw_mutex); |
@@ -807,8 +813,10 @@ struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd, | |||
807 | if (err) | 813 | if (err) |
808 | goto out_unlock; | 814 | goto out_unlock; |
809 | } | 815 | } |
810 | if (current->euid == ipcp->cuid || | 816 | |
811 | current->euid == ipcp->uid || capable(CAP_SYS_ADMIN)) | 817 | euid = current_euid(); |
818 | if (euid == ipcp->cuid || | ||
819 | euid == ipcp->uid || capable(CAP_SYS_ADMIN)) | ||
812 | return ipcp; | 820 | return ipcp; |
813 | 821 | ||
814 | err = -EPERM; | 822 | err = -EPERM; |