linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Chengguang Xu <cgxu519@mykernel.net>,
	overlayfs <linux-unionfs@vger.kernel.org>
Subject: Re: [PATCH] ovl: consistent behavior for immutable/append-only inodes
Date: Wed, 9 Jun 2021 09:08:02 +0300	[thread overview]
Message-ID: <CAOQ4uxheGdKSqEBYAOTf7=UwqeW=JAaZBwaCs-ng28G7rtqZ7Q@mail.gmail.com> (raw)
In-Reply-To: <CAJfpegtC+bg3_onOuzQv116axuX36y13P-_ojA5ZOUjfdTPR-g@mail.gmail.com>

On Tue, Jun 8, 2021 at 9:20 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Tue, 8 Jun 2021 at 17:33, Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Tue, Jun 8, 2021 at 5:49 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> > >
> > > On Tue, 8 Jun 2021 at 16:37, Amir Goldstein <amir73il@gmail.com> wrote:
> > > >
> > > > On Tue, Jun 8, 2021 at 4:52 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> > > > >
> > > > > On Sun, 6 Jun 2021 at 16:46, Amir Goldstein <amir73il@gmail.com> wrote:
> > > > > >
> > > > > > When a lower file has immutable/append-only attributes, the behavior of
> > > > > > overlayfs post copy up is inconsistent.
> > > > > >
> > > > > > Immediattely after copy up, ovl inode still has the S_IMMUTABLE/S_APPEND
> > > > > > inode flags copied from lower inode, so vfs code still treats the ovl
> > > > > > inode as immutable/append-only.  After ovl inode evict or mount cycle,
> > > > > > the ovl inode does not have these inode flags anymore.
> > > > > >
> > > > > > We cannot copy up the immutable and append-only fileattr flags, because
> > > > > > immutable/append-only inodes cannot be linked and because overlayfs will
> > > > > > not be able to set overlay.* xattr on the upper inodes.
> > > > >
> > > > > Ugh.
> > > > >
> > > > > > Instead, if any of the fileattr flags of interest exist on the lower
> > > > > > inode, we set an xattr overlay.xflags on the upper inode as an indication
> > > > > > to merge the origin inode fileattr flags on lookup.
> > > > > >
> > > > > > This gives consistent behavior post copy up regardless of inode eviction
> > > > > > from cache.
> > > > > >
> > > > > > When user sets new fileattr flags, we break the connection with the
> > > > > > origin fileattr by removing the overlay.xflags xattr.
> > > > > >
> > > > > > Note that having the S_IMMUTABLE/S_APPEND on the ovl inode does not
> > > > > > provide the same level of protection as setting those flags on the real
> > > > > > upper inode, because some filesystem check those flags internally in
> > > > > > addition or instead of the vfs checks (e.g. btrfs_may_delete()), but
> > > > > > that is the way it has always been for overlayfs.
> > > > >
> > > > > That's fine, underlying filesystem is just a backing store.
> > > > >
> > > >
> > > > Immutability of underlying files was not my concern.
> > > > My concern was that vfs does not provide full protection and that some
> > > > protection is provided in fs level, because I saw IS_APPEND/IS_IMMUTABLE
> > > > sprinkled all over the place in fs (e.g. ext4_setattr()), but I guess those are
> > > > just leftovers and I was over concerned.
> > >
> > > Would be a nice cleanup to get rid of these.   It would also prove
> > > that the vfs protection is sufficient.
> > >
> > > >
> > > > > > As can be seen in the comment above ovl_check_origin_xflags(), the
> > > > > > "xflags merge" feature is designed to solve other non-standard behavior
> > > > > > issues related to immutable directories and hardlinks in the future, but
> > > > > > this commit does not bother to fix those cases because those are corner
> > > > > > cases that are probably not so important to fix.
> > > > > >
> > > > > > A word about the design decision to merge the origin and upper xflags -
> > > > > > Because we do not copy up fileattr and because fileattr_set breaks the
> > > > > > link to origin xflags, the only cases where origin and upper inodes both
> > > > > > have xflags is if upper inode was modified not via overlayfs or if the
> > > > > > system crashed during ovl_fileattr_set() before removing the
> > > > > > overlay.xflags xattr.  In both cases, modifiying the upper inode is not
> > > > > > going to be permitted, so it is better to reflect this in the overlay
> > > > > > inode flags.
> > > > >
> > > > > So why not implement the non-merge (#3) behavior unconditionally?
> > > > > That would solve all issues related to fileattr, right?
> > > > >
> > > >
> > > > I suppose so. Note that #3 fileattr_get is still a merge between upper fileattr
> > > > and the 4 overlay stored flags, but for inode flags it will not be a merge.
> > > >
> > > > I can give this a shot.
> > > >
> > > > While you are here, do you think that will be sufficient for the on-disk format
> > > > of overlay.xflags?
> > > >
> > > > struct ovl_xflags {
> > > >         __le32 xflags;
> > > >         __le32 xflags_mask;
> > > > }
> > >
> > > I think I'd prefer a slightly more complex, but user friendlier
> > > "+i,-a,..." format.
> > >
> >
> > OK, but since this is not a merge, we'd only need:
> > overlay.xflags = "ia..."
> >
> > Which is compatible with the format of:
> > chattr =<xflags> <file>
>
> Fine.   Not sure what xflags_mask would be useful for in your proposal, though.
>

The idea was that in the context of fileattr_get(), any specific xflag
value can be one of: SET, CLEAR, REAL.

For most inodes all flags are REAL (no xflags xattr)
All flags but the 4 in OVL_FS_XFLAGS_MASK are always REAL
(i.e. taken from fileattr_get() on real inode).

If we ever decide to extend OVL_FS_XFLAGS_MASK, say to include
DIRSYNC, then an upper inode with DIRSYNC that was in state
REAL before upgrade would become CLEAR after upgrade unless
we kept the old xflags_mask in xattr.

With the string format, this is not a concern.
Therefore, I like the string format better.

Thanks,
Amir.

  reply	other threads:[~2021-06-09  6:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06 14:46 Amir Goldstein
2021-06-08 13:52 ` Miklos Szeredi
2021-06-08 14:37   ` Amir Goldstein
2021-06-08 14:49     ` Miklos Szeredi
2021-06-08 15:33       ` Amir Goldstein
2021-06-08 18:20         ` Miklos Szeredi
2021-06-09  6:08           ` Amir Goldstein [this message]
2021-06-09  7:28             ` Miklos Szeredi
2021-06-09  7:57               ` Amir Goldstein
2021-06-11  7:31                 ` Amir Goldstein
2021-06-11  7:55                   ` Miklos Szeredi
2021-06-11  8:37                     ` Amir Goldstein
2021-06-11  8:39                       ` Miklos Szeredi

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='CAOQ4uxheGdKSqEBYAOTf7=UwqeW=JAaZBwaCs-ng28G7rtqZ7Q@mail.gmail.com' \
    --to=amir73il@gmail.com \
    --cc=cgxu519@mykernel.net \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --subject='Re: [PATCH] ovl: consistent behavior for immutable/append-only inodes' \
    /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).