From: Andrew Morton <akpm@osdl.org>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, keyrings@linux-nfs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Keys: Deal properly with strnlen_user()
Date: Sat, 18 Feb 2006 02:20:26 -0800 [thread overview]
Message-ID: <20060218022026.348e3b39.akpm@osdl.org> (raw)
In-Reply-To: <8396.1140188581@warthog.cambridge.redhat.com>
David Howells <dhowells@redhat.com> wrote:
>
> +#define key_get_type_from_user(type, _type, error) \
> +do { \
> + ret = strncpy_from_user(type, _type, sizeof(type)); \
> + if (ret < 0) \
> + goto error; \
> + \
> + if (ret == 0 || ret > sizeof(type) - 1) { \
> + ret = -EINVAL; \
> + goto error; \
> + } \
> + \
> + ret = -EPERM; \
> + if (type[0] == '.') \
> + goto error; \
> + \
> + type[31] = '\0'; \
> +} while(0)
> +
> +#define key_get_description_from_user(desc, _desc, dlen, error, error2) \
> +do { \
> + ret = -EFAULT; \
> + dlen = strnlen_user(_desc, PAGE_SIZE); \
> + if (dlen <= 0) \
> + goto error; \
> + \
> + ret = -EINVAL; \
> + if (dlen > PAGE_SIZE) \
> + goto error; \
> + \
> + ret = -ENOMEM; \
> + desc = kmalloc(dlen, GFP_KERNEL); \
> + if (!desc) \
> + goto error; \
> + \
> + ret = -EFAULT; \
> + if (copy_from_user(desc, _desc, dlen - 1) != 0) \
> + goto error2; \
> + \
> + desc[dlen - 1] = '\0'; \
> +} while(0)
ug. Well it's your code ;)
It should really parameterise `ret' too.
Are you sure you want to do this? From my reading, doing it with plain old
subroutines would work?
next prev parent reply other threads:[~2006-02-18 10:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-17 15:03 David Howells
2006-02-18 10:20 ` Andrew Morton [this message]
2006-02-18 16:40 ` David Howells
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=20060218022026.348e3b39.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=dhowells@redhat.com \
--cc=keyrings@linux-nfs.org \
--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
all inboxes | Powered by JetHome®