mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	David Howells <dhowells@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH 2/2] test: check copy_to/from_user boundary validation
Date: Tue, 03 Dec 2013 13:53:36 -0800	[thread overview]
Message-ID: <1386107616.30493.18.camel@joe-AO722> (raw)
In-Reply-To: <1386106054-27636-3-git-send-email-keescook@chromium.org>

On Tue, 2013-12-03 at 13:27 -0800, Kees Cook wrote:
> To help avoid an architecture failing to correctly check kernel/user
> boundaries when handling copy_to_user, copy_from_user, put_user, or
> get_user, perform some simple tests and fail to load if any of them
> behave unexpectedly.

> diff --git a/kernel/test_user_copy.c b/kernel/test_user_copy.c

> +#define failed(msg) {	\
> +	pr_warn(msg);	\
> +	ret = -EINVAL;	\
> +}

That's an ugly macro.

Maybe use something like:

#define test(func, msg)				\
({						\
	int ret = func;				\
	if (ret)				\
		pr_warn("%s\n", msg);		\
	ret;					\
})

> +static int __init test_user_copy_init(void)
> +{
> +	int ret = 0;
> +	char *kmem;
> +	char __user *usermem;
> +	unsigned long user_addr;
> +	unsigned long value = 0x5A;
> +
> +	kmem = kmalloc(PAGE_SIZE * 2, GFP_KERNEL);
> +	if (!kmem) {
> +		pr_warn("Failed to allocate kernel memory\n");

Unnecessary as there's a generic alloc OOM
with a dump_stack()

[]

> +	/* Legitimate usage: none of these should fail. */
> +	if (copy_from_user(kmem, usermem, PAGE_SIZE))
> +		failed("legitimate copy_from_user failed");

	ret |= test(copy_from_user(kmem, usermem, PAGE_SIZE),
		    "legitimate copy_from_user failed");

> +	if (copy_to_user(usermem, kmem, PAGE_SIZE))
> +		failed("legitimate copy_to_user failed");

	ret |= test(copy_to_user(usermem, kmem, PAGE_SIZE),
		    "legitimate copy_to_user failed");

etc.



      parent reply	other threads:[~2013-12-03 21:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-03 21:27 [PATCH 0/2] test modules Kees Cook
2013-12-03 21:27 ` [PATCH 1/2] test: add minimal module for verification testing Kees Cook
2013-12-03 21:36   ` Andrew Morton
2013-12-03 23:52   ` Rusty Russell
2013-12-03 21:27 ` [PATCH 2/2] test: check copy_to/from_user boundary validation Kees Cook
2013-12-03 21:47   ` Andrew Morton
2013-12-03 22:03     ` Kees Cook
2013-12-03 21:53   ` Joe Perches [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=1386107616.30493.18.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dhowells@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®