aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/sysctl
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2014-06-06 17:37:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-06 19:08:13 -0400
commitf4aacea2f5d1a5f7e3154e967d70cf3f711bcd61 (patch)
tree6706ce16774c72bcbb33e4872b4913731349cb13 /Documentation/sysctl
parent2ca9bb456ada8bcbdc8f77f8fc78207653bbaa92 (diff)
sysctl: allow for strict write position handling
When writing to a sysctl string, each write, regardless of VFS position, begins writing the string from the start. This means the contents of the last write to the sysctl controls the string contents instead of the first: open("/proc/sys/kernel/modprobe", O_WRONLY) = 1 write(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 4096) = 4096 write(1, "/bin/true", 9) = 9 close(1) = 0 $ cat /proc/sys/kernel/modprobe /bin/true Expected behaviour would be to have the sysctl be "AAAA..." capped at maxlen (in this case KMOD_PATH_LEN: 256), instead of truncating to the contents of the second write. Similarly, multiple short writes would not append to the sysctl. The old behavior is unlike regular POSIX files enough that doing audits of software that interact with sysctls can end up in unexpected or dangerous situations. For example, "as long as the input starts with a trusted path" turns out to be an insufficient filter, as what must also happen is for the input to be entirely contained in a single write syscall -- not a common consideration, especially for high level tools. This provides kernel.sysctl_writes_strict as a way to make this behavior act in a less surprising manner for strings, and disallows non-zero file position when writing numeric sysctls (similar to what is already done when reading from non-zero file positions). For now, the default (0) is to warn about non-zero file position use, but retain the legacy behavior. Setting this to -1 disables the warning, and setting this to 1 enables the file position respecting behavior. [akpm@linux-foundation.org: fix build] [akpm@linux-foundation.org: move misplaced hunk, per Randy] Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation/sysctl')
-rw-r--r--Documentation/sysctl/kernel.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 9886c3d57fc2..708bb7f1b7e0 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -77,6 +77,7 @@ show up in /proc/sys/kernel:
77- shmmni 77- shmmni
78- stop-a [ SPARC only ] 78- stop-a [ SPARC only ]
79- sysrq ==> Documentation/sysrq.txt 79- sysrq ==> Documentation/sysrq.txt
80- sysctl_writes_strict
80- tainted 81- tainted
81- threads-max 82- threads-max
82- unknown_nmi_panic 83- unknown_nmi_panic
@@ -762,6 +763,26 @@ without users and with a dead originative process will be destroyed.
762 763
763============================================================== 764==============================================================
764 765
766sysctl_writes_strict:
767
768Control how file position affects the behavior of updating sysctl values
769via the /proc/sys interface:
770
771 -1 - Legacy per-write sysctl value handling, with no printk warnings.
772 Each write syscall must fully contain the sysctl value to be
773 written, and multiple writes on the same sysctl file descriptor
774 will rewrite the sysctl value, regardless of file position.
775 0 - (default) Same behavior as above, but warn about processes that
776 perform writes to a sysctl file descriptor when the file position
777 is not 0.
778 1 - Respect file position when writing sysctl strings. Multiple writes
779 will append to the sysctl value buffer. Anything past the max length
780 of the sysctl value buffer will be ignored. Writes to numeric sysctl
781 entries must always be at file position 0 and the value must be
782 fully contained in the buffer sent in the write syscall.
783
784==============================================================
785
765tainted: 786tainted:
766 787
767Non-zero if the kernel has been tainted. Numeric values, which 788Non-zero if the kernel has been tainted. Numeric values, which