From: Greg KH <gregkh@linuxfoundation.org>
To: Tiezhu Yang <kernelpatch@126.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] driver core: restrict buffer length in online_store()
Date: Fri, 21 Jul 2017 07:28:35 +0200 [thread overview]
Message-ID: <20170721052835.GB15738@kroah.com> (raw)
In-Reply-To: <665c0831.b66.15d629566c7.Coremail.kernelpatch@126.com>
On Fri, Jul 21, 2017 at 08:39:04AM +0800, Tiezhu Yang wrote:
> According to Documentation/ABI/testing/sysfs-devices-online, in order to
> control CPU N's hotplug state, we should write one of 'Yy1Nn0' to the file
> /sys/devices/system/cpu/cpuN/online, other values should be invalid. so the
> buffer length should be 2, buf[0] is one of 'Yy1Nn0' and buf[1] is '\n'.
>
> without patch:
> [root@localhost home]# echo 0test > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 0
> [root@localhost home]# echo 1test > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 1
> [root@localhost home]# echo ntest > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 0
> [root@localhost home]# echo ytest > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 1
> [root@localhost home]# echo Ntest > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 0
> [root@localhost home]# echo Ytest > /sys/devices/system/cpu/cpu1/online
> [root@localhost home]# cat /sys/devices/system/cpu/cpu1/online
> 1
>
> with patch:
> [root@localhost home]# echo 0test > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
> [root@localhost home]# echo 1test > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
> [root@localhost home]# echo ntest > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
> [root@localhost home]# echo ytest > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
> [root@localhost home]# echo Ntest > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
> [root@localhost home]# echo Ytest > /sys/devices/system/cpu/cpu1/online
> bash: echo: write error: Invalid argument
>
> Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
> ---
> drivers/base/core.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 755451f..6588ed5 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1005,6 +1005,12 @@ static ssize_t online_store(struct device *dev, struct device_attribute *attr,
> bool val;
> int ret;
>
> + /* According to Documentation/ABI/testing/sysfs-devices-online,
> + * the buf length should be 2, buf[0]: one of 'Yy1Nn0', buf[1]: '\n'.
> + */
> + if (strlen(buf) != 2)
> + return -EINVAL;
> +
> ret = strtobool(buf, &val);
strtobool should handle all of this, so let's not force every individual
user of it to check the "length".
What is the problem that this patch is trying to solve? Who is writing
odd values to this file that is not working properly? Who writes
"0testfoo" to the file and expect it to reject the value?
thanks,
greg k-h
prev parent reply other threads:[~2017-07-21 5:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 0:39 [PATCH] driver core: restrict buffer length in online_store() Tiezhu Yang
2017-07-21 5:28 ` Greg KH [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=20170721052835.GB15738@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=kernelpatch@126.com \
--cc=linux-kernel@vger.kernel.org \
/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