From: Yao Qi <yao@codesourcery.com>
To: pmuldoon@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Fix fileio.exp failuew when run as root user.
Date: Tue, 14 Dec 2010 09:08:00 -0000 [thread overview]
Message-ID: <4D073407.7070602@codesourcery.com> (raw)
In-Reply-To: <m3bp5ll1c5.fsf@redhat.com>
On 11/20/2010 12:34 AM, Phil Muldoon wrote:
>
> This patch has been carried in the Fedora RPM since 6.8. We are
> submitting it for inclusion upstream.
>
> gdb.base/fileio.exp|c fail when this test is executed as a root. This
> test fixes that.
I don't have Fedora system on hand, but I can reproduce this problem on
Ubuntu with 'sudo make check RUNTESTFLAGS="fileio.exp"', and get
following two fails.
FAIL: gdb.base/fileio.exp: Open for write but no write permission
returns EACCES
FAIL: gdb.base/fileio.exp: Unlinking a file in a directory w/o write
access returns EACCES
If they are what you want to fix in this patch, here is one cent,
> int
> main ()
> {
> + /* ROOTSUBDIR is already prepared by fileio.exp. We use it for easy cleanup
> + (by fileio.exp) if we are run by multiple users in the same directory. */
> +
> + if (chdir (ROOTSUBDIR) != 0)
> + {
> + printf ("chdir " ROOTSUBDIR ": %s\n", strerror (errno));
> + exit (1);
> + }
> +
> + /* These tests
> + Open for write but no write permission returns EACCES
> + Unlinking a file in a directory w/o write access returns EACCES
> + fail if we are being run as root - drop the privileges here. */
> +
> + if (geteuid () == 0)
> + {
> + uid_t uid = 99;
> +
> + if (chown (".", uid, uid) != 0)
> + {
> + printf ("chown %d.%d " ROOTSUBDIR ": %s\n", (int) uid, (int) uid,
> + strerror (errno));
> + exit (1);
> + }
> + if (setuid (uid) || geteuid () == 0)
> + {
> + printf ("setuid %d: %s\n", (int) uid, strerror (errno));
> + exit (1);
> + }
> + }
> +
We can extract these code into a separate function, and replace
"exit(1)" by "return 1".
/* Try to drop root privileges of this process. Return 0 if it is done
successfully, otherwise return non-zero. */
int try_drop_root_privilege()
{
....
}
int
main ()
{
if (try_drop_root_privilege())
{
exit (1);
}
...
...
}
--
Yao (é½å°§)
prev parent reply other threads:[~2010-12-14 9:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-19 16:34 Phil Muldoon
2010-12-14 6:58 ` Joel Brobecker
2010-12-14 9:55 ` Pedro Alves
2010-12-15 5:12 ` Joel Brobecker
2010-12-15 7:46 ` Phil Muldoon
2010-12-14 9:08 ` Yao Qi [this message]
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=4D073407.7070602@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=pmuldoon@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox