Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1381366 > unrolled thread

[PATCH] tracing: Don't use the address of the buffer array name in copy_from_user

Started byWang Xiaoqiang <wangxq10@lzu.edu.cn>
First post2016-04-18 10:30 +0200
Last post2016-04-26 18:40 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] tracing: Don't use the address of the buffer array name in  copy_from_user Wang Xiaoqiang <wangxq10@lzu.edu.cn> - 2016-04-18 10:30 +0200
    Re: [PATCH] tracing: Don't use the address of the buffer array name  in copy_from_user Steven Rostedt <rostedt@goodmis.org> - 2016-04-26 18:40 +0200

#1381366 — [PATCH] tracing: Don't use the address of the buffer array name in copy_from_user

FromWang Xiaoqiang <wangxq10@lzu.edu.cn>
Date2016-04-18 10:30 +0200
Subject[PATCH] tracing: Don't use the address of the buffer array name in copy_from_user
Message-ID<rpcJc-2fT-11@gated-at.bofh.it>
Hi, all,

From 7dbacb179a4d5f9ac9d7e1b3733664b3b0fe23ae Mon Sep 17 00:00:00 2001
From: Wang Xiaoqiang <wangxq10@lzu.edu.cn>
Date: Mon, 18 Apr 2016 14:58:15 +0800
Subject: [PATCH] tracing: Don't use the address of the buffer array name in
 copy_from_user

Fix the problem as follows:

    ...
    char buf[64];
    ...
    if (copy_from_user(&buf, ubuf, cnt))
    ...

Even though the value of "&buf" equals "buf", but there is no need
to get the address of the "buf" again. Use "buf" replace "&buf".

Signed-off-by: Wang Xiaoqiang <wangxq10@lzu.edu.cn>
---
 kernel/trace/trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a2f0b9f..422ab57 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3658,7 +3658,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 	if (cnt >= sizeof(buf))
 		return -EINVAL;
 
-	if (copy_from_user(&buf, ubuf, cnt))
+	if (copy_from_user(buf, ubuf, cnt))
 		return -EFAULT;
 
 	buf[cnt] = 0;
@@ -4474,7 +4474,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 	if (cnt > MAX_TRACER_SIZE)
 		cnt = MAX_TRACER_SIZE;
 
-	if (copy_from_user(&buf, ubuf, cnt))
+	if (copy_from_user(buf, ubuf, cnt))
 		return -EFAULT;
 
 	buf[cnt] = 0;
@@ -5264,7 +5264,7 @@ static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
 	if (cnt >= sizeof(buf))
 		return -EINVAL;
 
-	if (copy_from_user(&buf, ubuf, cnt))
+	if (copy_from_user(buf, ubuf, cnt))
 		return -EFAULT;
 
 	buf[cnt] = 0;
-- 
2.1.4

[toc] | [next] | [standalone]


#1387695 — Re: [PATCH] tracing: Don't use the address of the buffer array name in copy_from_user

FromSteven Rostedt <rostedt@goodmis.org>
Date2016-04-26 18:40 +0200
SubjectRe: [PATCH] tracing: Don't use the address of the buffer array name in copy_from_user
Message-ID<rsebM-2ma-9@gated-at.bofh.it>
In reply to#1381366
On Mon, 18 Apr 2016 15:23:29 +0800
Wang Xiaoqiang <wangxq10@lzu.edu.cn> wrote:

> Hi, all,
> 
> From 7dbacb179a4d5f9ac9d7e1b3733664b3b0fe23ae Mon Sep 17 00:00:00 2001
> From: Wang Xiaoqiang <wangxq10@lzu.edu.cn>
> Date: Mon, 18 Apr 2016 14:58:15 +0800
> Subject: [PATCH] tracing: Don't use the address of the buffer array name in
>  copy_from_user
> 
> Fix the problem as follows:

What problem is being fixed?

> 
>     ...
>     char buf[64];
>     ...
>     if (copy_from_user(&buf, ubuf, cnt))
>     ...
> 
> Even though the value of "&buf" equals "buf", but there is no need
> to get the address of the "buf" again. Use "buf" replace "&buf".

I'll take this, but more as a cleanup and not a "fix".

Thanks,

-- Steve

> 
> Signed-off-by: Wang Xiaoqiang <wangxq10@lzu.edu.cn>
> ---
>  kernel/trace/trace.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index a2f0b9f..422ab57 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3658,7 +3658,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
>  	if (cnt >= sizeof(buf))
>  		return -EINVAL;
>  
> -	if (copy_from_user(&buf, ubuf, cnt))
> +	if (copy_from_user(buf, ubuf, cnt))
>  		return -EFAULT;
>  
>  	buf[cnt] = 0;
> @@ -4474,7 +4474,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
>  	if (cnt > MAX_TRACER_SIZE)
>  		cnt = MAX_TRACER_SIZE;
>  
> -	if (copy_from_user(&buf, ubuf, cnt))
> +	if (copy_from_user(buf, ubuf, cnt))
>  		return -EFAULT;
>  
>  	buf[cnt] = 0;
> @@ -5264,7 +5264,7 @@ static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
>  	if (cnt >= sizeof(buf))
>  		return -EINVAL;
>  
> -	if (copy_from_user(&buf, ubuf, cnt))
> +	if (copy_from_user(buf, ubuf, cnt))
>  		return -EFAULT;
>  
>  	buf[cnt] = 0;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web