diff options
Diffstat (limited to 'ipc/shm.c')
-rw-r--r-- | ipc/shm.c | 41 |
1 files changed, 24 insertions, 17 deletions
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/security.h> | 27 | #include <linux/security.h> |
28 | #include <linux/syscalls.h> | 28 | #include <linux/syscalls.h> |
29 | #include <linux/audit.h> | 29 | #include <linux/audit.h> |
30 | #include <linux/capability.h> | ||
30 | #include <linux/ptrace.h> | 31 | #include <linux/ptrace.h> |
31 | #include <linux/seq_file.h> | 32 | #include <linux/seq_file.h> |
32 | 33 | ||
@@ -34,8 +35,6 @@ | |||
34 | 35 | ||
35 | #include "util.h" | 36 | #include "util.h" |
36 | 37 | ||
37 | #define shm_flags shm_perm.mode | ||
38 | |||
39 | static struct file_operations shm_file_operations; | 38 | static struct file_operations shm_file_operations; |
40 | static struct vm_operations_struct shm_vm_ops; | 39 | static struct vm_operations_struct shm_vm_ops; |
41 | 40 | ||
@@ -148,7 +147,7 @@ static void shm_close (struct vm_area_struct *shmd) | |||
148 | shp->shm_dtim = get_seconds(); | 147 | shp->shm_dtim = get_seconds(); |
149 | shp->shm_nattch--; | 148 | shp->shm_nattch--; |
150 | if(shp->shm_nattch == 0 && | 149 | if(shp->shm_nattch == 0 && |
151 | shp->shm_flags & SHM_DEST) | 150 | shp->shm_perm.mode & SHM_DEST) |
152 | shm_destroy (shp); | 151 | shm_destroy (shp); |
153 | else | 152 | else |
154 | shm_unlock(shp); | 153 | shm_unlock(shp); |
@@ -157,14 +156,22 @@ static void shm_close (struct vm_area_struct *shmd) | |||
157 | 156 | ||
158 | static int shm_mmap(struct file * file, struct vm_area_struct * vma) | 157 | static int shm_mmap(struct file * file, struct vm_area_struct * vma) |
159 | { | 158 | { |
160 | file_accessed(file); | 159 | int ret; |
161 | vma->vm_ops = &shm_vm_ops; | 160 | |
162 | shm_inc(file->f_dentry->d_inode->i_ino); | 161 | ret = shmem_mmap(file, vma); |
163 | return 0; | 162 | if (ret == 0) { |
163 | vma->vm_ops = &shm_vm_ops; | ||
164 | shm_inc(file->f_dentry->d_inode->i_ino); | ||
165 | } | ||
166 | |||
167 | return ret; | ||
164 | } | 168 | } |
165 | 169 | ||
166 | static struct file_operations shm_file_operations = { | 170 | static struct file_operations shm_file_operations = { |
167 | .mmap = shm_mmap | 171 | .mmap = shm_mmap, |
172 | #ifndef CONFIG_MMU | ||
173 | .get_unmapped_area = shmem_get_unmapped_area, | ||
174 | #endif | ||
168 | }; | 175 | }; |
169 | 176 | ||
170 | static struct vm_operations_struct shm_vm_ops = { | 177 | static struct vm_operations_struct shm_vm_ops = { |
@@ -197,7 +204,7 @@ static int newseg (key_t key, int shmflg, size_t size) | |||
197 | return -ENOMEM; | 204 | return -ENOMEM; |
198 | 205 | ||
199 | shp->shm_perm.key = key; | 206 | shp->shm_perm.key = key; |
200 | shp->shm_flags = (shmflg & S_IRWXUGO); | 207 | shp->shm_perm.mode = (shmflg & S_IRWXUGO); |
201 | shp->mlock_user = NULL; | 208 | shp->mlock_user = NULL; |
202 | 209 | ||
203 | shp->shm_perm.security = NULL; | 210 | shp->shm_perm.security = NULL; |
@@ -337,7 +344,7 @@ static inline unsigned long copy_shmid_from_user(struct shm_setbuf *out, void __ | |||
337 | 344 | ||
338 | out->uid = tbuf.shm_perm.uid; | 345 | out->uid = tbuf.shm_perm.uid; |
339 | out->gid = tbuf.shm_perm.gid; | 346 | out->gid = tbuf.shm_perm.gid; |
340 | out->mode = tbuf.shm_flags; | 347 | out->mode = tbuf.shm_perm.mode; |
341 | 348 | ||
342 | return 0; | 349 | return 0; |
343 | } | 350 | } |
@@ -350,7 +357,7 @@ static inline unsigned long copy_shmid_from_user(struct shm_setbuf *out, void __ | |||
350 | 357 | ||
351 | out->uid = tbuf_old.shm_perm.uid; | 358 | out->uid = tbuf_old.shm_perm.uid; |
352 | out->gid = tbuf_old.shm_perm.gid; | 359 | out->gid = tbuf_old.shm_perm.gid; |
353 | out->mode = tbuf_old.shm_flags; | 360 | out->mode = tbuf_old.shm_perm.mode; |
354 | 361 | ||
355 | return 0; | 362 | return 0; |
356 | } | 363 | } |
@@ -552,13 +559,13 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf) | |||
552 | if (!is_file_hugepages(shp->shm_file)) { | 559 | if (!is_file_hugepages(shp->shm_file)) { |
553 | err = shmem_lock(shp->shm_file, 1, user); | 560 | err = shmem_lock(shp->shm_file, 1, user); |
554 | if (!err) { | 561 | if (!err) { |
555 | shp->shm_flags |= SHM_LOCKED; | 562 | shp->shm_perm.mode |= SHM_LOCKED; |
556 | shp->mlock_user = user; | 563 | shp->mlock_user = user; |
557 | } | 564 | } |
558 | } | 565 | } |
559 | } else if (!is_file_hugepages(shp->shm_file)) { | 566 | } else if (!is_file_hugepages(shp->shm_file)) { |
560 | shmem_lock(shp->shm_file, 0, shp->mlock_user); | 567 | shmem_lock(shp->shm_file, 0, shp->mlock_user); |
561 | shp->shm_flags &= ~SHM_LOCKED; | 568 | shp->shm_perm.mode &= ~SHM_LOCKED; |
562 | shp->mlock_user = NULL; | 569 | shp->mlock_user = NULL; |
563 | } | 570 | } |
564 | shm_unlock(shp); | 571 | shm_unlock(shp); |
@@ -597,7 +604,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf) | |||
597 | goto out_unlock_up; | 604 | goto out_unlock_up; |
598 | 605 | ||
599 | if (shp->shm_nattch){ | 606 | if (shp->shm_nattch){ |
600 | shp->shm_flags |= SHM_DEST; | 607 | shp->shm_perm.mode |= SHM_DEST; |
601 | /* Do not find it any more */ | 608 | /* Do not find it any more */ |
602 | shp->shm_perm.key = IPC_PRIVATE; | 609 | shp->shm_perm.key = IPC_PRIVATE; |
603 | shm_unlock(shp); | 610 | shm_unlock(shp); |
@@ -636,7 +643,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf) | |||
636 | 643 | ||
637 | shp->shm_perm.uid = setbuf.uid; | 644 | shp->shm_perm.uid = setbuf.uid; |
638 | shp->shm_perm.gid = setbuf.gid; | 645 | shp->shm_perm.gid = setbuf.gid; |
639 | shp->shm_flags = (shp->shm_flags & ~S_IRWXUGO) | 646 | shp->shm_perm.mode = (shp->shm_perm.mode & ~S_IRWXUGO) |
640 | | (setbuf.mode & S_IRWXUGO); | 647 | | (setbuf.mode & S_IRWXUGO); |
641 | shp->shm_ctim = get_seconds(); | 648 | shp->shm_ctim = get_seconds(); |
642 | break; | 649 | break; |
@@ -769,7 +776,7 @@ invalid: | |||
769 | BUG(); | 776 | BUG(); |
770 | shp->shm_nattch--; | 777 | shp->shm_nattch--; |
771 | if(shp->shm_nattch == 0 && | 778 | if(shp->shm_nattch == 0 && |
772 | shp->shm_flags & SHM_DEST) | 779 | shp->shm_perm.mode & SHM_DEST) |
773 | shm_destroy (shp); | 780 | shm_destroy (shp); |
774 | else | 781 | else |
775 | shm_unlock(shp); | 782 | shm_unlock(shp); |
@@ -894,7 +901,7 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it) | |||
894 | return seq_printf(s, format, | 901 | return seq_printf(s, format, |
895 | shp->shm_perm.key, | 902 | shp->shm_perm.key, |
896 | shp->id, | 903 | shp->id, |
897 | shp->shm_flags, | 904 | shp->shm_perm.mode, |
898 | shp->shm_segsz, | 905 | shp->shm_segsz, |
899 | shp->shm_cprid, | 906 | shp->shm_cprid, |
900 | shp->shm_lprid, | 907 | shp->shm_lprid, |