mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qais Yousef <qyousef@layalina.io>
To: Xuewen Yan <xuewen.yan@unisoc.com>
Cc: rafael@kernel.org, pavel@ucw.cz, len.brown@intel.com,
	guohua.yan@unisoc.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PM: QOS: Always use "kstrtos32_from_user()" in cpu_latency_qos_write()
Date: Sat, 19 Aug 2023 20:05:44 +0100	[thread overview]
Message-ID: <20230819190544.kvf6rr4yhukpktle@airbuntu> (raw)
In-Reply-To: <20230807062345.490-1-xuewen.yan@unisoc.com>

On 08/07/23 14:23, Xuewen Yan wrote:
> In cpu_latency_qos_write, there is a judgment on whether the count
> value is equal to sizeof(s32). This means that when user write 100~999,
> it would get error value because it would call the "copy_from_user()"
> instead of "kstrtos32".
> Just like:
> 
>  # echo 500 > /dev/cpu_dma_latency
> [T4893] write: qos value=170930229
> [T4893] write: count value=4
> 
> [T4893] write: qos value=170930226
> [T4893] write: count value=4
> 
> To prevent this happening, delete the "copy_from_user()" and
> always use "kstrtos32_from_user()".
> 
> Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
> ---
>  kernel/power/qos.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/power/qos.c b/kernel/power/qos.c
> index 782d3b41c1f3..21a2f873e921 100644
> --- a/kernel/power/qos.c
> +++ b/kernel/power/qos.c
> @@ -379,17 +379,11 @@ static ssize_t cpu_latency_qos_write(struct file *filp, const char __user *buf,
>  				     size_t count, loff_t *f_pos)
>  {
>  	s32 value;
> +	int ret;
>  
> -	if (count == sizeof(s32)) {
> -		if (copy_from_user(&value, buf, sizeof(s32)))
> -			return -EFAULT;

In your test you use `echo` which produces a string. But from C, someone can
write a program where buf contains s32 and not a string, and this will break
those programs. If this expectations is no longer valid, then it's fine to
remove it.

Maybe we can change the order to call kstrtos32() first, but this is not bullet
proof though..


Cheers

--
Qais Yousef

> -	} else {
> -		int ret;
> -
> -		ret = kstrtos32_from_user(buf, count, 16, &value);
> -		if (ret)
> -			return ret;
> -	}
> +	ret = kstrtos32_from_user(buf, count, 16, &value);
> +	if (ret)
> +		return ret;
>  
>  	cpu_latency_qos_update_request(filp->private_data, value);
>  
> -- 
> 2.25.1
> 

      parent reply	other threads:[~2023-08-20 10:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07  6:23 Xuewen Yan
2023-08-15  6:56 ` Xuewen Yan
2023-08-19 19:05 ` Qais Yousef [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=20230819190544.kvf6rr4yhukpktle@airbuntu \
    --to=qyousef@layalina.io \
    --cc=guohua.yan@unisoc.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=xuewen.yan@unisoc.com \
    /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®