From owner-freebsd-fs@freebsd.org Tue Apr 11 18:23:58 2017 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 93B3FD3A23F for ; Tue, 11 Apr 2017 18:23:58 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: from mail-io0-x22f.google.com (mail-io0-x22f.google.com [IPv6:2607:f8b0:4001:c06::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6D960D71 for ; Tue, 11 Apr 2017 18:23:58 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: by mail-io0-x22f.google.com with SMTP id a103so13301849ioj.1 for ; Tue, 11 Apr 2017 11:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sippysoft-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=IrlRc7HMHS7hl1nOl0BAkxMJMToI9TH1rHrTn33fJiY=; b=gtdGVekgdlY1S4zsy9toGQeqag2oYTpGatsvJq/vkD9m/5U3OMoI+4ZqIBtrRkgfIy 5SoiipVfkBjrAajfczsjYQtKkEWjVJgFkd9q9koCrA8tdKHuATkoZNqsHU9Hh4MfELGp 2uN9J9x+DhQDw8ft520htk728W9uc1EkQx9Tfl2K2NvofRQ4deNl6JSiYDDyydRCywDI bQJInam+szENa52hcf1PVqVO2bRLQxS0W3G6Tom2506+mSbDYdvuF9cd0kH3tqoDpnzm +5it1en0oR4waCznHi/vG5U4Sa+PUs8q78m8IO2lGU390xWZYjNRYZE9hwi2NranVK3f JTxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=IrlRc7HMHS7hl1nOl0BAkxMJMToI9TH1rHrTn33fJiY=; b=pSFQpH8yhsBEILd6FfSAO0TcNtHdx9EQu1OehZD1z4RYR4rZ1drFfKkwIGArr8XLFj D3L462hxn4BsIehO3h5k73AXGoNHe5FvrYHnVAderiCiNdVqG/nYvR+2EPKD5miLkK9W tUKGm6dYWPlcAtfrTYm34B6i8zLhVYn8jkobHPRnseVYUlEBsE4o5mY1R/BaYQ26BNpz WplweQ1inEHzoeCLuQeF5a72r1UFyc7Q8hNUkPFXHXOk4ML9C3ZntMnYqxWoT542vssk QJvJpNRgASGdPF1RrHrEwo1uFBhLo2pzY8Em382ujKylVZuynEFKZ5QVPF1z5USRDEEo Rwkg== X-Gm-Message-State: AFeK/H03WVqNvfrcd/9nMTImnmeEp8dUOffvKqe4CRmOpk+le5+W/K5DaBQAh4UJ5Zb91PVXRarqdmlb4eXSgi+Z X-Received: by 10.107.203.7 with SMTP id b7mr59708840iog.115.1491935037535; Tue, 11 Apr 2017 11:23:57 -0700 (PDT) MIME-Version: 1.0 Sender: sobomax@sippysoft.com Received: by 10.36.112.210 with HTTP; Tue, 11 Apr 2017 11:23:57 -0700 (PDT) In-Reply-To: <201704111807.v3BI7PGM001952@chez.mckusick.com> References: <201704111807.v3BI7PGM001952@chez.mckusick.com> From: Maxim Sobolev Date: Tue, 11 Apr 2017 11:23:57 -0700 X-Google-Sender-Auth: CImaKWRmncEBjyxNALMPehW2Jl8 Message-ID: Subject: Re: mksnap_ffs(8) is not working while chrooted To: Kirk McKusick Cc: FreeBSD Filesystems Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Apr 2017 18:23:58 -0000 Kirk, what you are saying in not applying in our case. The whole FS is mounted *inside* the chroot. The reason why we are trying to use mksnap_ffs is to take a clean snapshot to make a compressed version of it without the need to forcefully zero out free space. So it looks like the following: parent# chroot /mnt/chroot /bin/sh chroot# truncate /tmp/diskimage chroot# mdconfig -a -f /tmp/diskimage md0 chroot# newfs md0 chroot# mount /dev/md0 /mnt [...do stuff with /mnt...] chroot# mksnap_ffs /mnt/snap mksnap_ffs: No such file or directory Perhaps, to work around your concern is to add some flag for the statfs(1) to normalize f_mntonname for use inside chroot then? I have not tested it here, but I believe that if I'd strip "/mnt/chroot" prefix inside mksnap_ffs(8) that would work in our scenario just fine. -Max On Tue, Apr 11, 2017 at 11:07 AM, Kirk McKusick wrote: > > From: Maxim Sobolev > > Date: Tue, 11 Apr 2017 10:40:58 -0700 > > Subject: mksnap_ffs(8) is not working while chrooted > > To: Kirk McKusick , > > FreeBSD Filesystems > > > > Hi Kirk et al, > > > > I've stumbled upon problem that it is impossible to use mksnap_ffs(8) > while > > in the chrooted environment. Other utilities that manipulate fs'es (i.e. > > mount(8) / umount(8)) work just fine. Quick glance through the code shows > > that the problem stems from the fact that mksnap_ffs uses f_mntonname > > returned by the statfs(2) system call to fill fspath parameter for the > > nmount call. And the statfs() returns f_mntonname path outside chroot. As > > far as I can see, there are two options to address this issue. > > > > 1. Adjust statfs(2) system call to substract chroot prefix while > > returning f_mntonname. Similar to what prison_enforce_statfs() function > > does for jails. > > > > 2. Enhance nmount(2) to allow taking FSID in place of mount path to do > > resolution using existing flag MNT_BYFSID and adjust mksnap_ffs to use > that > > instead. This is what umount(8) does to work around the problem. > > > > Which of two approaches would be preferred solution if any? The second > one > > seems a bit simpler to me. Please advise. Thanks! > > > > -Max > > It is not secure to allow mksnap_ffs(8) to work inside a jail. The issue > is that mksnap_ffs takes a snapshot of the entire filesystem. Based on the > way that snapshots work in FFS, it is not possible to snapshot only the > part of the filesystem that is in the jail. Thus, if you take a snapshot > of the entire filesystem and then mount it inside the jail, you will > expose parts of the filesystem from outside of the jail to the jail. > As such, you should only be able to snapshot a filesystem if it is > entirely contained within the jail. > > If snapshots within jails are important to you, I recommend that you use > ZFS which allows you to create per-jail filesystems which you can then > snapshot. > > Kirk McKusick > >