2022-04-23 03:48:38

by Junwen Wu

[permalink] [raw]
Subject: [PATCH v1] proc: limit schedstate node write operation

Whatever value is written to /proc/$pid/sched, a task's schedstate data
will reset.In some cases, schedstate will drop by accident. We restrict
writing a certain value to this node before the data is reset.

Signed-off-by: Junwen Wu <[email protected]>
---
fs/proc/base.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index d654ce7150fd..6bb2677659ce 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1459,13 +1459,21 @@ sched_write(struct file *file, const char __user *buf,
{
struct inode *inode = file_inode(file);
struct task_struct *p;
+ char ubuf[5];

- p = get_proc_task(inode);
- if (!p)
- return -ESRCH;
- proc_sched_set_task(p);
+ memset(ubuf, 0, sizeof(ubuf));
+ if (count > 5)
+ count = 0;
+ if (copy_from_user(ubuf, buf, count))
+ return -EFAULT;
+ if (strcmp(ubuf, "reset") == 0) {
+ p = get_proc_task(inode);
+ if (!p)
+ return -ESRCH;
+ proc_sched_set_task(p);

- put_task_struct(p);
+ put_task_struct(p);
+ }

return count;
}
--
2.25.1


2022-04-23 05:55:33

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

On Sat, Apr 23, 2022 at 02:31:04AM +0000, Junwen Wu wrote:
> Whatever value is written to /proc/$pid/sched, a task's schedstate data
> will reset.In some cases, schedstate will drop by accident. We restrict
> writing a certain value to this node before the data is reset.

... and break the existing scripts which expect the current behaviour.

2022-04-24 15:35:03

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

Hi Junwen,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on hnaz-mm/master]
[also build test WARNING on kees/for-next/pstore linus/master linux/master v5.18-rc3 next-20220422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/intel-lab-lkp/linux/commits/Junwen-Wu/proc-limit-schedstate-node-write-operation/20220423-103457
base: https://github.com/hnaz/linux-mm master
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20220423/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/e7bc039b7c0aa4e9a5bb3ae2340769a451f795db
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Junwen-Wu/proc-limit-schedstate-node-write-operation/20220423-103457
git checkout e7bc039b7c0aa4e9a5bb3ae2340769a451f795db
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

fs/proc/base.c: In function 'sched_write':
>> fs/proc/base.c:1468:13: warning: 'strcmp' of a string of length 5 and an array of size 5 evaluates to nonzero [-Wstring-compare]
1468 | if (strcmp(ubuf, "reset") == 0) {
| ^~~~~~~~~~~~~~~~~~~~~


vim +/strcmp +1468 fs/proc/base.c

1454
1455 static ssize_t
1456 sched_write(struct file *file, const char __user *buf,
1457 size_t count, loff_t *offset)
1458 {
1459 struct inode *inode = file_inode(file);
1460 struct task_struct *p;
1461 char ubuf[5];
1462
1463 memset(ubuf, 0, sizeof(ubuf));
1464 if (count > 5)
1465 count = 0;
1466 if (copy_from_user(ubuf, buf, count))
1467 return -EFAULT;
> 1468 if (strcmp(ubuf, "reset") == 0) {
1469 p = get_proc_task(inode);
1470 if (!p)
1471 return -ESRCH;
1472 proc_sched_set_task(p);
1473
1474 put_task_struct(p);
1475 }
1476
1477 return count;
1478 }
1479

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-04-25 01:55:00

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

On Sun, Apr 24, 2022 at 03:23:54PM +0000, Junwen Wu wrote:
> From: Matthew Wilcox <[email protected]>
>
> On Sat, Apr 23, 2022 at 02:31:04AM +0000, Junwen Wu wrote:
> > Whatever value is written to /proc/$pid/sched, a task's schedstate data
> > will reset.In some cases, schedstate will drop by accident. We restrict
> > writing a certain value to this node before the data is reset.
>
> ... and break the existing scripts which expect the current behaviour.
>
>
> Hi, Matthew,can you describe it in more detail.

What detail do you need? Existing scripts depend on the existing
behaviour. Your change to the behaviour will break them. That's not
allowed, so your patch is rejected.

2022-04-25 07:33:54

by Junwen Wu

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

From: kernel test robot <[email protected]>

>Hi Junwen,

>Thank you for the patch! Perhaps something to improve:

ooh ,I will fix the warning

2022-04-25 08:21:46

by Junwen Wu

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

From: Matthew Wilcox <[email protected]>

On Sat, Apr 23, 2022 at 02:31:04AM +0000, Junwen Wu wrote:
> Whatever value is written to /proc/$pid/sched, a task's schedstate data
> will reset.In some cases, schedstate will drop by accident. We restrict
> writing a certain value to this node before the data is reset.

... and break the existing scripts which expect the current behaviour.


Hi, Matthew,can you describe it in more detail.

Thanks

2022-05-03 00:55:05

by Junwen Wu

[permalink] [raw]
Subject: Re: [PATCH v1] proc: limit schedstate node write operation

From: Matthew Wilcox <[email protected]>

On Sun, Apr 24, 2022 at 03:23:54PM +0000, Junwen Wu wrote:
> From: Matthew Wilcox <[email protected]>
>
> On Sat, Apr 23, 2022 at 02:31:04AM +0000, Junwen Wu wrote:
> > Whatever value is written to /proc/$pid/sched, a task's schedstate data
> > will reset.In some cases, schedstate will drop by accident. We restrict
> > writing a certain value to this node before the data is reset.
>
> ... and break the existing scripts which expect the current behaviour.
>
>
> Hi, Matthew,can you describe it in more detail.

> What detail do you need? Existing scripts depend on the existing
> behaviour. Your change to the behaviour will break them. That's not
> allowed, so your patch is rejected.

ooh ,just how to operate the node make the script break. I write data to
this node can work well.

Thanks