mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Daily reports: Friday (threaded setuid testing)
Date: Sun, 10 Jul 2011 10:52:01 -0400	[thread overview]
Message-ID: <20110710145201.GB133@brightrain.aerifal.cx> (raw)
In-Reply-To: <20110709115301.GA6510@openwall.com>

On Sat, Jul 09, 2011 at 03:53:01PM +0400, Solar Designer wrote:
> Luka, Rich -
> 
> On Sat, Jul 09, 2011 at 12:41:02AM +0200, Luka Mar??eti?? wrote:
> > I wanted to move on to task number 8, but I had some questions. I asked 
> > Rich via XMPP about them, but I guess he's still out.
> 
> OK, let's wait for Rich's comments on this.  BTW, chances are that the
> RLIMIT_NPROC check on setuid(2) and friends will be removed from future
> kernels: http://www.openwall.com/lists/kernel-hardening/2011/07/06/8

I wonder if I should jump in that thread and mention that, even if the
application checks the return value of setuid, it can be wrong for
multi-threaded applications... Or at least I believe it can. I think
proving that it can be wrong with glibc would still be a really nice
task to get done in cluts, and it would establish the usefulness of
cluts to the community outside of just advancing musl towards 1.0.

Luka, to answer your questions from chat:

1. Yes, an otherwise-unused account (actually just uid number; it
doesn't need any files, homedir, etc.) is required for testing. This
should be configurable eventually, but hard-coding some oddball value
near the max uid would probably be sufficient for now.

2. An ordinary user can lower their RLIMIT_NPROCS, but you'll be doing
this before dropping root, not after.

3. Each thread does not need to call setuid (the library function);
rather setuid (the library function itself) jumps through hoops to
make every thread call the setuid syscall. The unfortunate situation
is that each thread's syscall can independently succeed or fail, and
glibc only reports the status of one of them (the last one, I believe,
which is also the thread that called the setuid library function).

4. Your goal (at least for catching the bug believed to exist in glibc
and which musl hopefully does not shared) is to cause some of the
setuid syscalls to fail, but the last one to succeed. This will
require very [un]lucky timing, so the test probably needs to run many
times.

- RLIMIT_NPROCS should be greater than the number of threads you'll be
  testing with.

- When setuid (the library function) is first called, the number of
  processes with the target uid should already be equal (or just
  under) RLIMIT_NPROCS due to having forked some children in advance
  and set their uid to the target uid.

- These children should attempt to terminate themselves after the
  parent (with all its threads) calls setuid, but before all threads
  get scheduled and have a chance to make the setuid syscall. This
  way, some threads may fail, but the last one should succeed.

- After setuid (library function) returns, you check its return value
  and have each thread call getuid to check that they all have the
  target uid or that the library function returned failure. If the
  library function returned success but some threads still have uid=0,
  this is a potentially-serious security bug.

Does this make sense? By the way, there's no exact science to when the
children should terminate. The best I can think of is to run the test
repeatedly with varying (extremely short) delays, probably just
spinning in userspace or making a single call to sched_yield. You
might also want to vary the number of threads, and note that it may be
easier or harder with the number very small (e.g. equal to the number
of cores).

> I understand that Rich's proposed tests are about the libc wrapper
> functions that are thread-aware rather than about syscalls, yet I felt
> the above was relevant to the tests.

If the syscalls were correct (process-global) it would be a non-issue,
and if they could not fail due to RLIMIT_NPROC, it would also be a
non-issue. But as the kernel currently works (or rather doesn't work),
the userspace has to put a lot of effort into changing uids safely...

Rich


  parent reply	other threads:[~2011-07-10 14:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05  0:41 Daily reports: Monday Luka Marčetić
2011-07-05 14:24 ` Daily reports: Tuesday Luka Marčetić
2011-07-06 20:28   ` Daily reports: Wednesday Luka Marčetić
2011-07-07 16:18     ` Szabolcs Nagy
2011-07-07 20:27       ` Luka Marčetić
2011-07-07 20:16     ` Daily reports: Thursday Luka Marčetić
2011-07-08 22:41       ` Daily reports: Friday Luka Marčetić
2011-07-09  1:12         ` Daily reports: Friday - cont Luka Marčetić
2011-07-09  1:38           ` Solar Designer
2011-07-09 11:53         ` Daily reports: Friday Solar Designer
2011-07-09 15:30           ` Luka Marčetić
2011-07-09 22:11             ` Luka Marčetić
2011-07-13 19:46             ` Solar Designer
2011-07-10 14:52           ` Rich Felker [this message]
2011-07-11 22:59             ` Daily cluts reports Luka Marčetić
2011-07-14  9:57               ` cluts: strerror_r() test (was: Daily cluts reports) Solar Designer
2011-07-14 10:41                 ` cluts: strerror_r() test Luka Marčetić
2011-07-14 10:47                   ` Solar Designer
2011-07-14 17:55                   ` Rich Felker
2011-07-14 19:35                     ` Luka Marčetić
2011-07-15  0:09               ` Daily cluts reports Luka Marčetić
2011-07-15 22:47                 ` Daily cluts reports - numeric, setuid, and mid-term evaluation Luka Marčetić
2011-07-15 23:51                   ` Rich Felker
2011-07-17  0:37                   ` Daily cluts reports - setuid reiteration Luka Marčetić

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=20110710145201.GB133@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).