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] [day] [month] [year] [list]
Message-Id: <20090803134632.7cff1658.akpm@linux-foundation.org>
Date:	Mon, 3 Aug 2009 13:46:32 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Julia Lawall <julia@...u.dk>
Cc:	linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
	Ming Lei <tom.leiming@...il.com>
Subject: Re: [PATCH 1/5] drivers/video: Add kmalloc NULL tests

On Thu, 30 Jul 2009 16:00:33 +0200 (CEST)
Julia Lawall <julia@...u.dk> wrote:

> From: Julia Lawall <julia@...u.dk>
> 
> Check that the result of kmalloc is not NULL before passing it to other
> functions.
> 
> The semantic match that finds this problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> expression *x;
> identifier f;
> constant char *C;
> @@
> 
> x = \(kmalloc\|kcalloc\|kzalloc\)(...);
> ... when != x == NULL
>     when != x != NULL
>     when != (x || ...)
> (
> kfree(x)
> |
> f(...,C,...,x,...)
> |
> *f(...,x,...)
> |
> *x->f
> )
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@...u.dk>
> 
> ---
>  drivers/video/au1100fb.c            |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
> index 378f277..1766846 100644
> --- a/drivers/video/au1100fb.c
> +++ b/drivers/video/au1100fb.c
> @@ -716,6 +716,10 @@ int au1100fb_setup(char *options)
>  			/* Mode option (only option that start with digit) */
>  			else if (isdigit(this_opt[0])) {
>  				mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
> +				if (!mode) {
> +					print_err("memory allocation failed");
> +					return -ENOMEM;
> +				}
>  				strncpy(mode, this_opt, strlen(this_opt) + 1);
>  			}
>  			/* Unsupported option */

We may as well clean up that open-coded kstrdup() too?

--- a/drivers/video/au1100fb.c~drivers-video-add-kmalloc-null-tests-fix
+++ a/drivers/video/au1100fb.c
@@ -715,12 +715,11 @@ int au1100fb_setup(char *options)
 			}
 			/* Mode option (only option that start with digit) */
 			else if (isdigit(this_opt[0])) {
-				mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
+				mode = kstrdup(this_opt, GFP_KERNEL);
 				if (!mode) {
 					print_err("memory allocation failed");
 					return -ENOMEM;
 				}
-				strncpy(mode, this_opt, strlen(this_opt) + 1);
 			}
 			/* Unsupported option */
 			else {
_

--
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