kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 2/2] gru: cleanup gru_dump_context() a little
@ 2014-01-30 12:10 Dan Carpenter
  2014-01-30 14:24 ` Dimitri Sivanich
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2014-01-30 12:10 UTC (permalink / raw)
  To: Dimitri Sivanich; +Cc: linux-kernel, kernel-janitors

"ret" is zero here so we can remove the "!ret" part of the condition.
"uhdr" is alread a __user pointer so we can remove the cast.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Btw, speaking of __user pointers there are some places where we
dereference them in this file.  It's not a security problem because we
have already used copy_to_user() to successfully write to the pointer at
point.  But if you have something like PAX which puts user pointers and
kernel pointers in a separate address space then this will cause
problems.

Run sparse to see the issue.

diff --git a/drivers/misc/sgi-gru/grukdump.c b/drivers/misc/sgi-gru/grukdump.c
index 2bef3f76032a..a3700a56b8ff 100644
--- a/drivers/misc/sgi-gru/grukdump.c
+++ b/drivers/misc/sgi-gru/grukdump.c
@@ -178,10 +178,10 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
 	hdr.cbrcnt = cbrcnt;
 	hdr.dsrcnt = dsrcnt;
 	hdr.cch_locked = cch_locked;
-	if (!ret && copy_to_user((void __user *)uhdr, &hdr, sizeof(hdr)))
-		ret = -EFAULT;
+	if (copy_to_user(uhdr, &hdr, sizeof(hdr)))
+		return -EFAULT;
 
-	return ret ? ret : bytes;
+	return bytes;
 }
 
 int gru_dump_chiplet_request(unsigned long arg)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch 2/2] gru: cleanup gru_dump_context() a little
  2014-01-30 12:10 [patch 2/2] gru: cleanup gru_dump_context() a little Dan Carpenter
@ 2014-01-30 14:24 ` Dimitri Sivanich
  0 siblings, 0 replies; 2+ messages in thread
From: Dimitri Sivanich @ 2014-01-30 14:24 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors

Acked-by: Dimitri Sivanich <sivanich@sgi.com>

On Thu, Jan 30, 2014 at 03:10:48PM +0300, Dan Carpenter wrote:
> "ret" is zero here so we can remove the "!ret" part of the condition.
> "uhdr" is alread a __user pointer so we can remove the cast.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Btw, speaking of __user pointers there are some places where we
> dereference them in this file.  It's not a security problem because we
> have already used copy_to_user() to successfully write to the pointer at
> point.  But if you have something like PAX which puts user pointers and
> kernel pointers in a separate address space then this will cause
> problems.
> 
> Run sparse to see the issue.
> 
> diff --git a/drivers/misc/sgi-gru/grukdump.c b/drivers/misc/sgi-gru/grukdump.c
> index 2bef3f76032a..a3700a56b8ff 100644
> --- a/drivers/misc/sgi-gru/grukdump.c
> +++ b/drivers/misc/sgi-gru/grukdump.c
> @@ -178,10 +178,10 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
>  	hdr.cbrcnt = cbrcnt;
>  	hdr.dsrcnt = dsrcnt;
>  	hdr.cch_locked = cch_locked;
> -	if (!ret && copy_to_user((void __user *)uhdr, &hdr, sizeof(hdr)))
> -		ret = -EFAULT;
> +	if (copy_to_user(uhdr, &hdr, sizeof(hdr)))
> +		return -EFAULT;
>  
> -	return ret ? ret : bytes;
> +	return bytes;
>  }
>  
>  int gru_dump_chiplet_request(unsigned long arg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-30 14:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-30 12:10 [patch 2/2] gru: cleanup gru_dump_context() a little Dan Carpenter
2014-01-30 14:24 ` Dimitri Sivanich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).