Skip to content

Commit

Permalink
shm: fix shmctl(SHM_INFO) lockup with !CONFIG_SHMEM
Browse files Browse the repository at this point in the history
shm_get_stat() assumes that the inode is a "struct shmem_inode_info",
which is incorrect for !CONFIG_SHMEM (see fs/ramfs/inode.c:
ramfs_get_inode() vs.  mm/shmem.c: shmem_get_inode()).

This bad assumption can cause shmctl(SHM_INFO) to lockup when
shm_get_stat() tries to spin_lock(&info->lock).  Users of !CONFIG_SHMEM
may encounter this lockup simply by invoking the 'ipcs' command.

Reported by Jiri Olsa back in February 2008:
http://lkml.org/lkml/2008/2/29/74

Signed-off-by: Tony Battersby <[email protected]>
Cc: Jiri Kosina <[email protected]>
Reported-by: Jiri Olsa <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: <[email protected]>		[2.6.everything]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
abattersby authored and torvalds committed Feb 5, 2009
1 parent 1f5e31d commit a68e61e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,15 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
struct hstate *h = hstate_file(shp->shm_file);
*rss += pages_per_huge_page(h) * mapping->nrpages;
} else {
#ifdef CONFIG_SHMEM
struct shmem_inode_info *info = SHMEM_I(inode);
spin_lock(&info->lock);
*rss += inode->i_mapping->nrpages;
*swp += info->swapped;
spin_unlock(&info->lock);
#else
*rss += inode->i_mapping->nrpages;
#endif
}

total++;
Expand Down

0 comments on commit a68e61e

Please sign in to comment.