Miles Chen
4adcdcea71
sched/psi: Correct overly pessimistic size calculation
When passing a equal or more then 32 bytes long string to psi_write(),
psi_write() copies 31 bytes to its buf and overwrites buf[30]
with '\0'. Which makes the input string 1 byte shorter than
it should be.
Fix it by copying sizeof(buf) bytes when nbytes >= sizeof(buf).
This does not cause problems in normal use case like:
"some 500000 10000000" or "full 500000 10000000" because they
are less than 32 bytes in length.
/* assuming nbytes == 35 */
char buf[32];
buf_size = min(nbytes, (sizeof(buf) - 1)); /* buf_size = 31 */
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
buf[buf_size - 1] = '\0'; /* buf[30] = '\0' */
Before:
%cd /proc/pressure/
%echo "123456789|123456789|123456789|1234" > memory
[ 22.473497] nbytes=35,buf_size=31
[ 22.473775] 123456789|123456789|123456789| (print 30 chars)
%sh: write error: Invalid argument
%echo "123456789|123456789|123456789|1" > memory
[ 64.916162] nbytes=32,buf_size=31
[ 64.916331] 123456789|123456789|123456789| (print 30 chars)
%sh: write error: Invalid argument
After:
%cd /proc/pressure/
%echo "123456789|123456789|123456789|1234" > memory
[ 254.837863] nbytes=35,buf_size=32
[ 254.838541] 123456789|123456789|123456789|1 (print 31 chars)
%sh: write error: Invalid argument
%echo "123456789|123456789|123456789|1" > memory
[ 9965.714935] nbytes=32,buf_size=32
[ 9965.715096] 123456789|123456789|123456789|1 (print 31 chars)
%sh: write error: Invalid argument
Also remove the superfluous parentheses.
Signed-off-by: Miles Chen <miles.chen@mediatek.com>
Cc: <linux-mediatek@lists.infradead.org>
Cc: <wsd_upstream@mediatek.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190912103452.13281-1-miles.chen@mediatek.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-09-13 07:49:28 +02:00
..
2019-07-20 10:45:15 -07:00
2019-07-25 15:55:04 +02:00
2019-05-21 10:50:46 +02:00
2019-07-20 12:09:52 -07:00
2019-07-25 15:51:54 +02:00
2019-06-03 16:18:12 +02:00
2019-07-25 15:51:54 +02:00
2019-07-11 15:30:05 -07:00
2019-07-25 15:51:54 +02:00
2019-07-15 20:44:49 -07:00
2019-05-21 11:28:45 +02:00
2019-08-08 09:09:30 +02:00
2019-09-13 07:49:28 +02:00
2019-07-10 20:37:49 +02:00
2019-07-25 15:51:54 +02:00
2019-04-29 16:48:03 +02:00
2019-04-04 21:04:13 -04:00
2019-06-05 17:37:17 +02:00
2019-05-30 11:26:37 -07:00
2019-04-26 13:51:03 -04:00
2019-05-30 11:26:35 -07:00
2019-07-08 18:55:42 -07:00
2019-07-08 18:55:42 -07:00
2019-07-08 18:55:42 -07:00
2019-05-28 17:46:43 -04:00
2019-06-05 17:37:17 +02:00
2019-01-25 11:22:43 -08:00
2019-06-19 17:09:55 +02:00
2019-03-07 18:32:02 -08:00
2019-05-21 10:50:45 +02:00
2019-06-05 17:36:37 +02:00
2019-07-08 10:39:56 -07:00
2019-06-19 17:09:06 +02:00
2019-05-21 10:50:45 +02:00
2019-07-08 19:19:37 -07:00
2019-05-21 11:52:39 +02:00
2019-07-22 16:02:03 +02:00
2019-05-30 11:26:35 -07:00
2019-06-03 15:49:06 +02:00
2019-07-25 15:37:04 +02:00
2019-05-21 10:50:45 +02:00
2019-06-03 11:50:18 +02:00
2019-07-09 10:10:52 +09:00
2019-05-21 10:50:45 +02:00
2019-07-12 11:05:40 -07:00
2019-05-21 10:50:45 +02:00
2019-06-17 12:09:22 +02:00
2019-05-21 10:50:45 +02:00
2019-05-21 10:50:46 +02:00
2019-05-21 10:50:46 +02:00
2019-05-21 10:50:46 +02:00
2019-07-22 18:05:11 +02:00
2019-03-07 18:32:02 -08:00
2019-06-19 17:09:06 +02:00
2019-07-08 20:28:59 -07:00
2019-06-19 17:09:06 +02:00
2019-05-24 20:16:01 +02:00
2019-07-18 11:51:00 -07:00
2019-05-30 11:26:39 -07:00
2019-05-21 10:50:45 +02:00
2019-06-05 17:37:17 +02:00
2019-05-24 20:16:01 +02:00
2019-07-18 17:08:07 -07:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-07-18 12:06:57 -07:00
2019-05-21 10:50:45 +02:00
2019-06-05 17:37:17 +02:00
2019-07-18 13:39:54 +08:00
2019-07-15 11:03:01 -03:00
2019-05-30 11:26:35 -07:00
2019-07-18 17:08:07 -07:00
2019-07-16 19:23:24 -07:00
2019-05-21 10:50:45 +02:00
2019-07-16 19:23:24 -07:00
2019-05-21 10:50:45 +02:00
2019-03-12 13:27:20 -07:00
2019-07-18 17:08:06 -07:00
2019-05-27 09:36:28 -05:00
2019-05-29 09:31:44 -05:00
2019-07-16 19:23:24 -07:00
2019-07-20 11:27:16 +02:00
2019-05-21 10:50:45 +02:00
2019-07-08 11:01:13 -07:00
2019-07-18 16:47:24 +02:00
2019-08-08 09:09:30 +02:00
2019-06-21 01:54:53 +02:00
2019-06-01 15:51:31 -07:00
2019-01-04 13:13:47 -08:00
2019-07-18 17:08:07 -07:00
2019-05-30 11:26:37 -07:00
2019-05-21 11:52:39 +02:00
2019-05-28 09:06:09 -07:00
2019-07-18 11:51:00 -07:00
2019-05-30 11:26:37 -07:00
2019-07-18 17:08:07 -07:00
2019-05-21 10:50:45 +02:00
2019-06-23 14:26:26 +02:00
2019-07-08 19:36:47 -07:00
2019-05-21 10:50:45 +02:00
2019-07-08 19:36:47 -07:00
2019-06-05 17:37:17 +02:00
2019-06-05 17:37:17 +02:00
2019-04-19 09:46:05 -07:00
2019-04-18 14:05:51 +02:00
2019-04-16 16:55:15 +02:00
2019-06-27 14:12:19 -07:00