lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1386107616.30493.18.camel@joe-AO722>
Date:	Tue, 03 Dec 2013 13:53:36 -0800
From:	Joe Perches <joe@...ches.com>
To:	Kees Cook <keescook@...omium.org>
Cc:	linux-kernel@...r.kernel.org,
	Andrew Morton <akpm@...ux-foundation.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	David Howells <dhowells@...hat.com>,
	Rusty Russell <rusty@...tcorp.com.au>,
	Dave Hansen <dave.hansen@...ux.intel.com>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Subject: Re: [PATCH 2/2] test: check copy_to/from_user boundary validation

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.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ