001-create_inode-Fix-compilation-again-kernel-5.12.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <[email protected]>
  3. Date: Sat, 25 Oct 2025 19:59:58 +0200
  4. Subject: create_inode: Fix compilation again kernel < 5.12
  5. Copy the header definition from Linux kernel v5.12 to allow compilation
  6. against kernel headers from an kernel older than v5.12.
  7. struct fsverity_descriptor was already added in kernel 5.11, compiling
  8. against kernel 5.11 kernel headers could cause problems.
  9. Signed-off-by: Hauke Mehrtens <[email protected]>
  10. ---
  11. misc/create_inode.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
  12. 1 file changed, 47 insertions(+)
  13. --- a/misc/create_inode.c
  14. +++ b/misc/create_inode.c
  15. @@ -575,6 +575,53 @@ static inline off_t round_up(off_t n, of
  16. return ((n - bias + (blksz - 1)) & ~(blksz - 1)) + bias;
  17. }
  18. +#ifndef FS_IOC_READ_VERITY_METADATA
  19. +
  20. +/*
  21. + * Struct containing a file's Merkle tree properties. The fs-verity file digest
  22. + * is the hash of this struct. A userspace program needs this struct only if it
  23. + * needs to compute fs-verity file digests itself, e.g. in order to sign files.
  24. + * It isn't needed just to enable fs-verity on a file.
  25. + *
  26. + * Note: when computing the file digest, 'sig_size' and 'signature' must be left
  27. + * zero and empty, respectively. These fields are present only because some
  28. + * filesystems reuse this struct as part of their on-disk format.
  29. + */
  30. +struct fsverity_descriptor {
  31. + __u8 version; /* must be 1 */
  32. + __u8 hash_algorithm; /* Merkle tree hash algorithm */
  33. + __u8 log_blocksize; /* log2 of size of data and tree blocks */
  34. + __u8 salt_size; /* size of salt in bytes; 0 if none */
  35. +#ifdef __KERNEL__
  36. + __le32 sig_size;
  37. +#else
  38. + __le32 __reserved_0x04; /* must be 0 */
  39. +#endif
  40. + __le64 data_size; /* size of file the Merkle tree is built over */
  41. + __u8 root_hash[64]; /* Merkle tree root hash */
  42. + __u8 salt[32]; /* salt prepended to each hashed block */
  43. + __u8 __reserved[144]; /* must be 0's */
  44. +#ifdef __KERNEL__
  45. + __u8 signature[];
  46. +#endif
  47. +};
  48. +
  49. +#define FS_VERITY_METADATA_TYPE_MERKLE_TREE 1
  50. +#define FS_VERITY_METADATA_TYPE_DESCRIPTOR 2
  51. +#define FS_VERITY_METADATA_TYPE_SIGNATURE 3
  52. +
  53. +struct fsverity_read_metadata_arg {
  54. + __u64 metadata_type;
  55. + __u64 offset;
  56. + __u64 length;
  57. + __u64 buf_ptr;
  58. + __u64 __reserved;
  59. +};
  60. +
  61. +#define FS_IOC_READ_VERITY_METADATA \
  62. + _IOWR('f', 135, struct fsverity_read_metadata_arg)
  63. +#endif
  64. +
  65. static errcode_t copy_fs_verity_data(ext2_file_t e2_file, ext2_off_t e2_offset,
  66. int fd, uint64_t metadata_type,
  67. __u32 *written)