mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Paul Moore" <paul@paul-moore.com>,
	"James Morris" <james.l.morris@oracle.com>,
	"Stephen Smalley" <sds@tycho.nsa.gov>
Subject: [PATCH 3.16 06/12] selinux: fix off-by-one in setprocattr
Date: Fri, 24 Feb 2017 12:10:01 +0000	[thread overview]
Message-ID: <lsq.1487938201.827610032@decadent.org.uk> (raw)
In-Reply-To: <lsq.1487938201.529166958@decadent.org.uk>

3.16.41-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Stephen Smalley <sds@tycho.nsa.gov>

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.

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: James Morris <james.l.morris@oracle.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 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--;

  parent reply	other threads:[~2017-02-24 13:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 12:10 [PATCH 3.16 00/12] 3.16.41-rc1 review Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 12/12] tcp: avoid infinite loop in tcp_splice_read() Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 09/12] ip6_gre: fix ip6gre_err() invalid reads Ben Hutchings
2017-02-24 12:10 ` Ben Hutchings [this message]
2017-02-24 12:10 ` [PATCH 3.16 08/12] tmpfs: clear S_ISGID when setting posix ACLs Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 07/12] USB: serial: kl5kusb105: fix line-state error handling Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 03/12] ext4: validate s_first_meta_bg at mount time Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 01/12] mnt: Add a per mount namespace limit on the number of mounts Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 02/12] kvm: nVMX: Allow L1 to intercept software exceptions (#BP and #OF) Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 05/12] KVM: x86: Introduce segmented_write_std Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 04/12] KVM: x86: fix emulation of "MOV SS, null selector" Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 10/12] ipv4: keep skb->dst around in presence of IP options Ben Hutchings
2017-02-24 12:10 ` [PATCH 3.16 11/12] dccp: fix freeing skb too early for IPV6_RECVPKTINFO Ben Hutchings
2017-02-24 16:19 ` [PATCH 3.16 00/12] 3.16.41-rc1 review Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lsq.1487938201.827610032@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=james.l.morris@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome