From: Andrew Morton <akpm@linux-foundation.org>
To: Tony Battersby <tonyb@cybernetics.com>
Cc: linux-kernel@vger.kernel.org, olsajiri@gmail.com, jkosina@suse.cz
Subject: Re: [PATCH 2/2] make shm_get_stat() more robust
Date: Tue, 27 Jan 2009 15:00:21 -0800 [thread overview]
Message-ID: <20090127150021.ee417076.akpm@linux-foundation.org> (raw)
In-Reply-To: <497F8F2D.600@cybernetics.com>
On Tue, 27 Jan 2009 17:48:13 -0500
Tony Battersby <tonyb@cybernetics.com> wrote:
> 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;
>
yup, well spotted.
It would be good to add a little typesafe wrapper:
static inline struct kern_ipc_perm *shm_idr_find(struct ipc_ids *ipc_ids)
{
return idr_find(&ipc_ids->ipcs_idr);
}
(or similar)
so that this sort of mistake cannot happen again.
As you've found, open-coded use of a bare void*-returning function is a
bit dangerous.
prev parent reply other threads:[~2009-01-27 23:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-27 22:48 [PATCH 2/2] make shm_get_stat() more robust Tony Battersby
2009-01-27 23:00 ` Andrew Morton [this message]
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=20090127150021.ee417076.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=olsajiri@gmail.com \
--cc=tonyb@cybernetics.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.