www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/01/22/09:44:37

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 60MEia0p2146109
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 60MEia0p2146109
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Izcw4JX4
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 771784BA9035
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1769093075;
bh=JVs1QOJdsxOYNaJHdzhfqoVIvPPCrDijc6paerS95CQ=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=Izcw4JX4d5ni4piYKr5KtjDdPAGnDkQmCxiFzRcDtKPdOS9fBCBv4/1bah/NXKXPY
9qPxXB4YOp48HxCYZi6DdoW+xwCyQ4r0t7idsixmjM7msuZvelOPshkdZj3rTzZ9al
Rqi1TopV9TUB25YLSg5+u0Q7gxHWCr4HNbzfzTGo=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37A514BA2E2F
Date: Thu, 22 Jan 2026 15:43:46 +0100
To: cygwin AT cygwin DOT com
Subject: Re: Fork bomb question about Cygwin
Message-ID: <aXI3osLanp-VA5qV@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <MN2PR09MB492382DA1F993B72742E1A98A596A AT MN2PR09MB4923 DOT namprd09 DOT prod DOT outlook DOT com>
<aXH2YPIcgWqd8zyX AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <aXH2YPIcgWqd8zyX@calimero.vinschen.de>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

On Jan 22 11:05, Corinna Vinschen via Cygwin wrote:
> On Jan 21 20:37, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via Cygwin wrote:
> > By default Cygwin creates the user environment with unlimited
> > processes (and I suppose that any user can just run "bash"
> > unrestricted, thus obtaining the unlimited process resource).  Which
> > then brings up a question about security of the system, as a whole.
> > And so the second part is, is there any way to securely control /
> > restrict the behavior?
> 
> This is not something controlled by Cygwin, rather by the OS.  Cygwin
> provides the POSIX calls getrlimit/setrlimit, but obviously those have
> to be implemented in terms of OS functions or faked.
> 
> The only implemented limits are RLIMIT_AS, RLIMIT_CORE, RLIMIT_NOFILE
> and RLIMIT_STACK, and only RLIMIT_AS is actually calling into the OS to
> install a restriction.
> 
> I just checked the MSDN man pages and it's possible to install a per-job
> process limit.  But that only affects processes inside the job.
> Assuming the process limit is established by a shell, only the child
> processes inside this shell would be affected, so it's basically
> equivalent to a soft limit in the terms of setrlimit.

You got me thinking there...

Unfortunately there's a tricky difference between POSIX soft limits and
the way Windows job limits work.

- Soft rlimits can be changed by any process, up or down, as long as the
  new limit doesn't exceed the hard limit.  A child process inherits the
  limits, but it can change (raise!) them right away, only limited by
  the hard limit.

- Job limits on Windows can be changed by the process, but the limits
  are accumulated if jobs are nested.  The lowest limit wins.

  If a child process inherited a job limit, it can't raise the limit,
  unless it knows the name of the job object *and* has the right to set
  limits on this object.  The problem here is, the current job the
  process is running in, does not necessarily contain the information
  about the real limit.  This information may be in a job object higher
  up in the job hirarchy.  Unfortunately QueryInformationJobObject only
  returns limits defined in this very job, not limits defined higher up.
  And there's no way to fetch info about parent job objects, unless you
  know their names or still have open handles on them.

All in all, that means, the current implementation of
setrlimit(RLIMIT_AS) is not quite correct.  The job object is inherited
by children, but then, if the child defines a new limit, it just creates
a nested job with this limit inside the already existing job.  So the new
limit is ignored if the parent (or grandparent, or ...) job defines a
lower limit.

Unfortunately the child can't just breakaway from a job.  Only the parent
can do this for a child at CreateProcess() time.  So we can't just
breakaway at setrlimit time and create a new, independent job object.

The bottom line is, if we want to do this right, we have to redesign
the entire setrlimit thingy:

- always allow BREAKAWAY_FROM_JOB
- always start the child with BREAKAWAY_FROM_JOB
- always create a new job object in the child after fork/exec implementing
  the soft limits inherited from the parent
- in setrlimit: always just change the current job object


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019