Re: [PATCH 2/3] vfs: add xflags mask to fileattr API

From: Amir Goldstein

Date: Mon Nov 23 2026 - 10:30:09 EST


On Mon, Nov 23, 2026 at 2:58 PM koraynilay <koray.fra@xxxxxxxxx> wrote:
>
> On Mon Nov 23, 2026 at 2:24 PM CET, Amir Goldstein wrote:
> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@xxxxxxxxx> wrote:
> >>
> >> Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr and
> >> equivalent masks to struct file_kattr.
> >>
> >> Also add has_masks selector to struct file_kattr so we can know when a
> >> user of this API (userspace or filesystem) supports them.
> >>
> >> This lets filesystems advertise their support for specific xflags, like
> >> statx.stx_attributes_mask does, and userspace can specify only which
> >> xflags it wants to change without needing a RMW cycle:
> >> - on GET: each filesystem that wants to support this new API fills the
> >> masks according to its supported and read-only xflags, then:
> >> * for boolean xflags: it fills fsx_xflags with the current on-disk value
> >> * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the
> >> xflag value in the struct field;
> >> - on SET: userspace fills the rw_mask with the bits of the xflags it
> >> wants to change, then:
> >> * for boolean xflags: it provides the xflag value as a bit in fa_xflags
> >> * for value xflags: it sets the xflag bit to 1 in fa_xflags and then
> >> provides the value in the struct field; if the xflag bit is set to 0
> >> instead, this informs the kernel to unset/clear that value.
> >>
> >> Since fa_xflags_rw_mask means "I want to change the xflags specified in
> >> here", if userspace specifies fa_xflags_rw_mask = 0, only check for
> >> permissions and fileattr support without checking any xflags.
> >>
> >> Behaviour of older programs that already use file_[gs]etattr() is
> >> preserved by checking against FILE_ATTR_SIZE_VER*.
> >>
> >> Also add the missing FS_XFLAG_PROJID xflag, to allow userspace to set
> >> the projid using file_[gs]etattr() by leveraging the new masks.
> >>
> >> Finally, in order to prevent the legacy FS_IOC_FSSETXATTR from accepting
> >> FS_XFLAG_PROJID, add a FS_FILE_ATTR_XFLAGS_MASK to support new xflags
> >> and use it to validate/clamp both the _xflags fields and the masks.
> >>
> >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11
> >> Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
> >> ---
...
> >> err = fileattr_set_prepare(inode, &old_ma, fa);
> >> @@ -424,6 +504,14 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
> >> return error;
> >>
> >> fileattr_to_file_attr(&fa, &fattr);
> >> + /*
> >> + * Remove xflags added in or after VER1 so userspace programs compiled
> >> + * against VER0 don't try to write xflags they don't know about (since
> >> + * they do RMW).
> >> + */
> >> + if (usize < FILE_ATTR_SIZE_VER1)
> >> + fattr.fa_xflags &= FS_XFLAGS_MASK;
> >> +
> >
> > This looks odd.
> > old struct size with new flags should be -EINVAL not silently drop them
>
> Right, and the GET path should strip any new flags, so old programs
> doing RMW will never see them, correct?
>

Yes, I think so.

> >
> >> error = copy_struct_to_user(ufattr, usize, &fattr,
> >> sizeof(struct file_attr), NULL);
> >>
> >> @@ -460,10 +548,6 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
> >> if (error)
> >> return error;
> >>
> >> - error = file_attr_to_fileattr(&fattr, &fa);
> >> - if (error)
> >> - return error;
> >> -
> >> CLASS(filename_maybe_null, name)(filename, at_flags);
> >> if (!name && dfd >= 0) {
> >> CLASS(fd, f)(dfd);
> >> @@ -479,6 +563,30 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
> >> return error;
> >> }
> >>
> >> + /*
> >> + * Userspace said "I don't want to change any flag", so be it I guess.
> >> + * Still check for fileattr support and permissions, also in case this
> >> + * is just a probe.
> >> + */
> >> + if (usize >= FILE_ATTR_SIZE_VER1 && fattr.fa_xflags_rw_mask == 0) {
> >> + struct inode *inode = d_inode(filepath.dentry);
> >
> >
> > No No this is not what this userspace said!
> >
> > This user space is the same old chattr programs recompiled with a new
> > fs.h header file
> > installed.
>
> Oh, right, I did not think about this case, I hope it doesn't break too
> much of the new code I changed already for v2 :(
>
> > When userspace does not set anything is masks it means "old API"
>
> And so a modern program using masks that passes rw_mask as 0 should be
> also interpreted as "old API", even if it kinda goes against the
> definition of rw_mask right?

Yes, but it is not a problem to describe this backward compat exception:
When (rw_mask | ro_mask) == 0, it means "no mask" "set everything"
but then vfs will not accept new xflags that were not supported in v0
syscall.

> And other than VER there is no way to know if it's a SETFLAGS compiled
> against modern fs.h or fileattr VER1 explicitly setting rw_mask to 0,
> right?
>

SETFLAGS with explicit 0 rw_mask is not useful and does not make
sense, so there is no reason to support this in any other meaning than
legacy programs.

Thanks,
Amir.