[linux] 05/08: selinux: fix off-by-one in setprocattr (CVE-2017-2618)

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Tue Feb 21 03:08:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch jessie-security
in repository linux.

commit 4acd7cd3db4413d765e7a54415b1a82a603e1af3
Author: Ben Hutchings <ben at decadent.org.uk>
Date:   Tue Feb 21 01:57:57 2017 +0000

    selinux: fix off-by-one in setprocattr (CVE-2017-2618)
---
 debian/changelog                                   |  1 +
 .../selinux-fix-off-by-one-in-setprocattr.patch    | 61 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 3 files changed, 63 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 14ea463..300b820 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,7 @@ linux (3.16.39-1+deb8u1) UNRELEASED; urgency=medium
     (CVE-2016-919)
   * [x86] KVM: fix emulation of "MOV SS, null selector" (CVE-2017-2583)
   * [x86] KVM: Introduce segmented_write_std (CVE-2017-2584)
+  * selinux: fix off-by-one in setprocattr (CVE-2017-2618)
 
  -- Salvatore Bonaccorso <carnil at debian.org>  Sat, 18 Feb 2017 18:26:58 +0100
 
diff --git a/debian/patches/bugfix/all/selinux-fix-off-by-one-in-setprocattr.patch b/debian/patches/bugfix/all/selinux-fix-off-by-one-in-setprocattr.patch
new file mode 100644
index 0000000..ef41f77
--- /dev/null
+++ b/debian/patches/bugfix/all/selinux-fix-off-by-one-in-setprocattr.patch
@@ -0,0 +1,61 @@
+From: Stephen Smalley <sds at tycho.nsa.gov>
+Date: Tue, 31 Jan 2017 11:54:04 -0500
+Subject: selinux: fix off-by-one in setprocattr
+Origin: https://git.kernel.org/linus/0c461cb727d146c9ef2d3e86214f498b78b7d125
+Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2017-2618
+
+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.
+
+Signed-off-by: Stephen Smalley <sds at tycho.nsa.gov>
+[PM: added the update about CVE-2017-2618 to the commit description]
+Cc: stable at vger.kernel.org # 3.5: d6ea83ec6864e
+Signed-off-by: Paul Moore <paul at paul-moore.com>
+
+Signed-off-by: James Morris <james.l.morris at oracle.com>
+---
+ security/selinux/hooks.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/security/selinux/hooks.c
++++ b/security/selinux/hooks.c
+@@ -5546,7 +5546,7 @@ static int selinux_setprocattr(struct ta
+ 		return error;
+ 
+ 	/* Obtain a SID for the context, if one was specified. */
+-	if (size && str[1] && str[1] != '\n') {
++	if (size && str[0] && str[0] != '\n') {
+ 		if (str[size-1] == '\n') {
+ 			str[size-1] = 0;
+ 			size--;
diff --git a/debian/patches/series b/debian/patches/series
index 2a51457..4f5034e 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -688,6 +688,7 @@ bugfix/all/fbdev-color-map-copying-bounds-checking.patch
 bugfix/all/sysctl-drop-reference-added-by-grab_header-in-proc_sys_readdir.patch
 bugfix/x86/kvm-x86-fix-emulation-of-mov-ss-null-selector.patch
 bugfix/x86/kvm-x86-introduce-segmented_write_std.patch
+bugfix/all/selinux-fix-off-by-one-in-setprocattr.patch
 
 # Fix ABI changes
 debian/of-fix-abi-changes.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/linux.git



More information about the Kernel-svn-changes mailing list