From: Andrew Morton <akpm@linux-foundation.org>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: Arjan van de Ven <arjan@infradead.org>,
adobriyan@gmail.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Karsten Keil <kkeil@suse.de>,
Samuel Ortiz <samuel@sortiz.org>,
Chris Mason <chris.mason@oracle.com>,
Steven Whitehouse <swhiteho@redhat.com>,
Trond Myklebust <trond.myklebust@fys.uio.no>
Subject: Re: [PATCH -v2] memdup_user(): introduce
Date: Sun, 8 Mar 2009 20:45:35 -0700 [thread overview]
Message-ID: <20090308204535.8a2af3fa.akpm@linux-foundation.org> (raw)
In-Reply-To: <49B48D4A.6000207@cn.fujitsu.com>
On Mon, 09 Mar 2009 11:30:18 +0800 Li Zefan <lizf@cn.fujitsu.com> wrote:
> Andrew Morton wrote:
> > On Mon, 09 Mar 2009 10:22:08 +0800 Li Zefan <lizf@cn.fujitsu.com> wrote:
> >
> >>>>> +EXPORT_SYMBOL(memdup_user);
> >>> Hi,
> >>>
> >>> I like the general idea of this a lot; it will make things much less
> >>> error prone (and we can add some sanity checks on "len" to catch the
> >>> standard security holes around copy_from_user usage). I'd even also
> >>> want a memdup_array() like thing in the style of calloc().
> >>>
> >>> However, I have two questions/suggestions for improvement:
> >>>
> >>> I would like to question the use of the gfp argument here;
> >>> copy_from_user sleeps, so you can't use GFP_ATOMIC anyway.
> >>> You can't use GFP_NOFS etc, because the pagefault path will happily do
> >>> things that are equivalent, if not identical, to GFP_KERNEL.
> >>>
> >>> So the only value you can pass in correctly, as far as I can see, is
> >>> GFP_KERNEL. Am I wrong?
> >>>
> >> Right! I just dug and found a few kmalloc(GFP_ATOMIC/GFP_NOFS)+copy_from_user(),
> >> so we have one more reason to use this memdup_user().
> >
> > gack, those callsites are probably buggy. Where are they?
> >
>
> Yes, either buggy or should use GFP_KERNEL.
>
> All are in -mm only, except the first one:
>
> drivers/isdn/i4l/isdn_common.c:
> struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
> ...
> if (copy_from_user(skb_put(skb, len), buf, len)) {
Bug. Should be GFP_KERNEL, or copy_from_user() is incorrect in this
context.
>
> net/irda/af_irda.c:
> ias_opt = kmalloc(sizeof(struct irda_ias_set), GFP_ATOMIC);
> ...
> if (copy_from_user(ias_opt, optval, optlen)) {
Bug. Should be GFP_KERNEL, or copy_from_user() is incorrect in this
context.
>
> fs/btrfs/ioctl.c:
> vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
> ...
> if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
Bug. Should be GFP_KERNEL, or copy_from_user() is incorrect in this
context.
> > fs/ocfs2/dlm/dlmfs.c:
> lvb_buf = kmalloc(writelen, GFP_NOFS);
> ...
> bytes_left = copy_from_user(lvb_buf, buf, writelen);
Bug. Should be GFP_KERNEL, or copy_from_user() is incorrect in this
context.
>
> net/sunrpc/auth_gss/auth_gss.c:
> buf = kmalloc(mlen, GFP_NOFS);
> ...
> if (copy_from_user(buf, src, mlen))
Bug. Should be GFP_KERNEL, or copy_from_user() is incorrect in this
context.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-03-09 3:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-06 7:04 [RFC][PATCH] kmemdup_from_user(): introduce Li Zefan
2009-03-06 7:23 ` Américo Wang
2009-03-06 7:37 ` KOSAKI Motohiro
2009-03-06 8:03 ` KOSAKI Motohiro
2009-03-06 7:39 ` Li Zefan
2009-03-06 8:20 ` Alexey Dobriyan
2009-03-06 8:27 ` Li Zefan
2009-03-06 8:39 ` Andrew Morton
2009-03-06 8:57 ` Alexey Dobriyan
2009-03-06 9:09 ` KOSAKI Motohiro
2009-03-06 9:01 ` Li Zefan
2009-03-06 9:15 ` Andrew Morton
2009-03-06 9:49 ` [PATCH -v2] memdup_user(): introduce Li Zefan
2009-03-06 23:03 ` Andrew Morton
2009-03-07 16:48 ` Arjan van de Ven
2009-03-07 16:54 ` Roland Dreier
2009-03-07 18:27 ` Andrew Morton
2009-03-09 2:22 ` Li Zefan
2009-03-09 3:00 ` Andrew Morton
2009-03-09 3:30 ` Li Zefan
2009-03-09 3:45 ` Andrew Morton [this message]
2009-03-06 9:03 ` [RFC][PATCH] kmemdup_from_user(): introduce Alexey Dobriyan
2009-03-06 9:02 ` Li Zefan
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=20090308204535.8a2af3fa.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=adobriyan@gmail.com \
--cc=arjan@infradead.org \
--cc=chris.mason@oracle.com \
--cc=kkeil@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizf@cn.fujitsu.com \
--cc=samuel@sortiz.org \
--cc=swhiteho@redhat.com \
--cc=trond.myklebust@fys.uio.no \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox