android_kernel_xiaomi_sm8350/fs/proc
David Rientjes 830e0fc967 fs, proc: truncate /proc/pid/comm writes to first TASK_COMM_LEN bytes
Currently, a write to a procfs file will return the number of bytes
successfully written.  If the actual string is longer than this, the
remainder of the string will not be be written and userspace will
complete the operation by issuing additional write()s.

Hence

	$ echo -n "abcdefghijklmnopqrs" > /proc/self/comm

results in

	$ cat /proc/$$/comm
	pqrs

since the final four bytes were written with a second write() since
TASK_COMM_LEN == 16.  This is obviously an undesired result and not
equivalent to prctl(PR_SET_NAME).  The implementation should not need to
know the definition of TASK_COMM_LEN.

This patch truncates the string to the first TASK_COMM_LEN bytes and
returns the bytes written as the length of the string written so the
second write() is suppressed.

	$ cat /proc/$$/comm
	abcdefghijklmno

Signed-off-by: David Rientjes <rientjes@google.com>
Acked-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-30 17:04:07 -07:00
..
array.c kthread: Prevent unpark race which puts threads on the wrong cpu 2013-04-12 14:18:43 +02:00
base.c fs, proc: truncate /proc/pid/comm writes to first TASK_COMM_LEN bytes 2013-04-30 17:04:07 -07:00
cmdline.c
consoles.c
cpuinfo.c
devices.c
fd.c
fd.h
generic.c procfs: add proc_remove_subtree() 2013-04-09 14:09:17 -04:00
inode.c vfs,proc: guarantee unique inodes in /proc 2013-03-22 11:44:04 -07:00
internal.h mm, vmalloc: move get_vmalloc_info() to vmalloc.c 2013-04-29 15:54:33 -07:00
interrupts.c
Kconfig
kcore.c fs/proc/kcore.c: use register_hotmemory_notifier() 2013-04-29 15:54:36 -07:00
kmsg.c
loadavg.c
Makefile mm, vmalloc: move get_vmalloc_info() to vmalloc.c 2013-04-29 15:54:33 -07:00
meminfo.c mm, vmalloc: move get_vmalloc_info() to vmalloc.c 2013-04-29 15:54:33 -07:00
namespaces.c proc: Use nd_jump_link in proc_ns_follow_link 2013-03-09 00:14:45 -08:00
nommu.c
page.c
proc_devtree.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
proc_net.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
proc_sysctl.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
proc_tty.c
root.c userns: Restrict when proc and sysfs can be mounted 2013-03-27 07:50:08 -07:00
self.c
softirqs.c
stat.c
task_mmu.c
task_nommu.c
uptime.c
version.c
vmcore.c fs/proc/vmcore.c: put if tests in the top of the while loop to reduce duplication 2013-02-27 19:10:11 -08:00