* [patch] Fix fileio.exp failuew when run as root user.
@ 2010-11-19 16:34 Phil Muldoon
2010-12-14 6:58 ` Joel Brobecker
2010-12-14 9:08 ` Yao Qi
0 siblings, 2 replies; 6+ messages in thread
From: Phil Muldoon @ 2010-11-19 16:34 UTC (permalink / raw)
To: gdb-patches
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.
2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/fileio.c (ROOTSUBDIR): New macro.
(main): CHDIR into ROOTSUBDIR. CHOWN ROOTSUBDIR and CHDIR into
ROOTSUBDIR if we are being run as root.
* gdb.base/fileio.exp: Change the startup and finish cleanup.
Change the test file reference to be into the `fileio.dir' directory.
--
diff --git a/gdb/testsuite/gdb.base/fileio.c b/gdb/testsuite/gdb.base/fileio.c
index 329522f..7c69d4c 100644
--- a/gdb/testsuite/gdb.base/fileio.c
+++ b/gdb/testsuite/gdb.base/fileio.c
@@ -58,6 +58,8 @@ system (const char * string);
1) Invalid string/command. - returns 127. */
static const char *strerrno (int err);
+#define ROOTSUBDIR "fileio.dir"
+
#define FILENAME "foo.fileio.test"
#define RENAMED "bar.fileio.test"
#define NONEXISTANT "nofoo.fileio.test"
@@ -542,6 +544,37 @@ strerrno (int err)
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);
+ }
+ }
+
/* Don't change the order of the calls. They partly depend on each other */
test_open ();
test_write ();
diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
index d6242d0..ddb853c 100644
--- a/gdb/testsuite/gdb.base/fileio.exp
+++ b/gdb/testsuite/gdb.base/fileio.exp
@@ -42,8 +42,8 @@ if [get_compiler_info ${binfile}] {
return -1;
}
-remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
-remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
+remote_exec build {sh -xc rm\ -rf\ fileio.dir}
+remote_exec build {sh -xc mkdir\ -m777\ fileio.dir}
set oldtimeout $timeout
set timeout [expr "$timeout + 60"]
@@ -85,7 +85,7 @@ gdb_test continue \
gdb_test "continue" ".*" ""
-catch "system \"chmod -f -w nowrt.fileio.test\""
+catch "system \"chmod -f -w fileio.dir/nowrt.fileio.test\""
gdb_test continue \
"Continuing\\..*open 5:.*EACCES$stop_msg" \
@@ -250,8 +250,8 @@ gdb_test continue \
send_gdb "quit\n"
send_gdb "y\n"
-remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test}
-remote_exec build {sh -xc rm\ -rf\ *.fileio.test}
+remote_exec build {sh -xc test\ -r\ fileio.dir/dir2.fileio.test\ &&\ chmod\ -f\ +w\ fileio.dir/dir2.fileio.test}
+remote_exec build {sh -xc rm\ -rf\ fileio.dir}
set timeout $oldtimeout
return 0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [patch] Fix fileio.exp failuew when run as root user.
2010-11-19 16:34 [patch] Fix fileio.exp failuew when run as root user Phil Muldoon
@ 2010-12-14 6:58 ` Joel Brobecker
2010-12-14 9:55 ` Pedro Alves
2010-12-14 9:08 ` Yao Qi
1 sibling, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2010-12-14 6:58 UTC (permalink / raw)
To: Phil Muldoon; +Cc: gdb-patches
> 2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> * gdb.base/fileio.c (ROOTSUBDIR): New macro.
> (main): CHDIR into ROOTSUBDIR. CHOWN ROOTSUBDIR and CHDIR into
> ROOTSUBDIR if we are being run as root.
> * gdb.base/fileio.exp: Change the startup and finish cleanup.
> Change the test file reference to be into the `fileio.dir' directory.
Did anyone comment on that patch? This looks OK to me.
(why would anyone want to run the testsuite as root, though???)
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Fix fileio.exp failuew when run as root user.
2010-12-14 6:58 ` Joel Brobecker
@ 2010-12-14 9:55 ` Pedro Alves
2010-12-15 5:12 ` Joel Brobecker
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2010-12-14 9:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker, Phil Muldoon
On Tuesday 14 December 2010 06:57:44, Joel Brobecker wrote:
> > 2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
> >
> > * gdb.base/fileio.c (ROOTSUBDIR): New macro.
> > (main): CHDIR into ROOTSUBDIR. CHOWN ROOTSUBDIR and CHDIR into
> > ROOTSUBDIR if we are being run as root.
> > * gdb.base/fileio.exp: Change the startup and finish cleanup.
> > Change the test file reference to be into the `fileio.dir' directory.
>
> Did anyone comment on that patch? This looks OK to me.
>
> (why would anyone want to run the testsuite as root, though???)
Note that this test is meant to test remote file io capabilities.
The fact that it runs on a native gdb is merely a way to give it
a bit more exposure against bitrot. We need to make sure to not
simply fail the test if the syscalls we're introducing are not supported
by remote file io (remote-fileio.c), and they fail on the
target (e.g., ENOSYS), and also that the test still compiles on
bare metal targets, with e.g., newlib (otherwise, the test becomes
useless). (The test was probably running on Windows/mingw as well,
but the "geteuid" call introduction is probably making it not compile
there anymore.)
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Fix fileio.exp failuew when run as root user.
2010-12-14 9:55 ` Pedro Alves
@ 2010-12-15 5:12 ` Joel Brobecker
2010-12-15 7:46 ` Phil Muldoon
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2010-12-15 5:12 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Phil Muldoon
> Note that this test is meant to test remote file io capabilities.
> The fact that it runs on a native gdb is merely a way to give it
> a bit more exposure against bitrot. We need to make sure to not
> simply fail the test if the syscalls we're introducing are not supported
> by remote file io (remote-fileio.c), and they fail on the
> target (e.g., ENOSYS), and also that the test still compiles on
> bare metal targets, with e.g., newlib (otherwise, the test becomes
> useless). (The test was probably running on Windows/mingw as well,
> but the "geteuid" call introduction is probably making it not compile
> there anymore.)
So, as it is, the fix doesn't meet those requirements and shouldn't
be applied, right? If that's the case, then perhaps the first question
is to figure out why someone is running the testsuite as root... Is
that a sysadmin who is building GDB as root?
I had checked that the new functions used are defined by POSIX,
but confess I never worried about Windows. Sorry.
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Fix fileio.exp failuew when run as root user.
2010-12-15 5:12 ` Joel Brobecker
@ 2010-12-15 7:46 ` Phil Muldoon
0 siblings, 0 replies; 6+ messages in thread
From: Phil Muldoon @ 2010-12-15 7:46 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Pedro Alves, gdb-patches
Joel Brobecker <brobecker@adacore.com> writes:
>> Note that this test is meant to test remote file io capabilities.
>> The fact that it runs on a native gdb is merely a way to give it
>> a bit more exposure against bitrot. We need to make sure to not
>> simply fail the test if the syscalls we're introducing are not supported
>> by remote file io (remote-fileio.c), and they fail on the
>> target (e.g., ENOSYS), and also that the test still compiles on
>> bare metal targets, with e.g., newlib (otherwise, the test becomes
>> useless). (The test was probably running on Windows/mingw as well,
>> but the "geteuid" call introduction is probably making it not compile
>> there anymore.)
>
> So, as it is, the fix doesn't meet those requirements and shouldn't
> be applied, right? If that's the case, then perhaps the first question
> is to figure out why someone is running the testsuite as root... Is
> that a sysadmin who is building GDB as root?
>
> I had checked that the new functions used are defined by POSIX,
> but confess I never worried about Windows. Sorry.
Jan wrote the patch and it was carried with our Fedora RPM patch set, so
I am going to surmise it is because of distribution build systems
running/testing as root.
I'll ping Jan and ask him to comment.
Cheers,
Phil
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Fix fileio.exp failuew when run as root user.
2010-11-19 16:34 [patch] Fix fileio.exp failuew when run as root user Phil Muldoon
2010-12-14 6:58 ` Joel Brobecker
@ 2010-12-14 9:08 ` Yao Qi
1 sibling, 0 replies; 6+ messages in thread
From: Yao Qi @ 2010-12-14 9:08 UTC (permalink / raw)
To: pmuldoon; +Cc: gdb-patches
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 (é½å°§)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-12-15 7:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-19 16:34 [patch] Fix fileio.exp failuew when run as root user 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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox