From: Davi Arnaut <davi.arnaut@gmail.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: torvalds@osdl.org, akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] strndup_user, v2
Date: Thu, 16 Feb 2006 00:56:09 -0300 [thread overview]
Message-ID: <20060216005609.fbc35236.davi.arnaut@gmail.com> (raw)
In-Reply-To: <1140053156.14831.43.camel@localhost.localdomain>
On Thu, 16 Feb 2006 01:25:56 +0000
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> On Mer, 2006-02-15 at 18:22 -0300, Davi Arnaut wrote:
> > +static inline char *strdup_user(const char __user *s)
> > +{
> > + return strndup_user(s, 4096);
> > +}
>
> Still shouldn't exist. Its just a bad idea to give people broken
> function they don't yet use.
Ok, I will remove it. But it's a sane default, if someone wants more
than 4096, they should use strndup_user.
> > + length = strlen_user(s);
>
> Should use strnlen_user or this function is useless for most cases.
Ok.
> > +
> > + if (!length)
> > + return ERR_PTR(-EFAULT);
>
> Zero isn't an -EFAULT length. Its a null string and valid
strlen_user returns _0_ on exception. If you don't belive me,
kernel/module.c or arch/x86_64/lib/usercopy.c are a good starting
point.
> > +
> > + if (length > n)
> > + length = n;
> > +
> > + p = kmalloc(length, GFP_KERNEL);
> > +
> > + if (!p)
> > + return ERR_PTR(-ENOMEM);
> > +
> > + if (strncpy_from_user(p, s, length) < 0) {
> > + kfree(p);
> > + return ERR_PTR(-EFAULT);
> > + }
> > +
> > + p[length - 1] = '\0';
>
> And still broken.
>
> "Hello" -> length = 5 "Hello\0"[4] = 0 "Hell"
>
NO! strlen_user("Hello") -> length = 6
strlen_user returns the size of the string INCLUDING the
terminating NUL.
Are we talking in the same language ?
--
Davi Arnaut
next prev parent reply other threads:[~2006-02-16 2:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-15 21:22 Davi Arnaut
2006-02-15 20:54 ` Sergey Vlasov
2006-02-16 1:25 ` Alan Cox
2006-02-16 3:56 ` Davi Arnaut [this message]
2006-02-16 14:44 ` Alan Cox
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=20060216005609.fbc35236.davi.arnaut@gmail.com \
--to=davi.arnaut@gmail.com \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/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
Powered by JetHome