Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andrey Albershteyn and committed by
Christian Brauner
0e6b7eae 40210c2b

+24 -3
+16
Documentation/filesystems/fsverity.rst
··· 341 341 FS_IOC_GETFLAGS and FS_IOC_MEASURE_VERITY because it doesn't require 342 342 opening the file, and opening verity files can be expensive. 343 343 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 + 344 360 .. _accessing_verity_files: 345 361 346 362 Accessing verity files
+4
fs/file_attr.c
··· 36 36 fa->flags |= FS_DAX_FL; 37 37 if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT) 38 38 fa->flags |= FS_PROJINHERIT_FL; 39 + if (fa->fsx_xflags & FS_XFLAG_VERITY) 40 + fa->flags |= FS_VERITY_FL; 39 41 } 40 42 EXPORT_SYMBOL(fileattr_fill_xflags); 41 43 ··· 68 66 fa->fsx_xflags |= FS_XFLAG_DAX; 69 67 if (fa->flags & FS_PROJINHERIT_FL) 70 68 fa->fsx_xflags |= FS_XFLAG_PROJINHERIT; 69 + if (fa->flags & FS_VERITY_FL) 70 + fa->fsx_xflags |= FS_XFLAG_VERITY; 71 71 } 72 72 EXPORT_SYMBOL(fileattr_fill_flags); 73 73
+3 -3
include/linux/fileattr.h
··· 7 7 #define FS_COMMON_FL \ 8 8 (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ 9 9 FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ 10 - FS_PROJINHERIT_FL) 10 + FS_PROJINHERIT_FL | FS_VERITY_FL) 11 11 12 12 #define FS_XFLAG_COMMON \ 13 13 (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ 14 14 FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ 15 - FS_XFLAG_PROJINHERIT) 15 + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) 16 16 17 17 /* Read-only inode flags */ 18 18 #define FS_XFLAG_RDONLY_MASK \ 19 - (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR) 19 + (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY) 20 20 21 21 /* Flags to indicate valid value of fsx_ fields */ 22 22 #define FS_XFLAG_VALUES_MASK \
+1
include/uapi/linux/fs.h
··· 253 253 #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */ 254 254 #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */ 255 255 #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */ 256 + #define FS_XFLAG_VERITY 0x00020000 /* fs-verity enabled */ 256 257 #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ 257 258 258 259 /* the read-only stuff doesn't really belong here, but any other place is