Skip to contentSkip to conversation

run_init and chdir()

DISCUSSION Russell Coker 2 participants 3 messages May 7, 2002 – May 14, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

Would it make sense to have run_init do "chdir /" before executing it's program?

It's annoying when you accidentally execute a daemon with a current directory that it can't read...

Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines
of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 2 lines · Russell Coker

Would it make sense to have run_init do "chdir /" before executing it's program?

Probably. We could have it call daemon(0,1) prior to the execvp_secure call.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
In reply to Russell Coker
Quoted 5 lines · Russell Coker

Would it make sense to have run_init do "chdir /" before executing it's program?

It's annoying when you accidentally execute a daemon with a current directory that it can't read...

Patch attached, and committed to the sourceforge CVS tree.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: utils/run_init/run_init.c
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/utils/run_init/run_init.c,v retrieving revision 1.1.1.2
retrieving revision 1.3

run_init/run_init.c +5 -0
diff -u -r1.1.1.2 -r1.3
@@ -381,6 +381,11 @@
    * Step 4: Run the command in the correct context.
    */
 
+  if (chdir("/")) {
+	  perror("chdir");
+	  exit(-1);
+  }
+
   if ( execvp_secure(argv[1], sid, argv + 1) ) {
     perror("execvp_secure");
     exit(-1);