From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25254 invoked by alias); 8 Dec 2007 18:14:35 -0000 Received: (qmail 25246 invoked by uid 22791); 8 Dec 2007 18:14:34 -0000 X-Spam-Check-By: sourceware.org Received: from pauline.vellum.cz (HELO pauline.vellum.cz) (89.250.243.234) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 08 Dec 2007 18:14:28 +0000 Received: from host0.dyn.jankratochvil.net (localhost.localdomain [127.0.0.1]) by pauline.vellum.cz (8.12.11.20060308/8.12.11) with ESMTP id lB8IEN79005151 for ; Sat, 8 Dec 2007 19:14:24 +0100 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.2/8.14.1) with ESMTP id lB8IENZB010313 for ; Sat, 8 Dec 2007 19:14:23 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.2/8.14.2/Submit) id lB8IEMLn010312 for gdb-patches@sourceware.org; Sat, 8 Dec 2007 19:14:22 +0100 Date: Sat, 08 Dec 2007 18:58:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] fileio.exp FAILs if run as root Message-ID: <20071208181422.GA10275@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00136.txt.bz2 --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 249 Hi, if you run gdb.base/fileio.exp as UID 0 it will print: 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 Regards, Jan --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="gdb-test-fileio-root.patch" Content-length: 3063 2007-12-08 Jan Kratochvil * 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. --- ./gdb/testsuite/gdb.base/fileio.c 13 Jun 2006 08:55:22 -0000 1.10 +++ ./gdb/testsuite/gdb.base/fileio.c 8 Dec 2007 16:04:10 -0000 @@ -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 (); --- ./gdb/testsuite/gdb.base/fileio.exp 23 Aug 2007 18:14:16 -0000 1.12 +++ ./gdb/testsuite/gdb.base/fileio.exp 8 Dec 2007 16:04:10 -0000 @@ -46,8 +46,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"] @@ -88,7 +88,7 @@ gdb_test continue \ "Opening nonexistant file returns ENOENT" send_gdb "continue\n" ; gdb_expect -re "$gdb_prompt $" -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" \ @@ -252,8 +252,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 --azLHFNyN32YCQGCU--