android_kernel_motorola_sm6375/kernel/sched
Repository files (latest commit first)
Filename Latest commit message Latest commit date
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
..
autogroup.c
autogroup.h
clock.c
completion.c
core.c sched/uclamp: Always use 'enum uclamp_id' for clamp_id values 2019-09-03 09:17:40 +02:00
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq.c
cpufreq_schedutil.c cpufreq: schedutil: fix equation in comment 2019-08-08 09:09:31 +02:00
cpupri.c
cpupri.h
cputime.c
deadline.c sched: Rework pick_next_task() slow-path 2019-08-08 09:09:31 +02:00
debug.c
fair.c sched/fair: Speed-up energy-aware wake-ups 2019-09-13 07:45:17 +02:00
features.h
idle.c sched: Rework pick_next_task() slow-path 2019-08-08 09:09:31 +02:00
isolation.c
loadavg.c
Makefile
membarrier.c
pelt.c
pelt.h
psi.c sched/psi: Correct overly pessimistic size calculation 2019-09-13 07:49:28 +02:00
rt.c sched: Rework pick_next_task() slow-path 2019-08-08 09:09:31 +02:00
sched-pelt.h
sched.h sched/uclamp: Always use 'enum uclamp_id' for clamp_id values 2019-09-03 09:17:40 +02:00
stats.c
stats.h
stop_task.c sched: Rework pick_next_task() slow-path 2019-08-08 09:09:31 +02:00
swait.c
topology.c sched/topology: Improve load balancing on AMD EPYC systems 2019-09-03 09:17:37 +02:00
wait.c
wait_bit.c