Re: setuid(geteuid());?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: setuid(geteuid());?
Date: 2001-04-21 17:10:33
Message-ID: 200104211710.f3LHAXJ17578@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> That is a valid concern, but the code doesn't actually prevent this. I
> just tried
>
> chmod u+s postgres
> su -
> postmaster -D ...
>
> Then loaded the function
>
> #include <postgres.h>
>
> int32 touch(int32 a) {
> if (setuid(0) == -1)
> elog(ERROR, "setuid: %m");
> elog(DEBUG, "getuid = %d, geteuid = %d", getuid(), geteuid());
> system("touch /tmp/foofile");
> setuid(500); /* my own */
> return a + 1;
> }
>
> and the output was
>
> DEBUG: getuid = 0, geteuid = 0
>
> and I got a file /tmp/foofile owned by root.
>
> ISTM that the best way to prevent this exploit would be to check for both
> geteuid() == 0 and getuid() == 0 in main.c.

Peter, can you check your setuid manual page. Is there a mention of
special handling of saved-uid for root? I don't have it here on BSD/OS
but have heard of some os's that treat setuid differently for root.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2001-04-21 17:17:34 Re: setuid(geteuid());?
Previous Message Bruce Momjian 2001-04-21 17:08:53 Re: setuid(geteuid());?