diff options
Diffstat (limited to 'ipc/shm.c')
| -rw-r--r-- | ipc/shm.c | 48 |
1 files changed, 27 insertions, 21 deletions
| @@ -75,7 +75,7 @@ void shm_init_ns(struct ipc_namespace *ns) | |||
| 75 | ns->shm_ctlall = SHMALL; | 75 | ns->shm_ctlall = SHMALL; |
| 76 | ns->shm_ctlmni = SHMMNI; | 76 | ns->shm_ctlmni = SHMMNI; |
| 77 | ns->shm_tot = 0; | 77 | ns->shm_tot = 0; |
| 78 | ipc_init_ids(&ns->ids[IPC_SHM_IDS]); | 78 | ipc_init_ids(&shm_ids(ns)); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | /* | 81 | /* |
| @@ -366,7 +366,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) | |||
| 366 | if (shmflg & SHM_HUGETLB) { | 366 | if (shmflg & SHM_HUGETLB) { |
| 367 | /* hugetlb_file_setup takes care of mlock user accounting */ | 367 | /* hugetlb_file_setup takes care of mlock user accounting */ |
| 368 | file = hugetlb_file_setup(name, size); | 368 | file = hugetlb_file_setup(name, size); |
| 369 | shp->mlock_user = current->user; | 369 | shp->mlock_user = current_user(); |
| 370 | } else { | 370 | } else { |
| 371 | int acctflag = VM_ACCOUNT; | 371 | int acctflag = VM_ACCOUNT; |
| 372 | /* | 372 | /* |
| @@ -440,7 +440,7 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp, | |||
| 440 | return 0; | 440 | return 0; |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | asmlinkage long sys_shmget (key_t key, size_t size, int shmflg) | 443 | SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg) |
| 444 | { | 444 | { |
| 445 | struct ipc_namespace *ns; | 445 | struct ipc_namespace *ns; |
| 446 | struct ipc_ops shm_ops; | 446 | struct ipc_ops shm_ops; |
| @@ -621,7 +621,7 @@ out_up: | |||
| 621 | return err; | 621 | return err; |
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | 624 | SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf) |
| 625 | { | 625 | { |
| 626 | struct shmid_kernel *shp; | 626 | struct shmid_kernel *shp; |
| 627 | int err, version; | 627 | int err, version; |
| @@ -644,7 +644,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 644 | if (err) | 644 | if (err) |
| 645 | return err; | 645 | return err; |
| 646 | 646 | ||
| 647 | memset(&shminfo,0,sizeof(shminfo)); | 647 | memset(&shminfo, 0, sizeof(shminfo)); |
| 648 | shminfo.shmmni = shminfo.shmseg = ns->shm_ctlmni; | 648 | shminfo.shmmni = shminfo.shmseg = ns->shm_ctlmni; |
| 649 | shminfo.shmmax = ns->shm_ctlmax; | 649 | shminfo.shmmax = ns->shm_ctlmax; |
| 650 | shminfo.shmall = ns->shm_ctlall; | 650 | shminfo.shmall = ns->shm_ctlall; |
| @@ -669,7 +669,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 669 | if (err) | 669 | if (err) |
| 670 | return err; | 670 | return err; |
| 671 | 671 | ||
| 672 | memset(&shm_info,0,sizeof(shm_info)); | 672 | memset(&shm_info, 0, sizeof(shm_info)); |
| 673 | down_read(&shm_ids(ns).rw_mutex); | 673 | down_read(&shm_ids(ns).rw_mutex); |
| 674 | shm_info.used_ids = shm_ids(ns).in_use; | 674 | shm_info.used_ids = shm_ids(ns).in_use; |
| 675 | shm_get_stat (ns, &shm_info.shm_rss, &shm_info.shm_swp); | 675 | shm_get_stat (ns, &shm_info.shm_rss, &shm_info.shm_swp); |
| @@ -678,7 +678,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 678 | shm_info.swap_successes = 0; | 678 | shm_info.swap_successes = 0; |
| 679 | err = ipc_get_maxid(&shm_ids(ns)); | 679 | err = ipc_get_maxid(&shm_ids(ns)); |
| 680 | up_read(&shm_ids(ns).rw_mutex); | 680 | up_read(&shm_ids(ns).rw_mutex); |
| 681 | if(copy_to_user (buf, &shm_info, sizeof(shm_info))) { | 681 | if (copy_to_user(buf, &shm_info, sizeof(shm_info))) { |
| 682 | err = -EFAULT; | 682 | err = -EFAULT; |
| 683 | goto out; | 683 | goto out; |
| 684 | } | 684 | } |
| @@ -692,11 +692,6 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 692 | struct shmid64_ds tbuf; | 692 | struct shmid64_ds tbuf; |
| 693 | int result; | 693 | int result; |
| 694 | 694 | ||
| 695 | if (!buf) { | ||
| 696 | err = -EFAULT; | ||
| 697 | goto out; | ||
| 698 | } | ||
| 699 | |||
| 700 | if (cmd == SHM_STAT) { | 695 | if (cmd == SHM_STAT) { |
| 701 | shp = shm_lock(ns, shmid); | 696 | shp = shm_lock(ns, shmid); |
| 702 | if (IS_ERR(shp)) { | 697 | if (IS_ERR(shp)) { |
| @@ -712,7 +707,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 712 | } | 707 | } |
| 713 | result = 0; | 708 | result = 0; |
| 714 | } | 709 | } |
| 715 | err=-EACCES; | 710 | err = -EACCES; |
| 716 | if (ipcperms (&shp->shm_perm, S_IRUGO)) | 711 | if (ipcperms (&shp->shm_perm, S_IRUGO)) |
| 717 | goto out_unlock; | 712 | goto out_unlock; |
| 718 | err = security_shm_shmctl(shp, cmd); | 713 | err = security_shm_shmctl(shp, cmd); |
| @@ -747,14 +742,13 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 747 | goto out; | 742 | goto out; |
| 748 | } | 743 | } |
| 749 | 744 | ||
| 750 | err = audit_ipc_obj(&(shp->shm_perm)); | 745 | audit_ipc_obj(&(shp->shm_perm)); |
| 751 | if (err) | ||
| 752 | goto out_unlock; | ||
| 753 | 746 | ||
| 754 | if (!capable(CAP_IPC_LOCK)) { | 747 | if (!capable(CAP_IPC_LOCK)) { |
| 748 | uid_t euid = current_euid(); | ||
| 755 | err = -EPERM; | 749 | err = -EPERM; |
| 756 | if (current->euid != shp->shm_perm.uid && | 750 | if (euid != shp->shm_perm.uid && |
| 757 | current->euid != shp->shm_perm.cuid) | 751 | euid != shp->shm_perm.cuid) |
| 758 | goto out_unlock; | 752 | goto out_unlock; |
| 759 | if (cmd == SHM_LOCK && | 753 | if (cmd == SHM_LOCK && |
| 760 | !current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur) | 754 | !current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur) |
| @@ -766,7 +760,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf) | |||
| 766 | goto out_unlock; | 760 | goto out_unlock; |
| 767 | 761 | ||
| 768 | if(cmd==SHM_LOCK) { | 762 | if(cmd==SHM_LOCK) { |
| 769 | struct user_struct * user = current->user; | 763 | struct user_struct *user = current_user(); |
| 770 | if (!is_file_hugepages(shp->shm_file)) { | 764 | if (!is_file_hugepages(shp->shm_file)) { |
| 771 | err = shmem_lock(shp->shm_file, 1, user); | 765 | err = shmem_lock(shp->shm_file, 1, user); |
| 772 | if (!err && !(shp->shm_perm.mode & SHM_LOCKED)){ | 766 | if (!err && !(shp->shm_perm.mode & SHM_LOCKED)){ |
| @@ -945,7 +939,7 @@ out_put_dentry: | |||
| 945 | goto out_nattch; | 939 | goto out_nattch; |
| 946 | } | 940 | } |
| 947 | 941 | ||
| 948 | asmlinkage long sys_shmat(int shmid, char __user *shmaddr, int shmflg) | 942 | SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg) |
| 949 | { | 943 | { |
| 950 | unsigned long ret; | 944 | unsigned long ret; |
| 951 | long err; | 945 | long err; |
| @@ -961,7 +955,7 @@ asmlinkage long sys_shmat(int shmid, char __user *shmaddr, int shmflg) | |||
| 961 | * detach and kill segment if marked destroyed. | 955 | * detach and kill segment if marked destroyed. |
| 962 | * The work is done in shm_close. | 956 | * The work is done in shm_close. |
| 963 | */ | 957 | */ |
| 964 | asmlinkage long sys_shmdt(char __user *shmaddr) | 958 | SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) |
| 965 | { | 959 | { |
| 966 | struct mm_struct *mm = current->mm; | 960 | struct mm_struct *mm = current->mm; |
| 967 | struct vm_area_struct *vma, *next; | 961 | struct vm_area_struct *vma, *next; |
| @@ -996,6 +990,7 @@ asmlinkage long sys_shmdt(char __user *shmaddr) | |||
| 996 | */ | 990 | */ |
| 997 | vma = find_vma(mm, addr); | 991 | vma = find_vma(mm, addr); |
| 998 | 992 | ||
| 993 | #ifdef CONFIG_MMU | ||
| 999 | while (vma) { | 994 | while (vma) { |
| 1000 | next = vma->vm_next; | 995 | next = vma->vm_next; |
| 1001 | 996 | ||
| @@ -1040,6 +1035,17 @@ asmlinkage long sys_shmdt(char __user *shmaddr) | |||
| 1040 | vma = next; | 1035 | vma = next; |
| 1041 | } | 1036 | } |
| 1042 | 1037 | ||
| 1038 | #else /* CONFIG_MMU */ | ||
| 1039 | /* under NOMMU conditions, the exact address to be destroyed must be | ||
| 1040 | * given */ | ||
| 1041 | retval = -EINVAL; | ||
| 1042 | if (vma->vm_start == addr && vma->vm_ops == &shm_vm_ops) { | ||
| 1043 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); | ||
| 1044 | retval = 0; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | #endif | ||
| 1048 | |||
| 1043 | up_write(&mm->mmap_sem); | 1049 | up_write(&mm->mmap_sem); |
| 1044 | return retval; | 1050 | return retval; |
| 1045 | } | 1051 | } |
