All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel J Walsh <dwalsh@redhat.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: David Howells <dhowells@redhat.com>,
	serge.hallyn@canonical.com, eparis@redhat.com,
	linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov
Subject: Re: [PATCH 0/9] Open loaders and interpreters with new creds during exec
Date: Thu, 21 Apr 2011 12:30:17 -0400	[thread overview]
Message-ID: <4DB05B99.9060303@redhat.com> (raw)
In-Reply-To: <1303402367.5381.17.camel@moss-pluto>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/21/2011 12:12 PM, Stephen Smalley wrote:
> On Thu, 2011-04-21 at 15:30 +0100, David Howells wrote:
>> Currently, the caller must be able to open the script interpreter and/or the
>> binary loader that an executable wants to make use of, even if the executable
>> will be transitioned to a different context that can make use of that
>> interpreter or loader when the caller's context does not permit it.
>>
>> Override credentials in open_exec() and kernel_read() with the currently
>> constructed new credentials so that if the executable file or its interpreter
>> specifies a transition to a different security context (DAC or MAC), then the
>> caller only has to provide access to the file to be executed, and not to the
>> interpreter (e.g. perl) or binary loader (e.g. ld.so) for the executable or
>> interpreter.
>>
>> This means that if the caller does not have access to a script interpreter or
>> binary loader, it can still use scripts and executables that transition to a
>> security context that do.
>>
>> Tetsuo Handa pointed out that TOMOYO had a problem because the loader image
>> (such as ld-config.so) was checked with the wrong credentials (open_exec() is
>> using the caller's credentials rather than credentials-to-be of the exec'd
>> process.
>>
>> I note that this also applies to scripts and their interpreters.  A script may
>> end up getting run in a context that allows access to its interpreter, but
>> that's no good if the caller of execve() doesn't permit the script interpreter
>> to be opened.
>>
>> Here's a set of patches to deal with this.  The last patch is the main
>> ingredient.
>>
>>
>> I have a couple of comments/questions on the above:
>>
>>  (1) Consider a SUID binary.  If the loader for that binary is executable by
>>      the uid to which the binary changes its uid on execution, but not by the
>>      uid of the caller, should execution succeed?
>>
>>      For example, if, as root, I do this:
>>
>> 	cp -v /bin/ls /tmp/ls
>> 	perl -p -i -e s/ld-linux/ld-linuQ/ /tmp/ls
>> 	cp -v /lib64/ld-linux-x86-64.so.2 /lib64/ld-linuQ-x86-64.so.2
>> 	chmod -v 0700 /lib64/ld-linuQ-x86-64.so.2
>>
>>      then as myself do this:
>>
>> 	/tmp/ls
>>
>>      this currently fails with permission denied; but with patch (5) above
>>      applied, it works.  Obviously, this is a contrived example, but it also
>>      may applies to script interpreters if an LSM provides a security ID
>>      transition.
>>
>>  (2) Conversely, if the loader is not executable by the uid to which an SUID
>>      executable switches, should that execution succeed?
>>
>>      So if I alter the ownership and permissions on the above binaries:
>>
>> 	chown -v dhowells /lib64/ld-linuQ-x86-64.so.2
>> 	chown -v bin /tmp/ls
>> 	chmod u+s /tmp/ls
>>
>>      then as myself do:
>>
>> 	/tmp/ls
>>
>>      this works with patches removed and gives permission denied with it
>>      applied.
>>
>>  (3) The SUID/SGID changes from patch 5 that I've noted in comments (1) and (2)
>>      should, I think, have no impact on the execution environment because:
>>
>> 	(*) loaders and interpreters are normally accessible to everyone in
>> 	    their DAC permissions (UID, GID, umask), and
>>
>> 	(*) recursing through prepare_binprm() multiple times only takes
>> 	    account of the SUID/SGID settings of the final level (which means
>> 	    that whilst you can have a SUID/SGID interpreter, you can't have a
>> 	    SUID/SGID script).
>>
>> 	    An exception to this are binfmt_misc cases that have
>> 	    MISC_FMT_CREDENTIALS flagged - in those the credentials remain
>> 	    unchanged for the iteration, even if the next executable is
>> 	    SUID/SGID.
>>
>>  (4) SELinux's testsuite needs the following additional rules:
>>
>> 	[policy/test_ptrace.te]
>> 	allow test_ptrace_traced_t bin_t:file { execute read open };
>>
>> 	[policy/test_file.te]
>> 	allow fileop_t fileop_exec_t:file { execute read open };
>>
>>      to permit the ptrace test to access its script interpreter (perl) and the
>>      SIGIO file test's wait_io program to access its own executable.
> 
> This is an interesting change, but as it does change user-visible
> behavior, does it need to be subject to some /proc/sys/kernel toggle so
> that users can retain the existing behavior?  And does at least the SUID
> behavior change require discussion on lkml?
> 
Could we use this change to prevent the execution of scripts in the
homedir?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk2wW5kACgkQrlYvE4MpobMHZACgwrHyHF9hzs0lAhftf9D0Gy/W
oKUAoMXxECkganLDs2RLsauufNCz9R6i
=82tP
-----END PGP SIGNATURE-----

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2011-04-21 16:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-21 14:30 [PATCH 0/9] Open loaders and interpreters with new creds during exec David Howells
2011-04-21 14:30 ` [PATCH 1/9] TOMOYO: Fix tomoyo_dentry_open() to use the right creds David Howells
2011-04-21 14:30 ` [PATCH 2/9] TOMOYO: Derive the new domain for an exec'd process in tomoyo_bprm_set_creds() David Howells
2011-04-21 14:30 ` [PATCH 3/9] LSM: Permit commit_creds() to take a const pointer David Howells
2011-04-21 14:30 ` [PATCH 4/9] LSM: Make the linux_binfmt creds pointer const and pass creds to bprm_set_creds David Howells
2011-04-21 14:30 ` [PATCH 5/9] LSM: Install the new credentials earlier in the exec procedure David Howells
2011-04-21 14:31 ` [PATCH 6/9] LSM: Pass linux_binprm pointer to kernel_read() so creds are available David Howells
2011-04-21 14:31 ` [PATCH 7/9] LSM: Allow an LSM to indicate that it wants bprm->file reopening with new creds David Howells
2011-04-21 14:31 ` [PATCH 8/9] LSM: Pass linux_binprm pointer to open_exec() so creds are available David Howells
     [not found]   ` <201104220225.p3M2PjJR020777@www262.sakura.ne.jp>
2011-04-28 15:27     ` David Howells
2011-04-21 14:31 ` [PATCH 9/9] LSM: Use derived creds for accessing an executable's interpreter and binary loader David Howells
2011-04-21 16:12 ` [PATCH 0/9] Open loaders and interpreters with new creds during exec Stephen Smalley
2011-04-21 16:30   ` Daniel J Walsh [this message]
2011-04-21 17:32 ` Casey Schaufler
2011-04-21 18:13   ` David Howells
2011-04-21 18:53 ` David Howells
     [not found] ` <20110428200218.GB9186@hallyn.com>
2011-04-30 10:48   ` David Howells
2011-05-02 13:28     ` Stephen Smalley
2011-05-04 12:12   ` David Howells
2011-05-04 13:15     ` David Howells
     [not found]     ` <20110504144558.GC917@mail.hallyn.com>
2011-05-04 16:27       ` David Howells

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=4DB05B99.9060303@redhat.com \
    --to=dwalsh@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=eparis@redhat.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    --cc=serge.hallyn@canonical.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.