Skip to content

Commit 0e6b7ea

Browse files
alberandbrauner
authored andcommitted
fs: add FS_XFLAG_VERITY for fs-verity files
fs-verity introduced inode flag for inodes with enabled fs-verity on them. This patch adds FS_XFLAG_VERITY file attribute which can be retrieved with FS_IOC_FSGETXATTR ioctl() and file_getattr() syscall. This flag is read-only and can not be set with corresponding set ioctl() and file_setattr(). The FS_IOC_SETFLAGS requires file to be opened for writing which is not allowed for verity files. The FS_IOC_FSSETXATTR and file_setattr() clears this flag from the user input. As this is now common flag for both flag interfaces (flags/xflags) add it to overlapping flags list to exclude it from overwrite. Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org> Link: https://patch.msgid.link/20260126115658.27656-2-aalbersh@kernel.org Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 40210c2 commit 0e6b7ea

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

Documentation/filesystems/fsverity.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,22 @@ the file has fs-verity enabled. This can perform better than
341341
FS_IOC_GETFLAGS and FS_IOC_MEASURE_VERITY because it doesn't require
342342
opening the file, and opening verity files can be expensive.
343343

344+
FS_IOC_FSGETXATTR
345+
-----------------
346+
347+
Since Linux v7.0, the FS_IOC_FSGETXATTR ioctl sets FS_XFLAG_VERITY (0x00020000)
348+
in the returned flags when the file has verity enabled. Note that this attribute
349+
cannot be set with FS_IOC_FSSETXATTR as enabling verity requires input
350+
parameters. See FS_IOC_ENABLE_VERITY.
351+
352+
file_getattr
353+
------------
354+
355+
Since Linux v7.0, the file_getattr() syscall sets FS_XFLAG_VERITY (0x00020000)
356+
in the returned flags when the file has verity enabled. Note that this attribute
357+
cannot be set with file_setattr() as enabling verity requires input parameters.
358+
See FS_IOC_ENABLE_VERITY.
359+
344360
.. _accessing_verity_files:
345361

346362
Accessing verity files

fs/file_attr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags)
3636
fa->flags |= FS_DAX_FL;
3737
if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT)
3838
fa->flags |= FS_PROJINHERIT_FL;
39+
if (fa->fsx_xflags & FS_XFLAG_VERITY)
40+
fa->flags |= FS_VERITY_FL;
3941
}
4042
EXPORT_SYMBOL(fileattr_fill_xflags);
4143

@@ -66,6 +68,8 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags)
6668
fa->fsx_xflags |= FS_XFLAG_DAX;
6769
if (fa->flags & FS_PROJINHERIT_FL)
6870
fa->fsx_xflags |= FS_XFLAG_PROJINHERIT;
71+
if (fa->flags & FS_VERITY_FL)
72+
fa->fsx_xflags |= FS_XFLAG_VERITY;
6973
}
7074
EXPORT_SYMBOL(fileattr_fill_flags);
7175

include/linux/fileattr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
#define FS_COMMON_FL \
88
(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
99
FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \
10-
FS_PROJINHERIT_FL)
10+
FS_PROJINHERIT_FL | FS_VERITY_FL)
1111

1212
#define FS_XFLAG_COMMON \
1313
(FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \
1414
FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \
15-
FS_XFLAG_PROJINHERIT)
15+
FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY)
1616

1717
/* Read-only inode flags */
1818
#define FS_XFLAG_RDONLY_MASK \
19-
(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR)
19+
(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY)
2020

2121
/* Flags to indicate valid value of fsx_ fields */
2222
#define FS_XFLAG_VALUES_MASK \

include/uapi/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ struct file_attr {
253253
#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
254254
#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
255255
#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
256+
#define FS_XFLAG_VERITY 0x00020000 /* fs-verity enabled */
256257
#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
257258

258259
/* the read-only stuff doesn't really belong here, but any other place is

0 commit comments

Comments
 (0)