From nobody Fri Jun 25 16:19:05 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 65D6A11E2449 for ; Fri, 25 Jun 2021 16:19:12 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org (gritton.org [199.192.165.131]) (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 4GBMdX1SYHz4kfP for ; Fri, 25 Jun 2021 16:19:12 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org ([127.0.0.131]) (authenticated bits=0) by gritton.org (8.15.2/8.15.2) with ESMTPA id 15PGJ5k4054667; Fri, 25 Jun 2021 09:19:05 -0700 (PDT) (envelope-from jamie@freebsd.org) 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=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 25 Jun 2021 09:19:05 -0700 From: James Gritton To: jail@freebsd.org Cc: Michael Gmelin Subject: Re: POSIX shared memory and dying jails In-Reply-To: <20210625164100.73c71055@bsd64.grem.de> References: <20210625164100.73c71055@bsd64.grem.de> User-Agent: Roundcube Webmail/1.4.1 Message-ID: <03809b2655a40134dd802386afa6be7d@freebsd.org> X-Sender: jamie@freebsd.org X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (gritton.org [127.0.0.131]); Fri, 25 Jun 2021 09:19:05 -0700 (PDT) X-Rspamd-Queue-Id: 4GBMdX1SYHz4kfP 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 2021-06-25 07:41, Michael Gmelin wrote: > It seems like non-anonymous POSIX shared memory is not freed > automatically when a jail is removed and keeps it in a dying state, > until the shared memory segment is deleted manually. > > See below for the most basic example: > > [root@jailhost ~]# jail -c path=/ command=/bin/sh > # posixshmcontrol create /removeme > # exit > [root@jailhost ~]# jls -dv -j shmtest dying > true > > So at this point, the jail is stuck in a dying state. > > Checking POSIX shared memory segments shows the shared memory segment > which is stopping the jail from crossing the Styx: > > [root@jailhost ~]# posixshmcontrol list > MODE OWNER GROUP SIZE PATH > rw------- root wheel 0 /removeme > > After removing the shared memory segment manually... > > [root@jailhost ~]# posixshmcontrol rm /removeme > > the jail passes away peacefully: > > [root@jailhost ~]# jls -dv -j shmtest dying > jls: jail "shmtest" not found > > I wonder if it wouldn't make sense to always remove POSIX shared memory > created by a jail automatically when it's removed. That does seem reasonable, though it would take some bookkeeping to do right. There is currently no concrete idea of a jail's ownership of a POSIX shm object, as it uses only uid and gid for access permissions, same as files. The tie to the jail is in the underlying vm_object, which holds a cred that references the jail - that seems to be what's keeping the jail from going away. Like files, POSIX shared memory is one way a jail may communicate with the rest of the system. So it's theoretically conceivable that shared memory created by a defunct jail my still be in use by a parent jail, in the same way that shared memory created by a defunct process is still visible to other processes, but that may be a rare enough case to disregard. - Jamie