All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Battersby <tonyb@cybernetics.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <olsajiri@gmail.com>, Jiri Kosina <jkosina@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 2/2] make shm_get_stat() more robust
Date: Tue, 27 Jan 2009 17:48:13 -0500	[thread overview]
Message-ID: <497F8F2D.600@cybernetics.com> (raw)

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 <tonyb@cybernetics.com>
---
--- linux-2.6.29-rc2-git3/ipc/shm.c.orig	2009-01-27 16:23:10.000000000 -0500
+++ linux-2.6.29-rc2-git3/ipc/shm.c	2009-01-27 16:24:19.000000000 -0500
@@ -551,12 +551,14 @@ static void shm_get_stat(struct ipc_name
 	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;
 




             reply	other threads:[~2009-01-27 22:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-27 22:48 Tony Battersby [this message]
2009-01-27 23:00 ` [PATCH 2/2] make shm_get_stat() more robust Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=497F8F2D.600@cybernetics.com \
    --to=tonyb@cybernetics.com \
    --cc=akpm@linux-foundation.org \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olsajiri@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.