Skip to content

Commit

Permalink
ipc: make shm_get_stat() more robust
Browse files Browse the repository at this point in the history
shm_get_stat() assumes idr_find(&shm_ids(ns).ipcs_idr) returns "struct
shmid_kernel *"; all other callers assume that it returns "struct
kern_ipc_perm *".  This works because "struct kern_ipc_perm" is currently
the first member of "struct shmid_kernel", but it would be better to use
container_of() to prevent future breakage.

Signed-off-by: Tony Battersby <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Jiri Kosina <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
abattersby authored and torvalds committed Apr 3, 2009
1 parent 40e8a10 commit e562aeb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,14 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
in_use = shm_ids(ns).in_use;

for (total = 0, next_id = 0; total < in_use; next_id++) {
struct kern_ipc_perm *ipc;
struct shmid_kernel *shp;
struct inode *inode;

shp = idr_find(&shm_ids(ns).ipcs_idr, next_id);
if (shp == NULL)
ipc = idr_find(&shm_ids(ns).ipcs_idr, next_id);
if (ipc == NULL)
continue;
shp = container_of(ipc, struct shmid_kernel, shm_perm);

inode = shp->shm_file->f_path.dentry->d_inode;

Expand Down

0 comments on commit e562aeb

Please sign in to comment.