android_kernel_google_msm/security
Stephen Smalley ad0f565471 selinux: fix off-by-one in setprocattr
commit 0c461cb727d146c9ef2d3e86214f498b78b7d125 upstream.

SELinux tries to support setting/clearing of /proc/pid/attr attributes
from the shell by ignoring terminating newlines and treating an
attribute value that begins with a NUL or newline as an attempt to
clear the attribute.  However, the test for clearing attributes has
always been wrong; it has an off-by-one error, and this could further
lead to reading past the end of the allocated buffer since commit
bb646cdb12e75d82258c2f2e7746d5952d3e321a ("proc_pid_attr_write():
switch to memdup_user()").  Fix the off-by-one error.

Even with this fix, setting and clearing /proc/pid/attr attributes
from the shell is not straightforward since the interface does not
support multiple write() calls (so shells that write the value and
newline separately will set and then immediately clear the attribute,
requiring use of echo -n to set the attribute), whereas trying to use
echo -n "" to clear the attribute causes the shell to skip the
write() call altogether since POSIX says that a zero-length write
causes no side effects. Thus, one must use echo -n to set and echo
without -n to clear, as in the following example:
$ echo -n unconfined_u:object_r:user_home_t:s0 > /proc/$$/attr/fscreate
$ cat /proc/$$/attr/fscreate
unconfined_u:object_r:user_home_t:s0
$ echo "" > /proc/$$/attr/fscreate
$ cat /proc/$$/attr/fscreate

Note the use of /proc/$$ rather than /proc/self, as otherwise
the cat command will read its own attribute value, not that of the shell.

There are no users of this facility to my knowledge; possibly we
should just get rid of it.

UPDATE: Upon further investigation it appears that a local process
with the process:setfscreate permission can cause a kernel panic as a
result of this bug.  This patch fixes CVE-2017-2618.

Change-Id: I646d6db150ae470b25cade2d8442199fb133f8dc
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: added the update about CVE-2017-2618 to the commit description]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
2017-07-04 01:23:13 +03:00
..
apparmor nick kvfree() from apparmor 2014-11-18 15:13:23 -08:00
integrity
keys KEYS: Disallow keyrings beginning with '.' to be joined as session keyrings 2017-06-26 21:32:46 +03:00
selinux selinux: fix off-by-one in setprocattr 2017-07-04 01:23:13 +03:00
smack consitify do_mount() arguments 2015-07-13 11:17:52 -07:00
tomoyo consitify do_mount() arguments 2015-07-13 11:17:52 -07:00
yama
capability.c consitify do_mount() arguments 2015-07-13 11:17:52 -07:00
commoncap.c Add PR_{GET,SET}_NO_NEW_PRIVS to prevent execve from granting privs 2014-10-31 19:46:07 -07:00
device_cgroup.c
inode.c
Kconfig FROMLIST: security,perf: Allow further restriction of perf_event_open 2016-06-20 19:00:29 +00:00
lsm_audit.c security: lsm_audit: add ioctl specific auditing 2015-04-20 09:42:31 -07:00
Makefile
min_addr.c
security.c consitify do_mount() arguments 2015-07-13 11:17:52 -07:00