9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] git: use new /dev/drivers for privdrop
Date: Sat, 28 May 2022 12:51:22 -0400	[thread overview]
Message-ID: <B5973797B8A9E12627CD8864FA2009CD@eigenstate.org> (raw)

This needs to be held off for a bit, but it seems
like a good idea: we shouldn't need any devices at
all for this code, so let's not keep them.

ddiff 01a6de812c2fd38c9a28036300e3c2c7dc8441f5 uncommitted
--- a/sys/src/cmd/git/serve.c
+++ b/sys/src/cmd/git/serve.c
@@ -5,7 +5,7 @@
 
 #include "git.h"
 
-char	*pathpfx = nil;
+char	*pathpfx = "/";
 int	allowwrite;
 
 int
@@ -469,6 +469,22 @@
 	return 0;
 }
 
+void
+privdrop(void)
+{
+	int fd;
+
+	if(rfork(RFNAMEG) == -1)
+		sysfatal("rfork: %r");
+	if((fd = open("#c/drivers", OWRITE)) == -1)
+		sysfatal("open drivers: %r");
+	if(bind(pathpfx, "/", MREPL) == -1)
+		sysfatal("bind: %r");
+	if(write(fd, "chdev &", strlen("chdev &")) == -1)
+		sysfatal("drop permissions: %r");
+	close(fd);
+}
+
 char*
 parsecmd(char *buf, char *cmd, int ncmd)
 {
@@ -518,15 +534,8 @@
 	}ARGEND;
 
 	gitinit();
+	privdrop();
 	interactive = 0;
-	if(rfork(RFNAMEG) == -1)
-		sysfatal("rfork: %r");
-	if(pathpfx != nil){
-		if(bind(pathpfx, "/", MREPL) == -1)
-			sysfatal("bind: %r");
-	}
-	if(rfork(RFNOMNT) == -1)
-		sysfatal("rfork: %r");
 
 	initconn(&c, 0, 1);
 	if(readpkt(&c, buf, sizeof(buf)) == -1)


             reply	other threads:[~2022-05-28 16:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28 16:51 ori [this message]
2022-05-28 19:23 ` unobe
2022-05-28 19:41   ` ori
2022-05-28 22:54     ` Jacob Moody
2022-05-29  0:23       ` Frank D. Engel, Jr.
2022-05-29  1:00         ` Jacob Moody
2022-05-28 21:47 ` covertusername967
2022-05-28 22:07   ` ori
2022-05-28 23:24     ` adr

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=B5973797B8A9E12627CD8864FA2009CD@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --subject='Re: [9front] git: use new /dev/drivers for privdrop' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).