9front - general discussion about 9front
 help / color / mirror / Atom feed
From: unobe@cpan.org
To: 9front@9front.org
Subject: Re: [9front] git: use new /dev/drivers for privdrop
Date: Sat, 28 May 2022 12:23:59 -0700	[thread overview]
Message-ID: <6D0CAE9C3EDDCF15EF90F526821E14E6@smtp.pobox.com> (raw)
In-Reply-To: <B5973797B8A9E12627CD8864FA2009CD@eigenstate.org>

In general, how does one restrict computation/process limitations?  I
am admittedly ignorant, so if anyone has docs for me to read instead
of replying that what I want to do is already solved or is a waste of
time I'd appreciate it.

I see proc(3) describes each process's status file as containing the
user, amount of memory, and scheduling priority.  So for unnecessary
churn and limiting fork bombs, is the idea to have a monitor that
watches the interested values (e.g.  memory or number of processes)
for a user, and kill if a certain amount has been reached?

For example, say I want a sandboxing area for people to "try 9front".
With moody's recent work, it removes a big attack vector by
restricting certain drivers.  But isn't it still possible to fork-bomb
a server, or to just cause unnecessary churn (i.e., computation), or
just open too many files, or fill a disk?

To address the "fill a disk" scenario, I assume the best thing is to
create a temporary disk that is used by the process which is provided
to the test user--they'll only have so much space to work with.  If
there's no space to allocate for the new temporary disk, it's easy
enough to stop the process from starting.  Disk-resizing would be
neat, but I don't care about that to start.

Quoth ori@eigenstate.org:
> 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 19:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28 16:51 ori
2022-05-28 19:23 ` unobe [this message]
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=6D0CAE9C3EDDCF15EF90F526821E14E6@smtp.pobox.com \
    --to=unobe@cpan.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).