public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: Andrew Morton <akpm@osdl.org>
Cc: "David S. Miller" <davem@redhat.com>,
	linux-arch@vger.kernel.org, rusty@rustcorp.com.au
Subject: Re: copy_mount_options()
Date: Sat, 21 Aug 2004 09:18:33 +1000	[thread overview]
Message-ID: <20040820231833.GH1945@krispykreme> (raw)
In-Reply-To: <20040820154736.166b66ec.akpm@osdl.org>


> OK, here's #2, with enhanced comment and changelog!
> 
> Untested though.

That removes one more place that uses the return value of 
copy_to/from_user.

Queue Rusty's "copy_from_user is a deathtrap" spiel:

http://www.ussg.iu.edu/hypermail/linux/kernel/0205.2/0193.html

I too hate that interface, Im continually getting it wrong. It would be
nice to remove the possibility of having similar such subtle bugs.

Anton

> davem says that copy_mount_options is failing in obscure ways if the
> architecture's copy_from_user() doesn't return an exact count of the number of
> uncopied bytes.
> 
> Fixing that up in each architecture is a pain - it involves falling back to
> byte-at-a-time copies.
> 
> It's simple to open-code this in namespace.c.  If we find other places in the
> kernel which care about this we can promote this to a global function.
> 
> Signed-off-by: Andrew Morton <akpm@osdl.org>
> ---
> 
>  25-akpm/fs/namespace.c |   30 ++++++++++++++++++++++++++++--
>  1 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff -puN fs/namespace.c~copy_mount_options-size-fix fs/namespace.c
> --- 25/fs/namespace.c~copy_mount_options-size-fix	Fri Aug 20 15:43:26 2004
> +++ 25-akpm/fs/namespace.c	Fri Aug 20 15:46:05 2004
> @@ -930,7 +930,33 @@ void mark_mounts_for_expiry(struct list_
>  
>  EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
>  
> -int copy_mount_options (const void __user *data, unsigned long *where)
> +/*
> + * Some copy_from_user() implementations do not return the exact number of
> + * bytes remaining to copy on a fault.  But copy_mount_options() requires that.
> + * Note that this function differs from copy_from_user() in that it will oops
> + * on bad values of `to', rather than returning a short copy.
> + */
> +static long
> +exact_copy_from_user(void *to, const void __user *from, unsigned long n)
> +{
> +	char *t = to;
> +	const char __user *f = from;
> +	char c;
> +
> +	if (!access_ok(VERIFY_READ, from, n))
> +		return n;
> +
> +	while (n) {
> +		if (__get_user(c, f))
> +			break;
> +		*t++ = c;
> +		f++;
> +		n--;
> +	}
> +	return n;
> +}
> +
> +int copy_mount_options(const void __user *data, unsigned long *where)
>  {
>  	int i;
>  	unsigned long page;
> @@ -952,7 +978,7 @@ int copy_mount_options (const void __use
>  	if (size > PAGE_SIZE)
>  		size = PAGE_SIZE;
>  
> -	i = size - copy_from_user((void *)page, data, size);
> +	i = size - exact_copy_from_user((void *)page, data, size);
>  	if (!i) {
>  		free_page(page); 
>  		return -EFAULT;
> _

  reply	other threads:[~2004-08-20 23:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-20 20:01 copy_mount_options() David S. Miller
2004-08-20 20:10 ` copy_mount_options() Andrew Morton
2004-08-20 21:11   ` copy_mount_options() David S. Miller
2004-08-20 21:31     ` copy_mount_options() Andrew Morton
2004-08-20 21:40       ` copy_mount_options() David S. Miller
2004-08-20 22:47         ` copy_mount_options() Andrew Morton
2004-08-20 23:18           ` Anton Blanchard [this message]
2004-08-20 23:51             ` copy_mount_options() David S. Miller
2004-08-21  0:07               ` copy_mount_options() Andrew Morton
2004-08-21  7:50                 ` copy_mount_options() Rusty Russell
2004-08-20 23:15 ` copy_mount_options() Benjamin Herrenschmidt
2004-08-22 11:50   ` copy_mount_options() Ralf Baechle

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=20040820231833.GH1945@krispykreme \
    --to=anton@samba.org \
    --cc=akpm@osdl.org \
    --cc=davem@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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