diff options
| author | Davidlohr Bueso <dave@stgolabs.net> | 2015-06-30 17:58:36 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-30 22:44:58 -0400 |
| commit | c5c8975b2eb4eb7604e8ce4f762987f56d2a96a2 (patch) | |
| tree | 9f21ef2539c3c0110dde47e1fc6b56c50da8b507 | |
| parent | c859aa83113dcad165d986e66aa21c5b73745f42 (diff) | |
ipc,shm: move BUG_ON check into shm_lock
Upon every shm_lock call, we BUG_ON if an error was returned, indicating
racing either in idr or in shm_destroy. Move this logic into the locking.
[akpm@linux-foundation.org: simplify code]
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | ipc/shm.c | 10 |
1 files changed, 5 insertions, 5 deletions
| @@ -155,8 +155,11 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) | |||
| 155 | { | 155 | { |
| 156 | struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); | 156 | struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); |
| 157 | 157 | ||
| 158 | if (IS_ERR(ipcp)) | 158 | /* |
| 159 | return (struct shmid_kernel *)ipcp; | 159 | * We raced in the idr lookup or with shm_destroy(). Either way, the |
| 160 | * ID is busted. | ||
| 161 | */ | ||
| 162 | BUG_ON(IS_ERR(ipcp)); | ||
| 160 | 163 | ||
| 161 | return container_of(ipcp, struct shmid_kernel, shm_perm); | 164 | return container_of(ipcp, struct shmid_kernel, shm_perm); |
| 162 | } | 165 | } |
| @@ -191,7 +194,6 @@ static void shm_open(struct vm_area_struct *vma) | |||
| 191 | struct shmid_kernel *shp; | 194 | struct shmid_kernel *shp; |
| 192 | 195 | ||
| 193 | shp = shm_lock(sfd->ns, sfd->id); | 196 | shp = shm_lock(sfd->ns, sfd->id); |
| 194 | BUG_ON(IS_ERR(shp)); | ||
| 195 | shp->shm_atim = get_seconds(); | 197 | shp->shm_atim = get_seconds(); |
| 196 | shp->shm_lprid = task_tgid_vnr(current); | 198 | shp->shm_lprid = task_tgid_vnr(current); |
| 197 | shp->shm_nattch++; | 199 | shp->shm_nattch++; |
| @@ -258,7 +260,6 @@ static void shm_close(struct vm_area_struct *vma) | |||
| 258 | down_write(&shm_ids(ns).rwsem); | 260 | down_write(&shm_ids(ns).rwsem); |
| 259 | /* remove from the list of attaches of the shm segment */ | 261 | /* remove from the list of attaches of the shm segment */ |
| 260 | shp = shm_lock(ns, sfd->id); | 262 | shp = shm_lock(ns, sfd->id); |
| 261 | BUG_ON(IS_ERR(shp)); | ||
| 262 | shp->shm_lprid = task_tgid_vnr(current); | 263 | shp->shm_lprid = task_tgid_vnr(current); |
| 263 | shp->shm_dtim = get_seconds(); | 264 | shp->shm_dtim = get_seconds(); |
| 264 | shp->shm_nattch--; | 265 | shp->shm_nattch--; |
| @@ -1191,7 +1192,6 @@ out_fput: | |||
| 1191 | out_nattch: | 1192 | out_nattch: |
| 1192 | down_write(&shm_ids(ns).rwsem); | 1193 | down_write(&shm_ids(ns).rwsem); |
| 1193 | shp = shm_lock(ns, shmid); | 1194 | shp = shm_lock(ns, shmid); |
| 1194 | BUG_ON(IS_ERR(shp)); | ||
| 1195 | shp->shm_nattch--; | 1195 | shp->shm_nattch--; |
| 1196 | if (shm_may_destroy(ns, shp)) | 1196 | if (shm_may_destroy(ns, shp)) |
| 1197 | shm_destroy(ns, shp); | 1197 | shm_destroy(ns, shp); |
