All of lore.kernel.org
 help / color / mirror / Atom feed
From: Klaus Weidner <klaus@atsec.com>
To: Joshua Brindle <jbrindle@tresys.com>
Cc: Karl MacMillan <kmacmillan@mentalrootkit.com>,
	russell@coker.com.au, selinux@tycho.nsa.gov,
	Stephan Mueller <smueller@atsec.com>
Subject: Re: type transitioning script race condition?
Date: Thu, 31 Aug 2006 11:40:06 -0500	[thread overview]
Message-ID: <20060831164006.GE12307@w-m-p.com> (raw)
In-Reply-To: <1157040794.24429.116.camel@twoface.columbia.tresys.com>

On Thu, Aug 31, 2006 at 12:13:14PM -0400, Joshua Brindle wrote:
> The race is insignificant compared to the environment. The scripts
> cannot clean their own environment because the environment affects the
> interpreters potentially before the script is started (like PATH
> variables specific to the interpreter, or preload like PYTHONSTARTUP
> (run before the script is started).

perl has a couple of features to support suid execution, mainly the
"taint" mode which is activated automatically when it detects that it's
running setuid, and which can be specified on the #! line so that it's
activated race-free by the kernel. In that mode, it ignores variables
like PERLLIB automatically.

I'm not sure how Python handles it, and I'm not disagreeing with you in
general, it *is* very important to clean the environment and I think it's
safest to do this in the wrapper program.

> On Thu, 2006-08-31 at 10:46 -0500, Klaus Weidner wrote:
> > - other environment variables may be dangerous, for example program "foo"
> >   launched indirectly from the script may look at a FOORC variable to
> >   find its config file. In general it's safer to completely wipe the
> >   environment and only retain specific variables from a whitelist.
> 
> applications that use their own environment and are trusted within a
> specific domain are a non-issue, we already trust them to act
> appropriately within the confines we've given.

I think it's more dangerous than that - if you use a blacklist approach
to clean the environment, you're likely to miss variables which
indirectly affect things.

For example, say /usr/sbin/trustedapp is a shell script, and your wrapper
takes care to sanitize all environment variables that the shell cares
about (IFS, PATH, ...). But /usr/sbin/trustedapp contains a perl
one-liner, and you haven't sanitized PERLLIB, PERL5OPT, PERLDB_OPT etc,
so the trusted app ends up running user specified code at its current
privilege level due to that. You'd have to do a lot of analysis to find
all the potentially dangerous options, and it's a lot simpler to use a
whitelist.

> > - make sure that resource limits are reasonable. Another hack involved
> >   setting the max file size to a very low value and calling passwd(1),
> >   which then truncated /etc/shadow due to the limit.
> 
> not sure why this helps.

Well, this example is a denial of service, and I can't think of an
example how to use it to gain privileges, so I agree that it's probably
less critical. But it wouldn't surprise me if people find creative ways
to abuse such limits.

> > These things should be done for all suid/privileged programs, not just
> > scripts, because they may be using system(3) or equivalent to call a
> > program via the shell which could then get contaminated by $IFS or other
> > malicious settings.
> 
> privileged programs already handle this if they are binary (atsecure
> cleanses things that can affect the binary that are out of its control)

atsecure doesn't do anything to protect against indirect effects, for
example if the C app uses system(3) without cleaning IFS and PATH first,
so it's not sufficient to rely on the atsecure mechanism alone. You're
right that it's good protection against things out of the binary's
control, but it's important for it to do the security measures that are
under its control.

-Klaus

-Klaus

--
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:[~2006-08-31 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-30 22:39 type transitioning script race condition? Klaus Weidner
2006-08-30 23:18 ` Russell Coker
2006-08-31  3:12   ` Joshua Brindle
2006-08-31 13:23     ` Karl MacMillan
2006-08-31 13:53       ` Joshua Brindle
2006-08-31 15:29         ` Karl MacMillan
2006-08-31 15:41           ` Joshua Brindle
2006-08-31 16:02           ` Klaus Weidner
2006-08-31 16:39             ` Karl MacMillan
2006-08-31 17:19               ` Klaus Weidner
2006-08-31 20:02                 ` Karl MacMillan
2006-08-31 15:46         ` Klaus Weidner
2006-08-31 16:13           ` Joshua Brindle
2006-08-31 16:40             ` Klaus Weidner [this message]
2006-09-01 11:37           ` Stephen Smalley
2006-09-01 12:48         ` Russell Coker
2006-09-01 13:13           ` Joshua Brindle
2006-08-31 14:43     ` Stephen Smalley
2006-08-31 14:49       ` Joshua Brindle
2006-08-31 15:09         ` Stephen Smalley

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=20060831164006.GE12307@w-m-p.com \
    --to=klaus@atsec.com \
    --cc=jbrindle@tresys.com \
    --cc=kmacmillan@mentalrootkit.com \
    --cc=russell@coker.com.au \
    --cc=selinux@tycho.nsa.gov \
    --cc=smueller@atsec.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.