From nobody Mon Aug 2 19:03:27 2021 X-Original-To: jail@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 469E012B55BE for ; Mon, 2 Aug 2021 19:03:42 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4GdnTn6MZ1z4rKk for ; Mon, 2 Aug 2021 19:03:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 172J3SmJ083294 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 2 Aug 2021 22:03:31 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 172J3SmJ083294 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 172J3R5B083293; Mon, 2 Aug 2021 22:03:27 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 2 Aug 2021 22:03:27 +0300 From: Konstantin Belousov To: Michael Gmelin Cc: jail@freebsd.org Subject: Re: POSIX shared memory, jails, and (lack of) limits Message-ID: References: List-Id: Discussion about FreeBSD jail(8) List-Archive: https://lists.freebsd.org/archives/freebsd-jail List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-jail@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4GdnTn6MZ1z4rKk X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Mon, Aug 02, 2021 at 05:06:43PM +0200, Michael Gmelin wrote: > > > > On 2. Aug 2021, at 15:56, Konstantin Belousov wrote: > > > > On Mon, Aug 02, 2021 at 02:19:00PM +0200, Michael Gmelin wrote: > >> Hi, > >> > >> I've been playing a bit with POSIX shared memory and, unlike for SysV > >> shared memory, I couldn't find any way to limit its use by jails. > >> > >> First, I looked at racct/rctl, but there is no resource for POSIX shared > >> memory and memoryuse/vmemoryuse don't seem to have an effect (which > >> makes sense). > >> > >> Then I checked if there are jail parameters that could help, but there > >> doesn't seem to be anything like "allow.sysvshm" for POSIX shared > >> memory to limit access to the feature. > >> > >> So, unless I'm missing something, it seems like all jails on a system > >> have unlimited access to POSIX shared memory and therefore any single > >> jail can use up the jailhost's virtual memory until the jailhost comes > >> to a grinding halt. > >> > >> I wrote a little test program that keeps allocating POSIX shared memory > >> inside of a jail and it can easily bring the host down to its knees: > >> > >> login: Aug 2 12:12:09 test kernel: pid 11825 (getty), jid 0, uid 0, > >> was killed: out of swap space > >> Aug 2 12:12:10 test init[11827]: getty repeating too quickly on port > >> /dev/ttyu0, sleeping 30 secs > >> Aug 2 12:12:10 test kernel: pid 11826 (getty), jid 0, uid 0, was > >> killed: out of swap space > > > > Posix shm is limited by the swap accounting. For non-jail consumers, > > it is per-uid RLIMIT_SWAP. I do not know if other mechanisms make > > RLIMIT_SWAP per-jail per-uid. > > Unfortunately it seems like POSIX shared memory is not linked to the jail it was created in (we discussed this on this list in June and I created a few PRs about that), so per jail rctl rules don’t apply (and limiting uid 0 won’t have the desired effect ^_^). > In what sense 'not linked'? The backing vm_object is created with the current process credentials, which are jailed if creator belongs to a jail.