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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'xfs-6.5-fixes-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

Pull xfs fixes from Darrick Wong:
"Flexarray declaration conversions.

This probably should've been done with the merge window open, but I
was not aware that the UBSAN knob would be getting turned up for 6.5,
and the fstests failures due to the kernel warnings are getting in the
way of testing.

Summary:

- Convert all the array[1] declarations into the accepted flex
array[] declarations so that UBSAN and friends will not get
confused"

* tag 'xfs-6.5-fixes-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux:
xfs: convert flex-array declarations in xfs attr shortform objects
xfs: convert flex-array declarations in xfs attr leaf blocks
xfs: convert flex-array declarations in struct xfs_attrlist*

+71 -13
+66 -9
fs/xfs/libxfs/xfs_da_format.h
··· 591 591 uint8_t valuelen; /* actual length of value (no NULL) */ 592 592 uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ 593 593 uint8_t nameval[]; /* name & value bytes concatenated */ 594 - } list[1]; /* variable sized array */ 594 + } list[]; /* variable sized array */ 595 595 }; 596 596 597 597 typedef struct xfs_attr_leaf_map { /* RLE map of free bytes */ ··· 620 620 typedef struct xfs_attr_leaf_name_local { 621 621 __be16 valuelen; /* number of bytes in value */ 622 622 __u8 namelen; /* length of name bytes */ 623 - __u8 nameval[1]; /* name/value bytes */ 623 + /* 624 + * In Linux 6.5 this flex array was converted from nameval[1] to 625 + * nameval[]. Be very careful here about extra padding at the end; 626 + * see xfs_attr_leaf_entsize_local() for details. 627 + */ 628 + __u8 nameval[]; /* name/value bytes */ 624 629 } xfs_attr_leaf_name_local_t; 625 630 626 631 typedef struct xfs_attr_leaf_name_remote { 627 632 __be32 valueblk; /* block number of value bytes */ 628 633 __be32 valuelen; /* number of bytes in value */ 629 634 __u8 namelen; /* length of name bytes */ 630 - __u8 name[1]; /* name bytes */ 635 + /* 636 + * In Linux 6.5 this flex array was converted from name[1] to name[]. 637 + * Be very careful here about extra padding at the end; see 638 + * xfs_attr_leaf_entsize_remote() for details. 639 + */ 640 + __u8 name[]; /* name bytes */ 631 641 } xfs_attr_leaf_name_remote_t; 632 642 633 643 typedef struct xfs_attr_leafblock { 634 644 xfs_attr_leaf_hdr_t hdr; /* constant-structure header block */ 635 - xfs_attr_leaf_entry_t entries[1]; /* sorted on key, not name */ 645 + xfs_attr_leaf_entry_t entries[]; /* sorted on key, not name */ 636 646 /* 637 647 * The rest of the block contains the following structures after the 638 648 * leaf entries, growing from the bottom up. The variables are never ··· 674 664 675 665 struct xfs_attr3_leafblock { 676 666 struct xfs_attr3_leaf_hdr hdr; 677 - struct xfs_attr_leaf_entry entries[1]; 667 + struct xfs_attr_leaf_entry entries[]; 678 668 679 669 /* 680 670 * The rest of the block contains the following structures after the ··· 757 747 */ 758 748 static inline int xfs_attr_leaf_entsize_remote(int nlen) 759 749 { 760 - return round_up(sizeof(struct xfs_attr_leaf_name_remote) - 1 + 761 - nlen, XFS_ATTR_LEAF_NAME_ALIGN); 750 + /* 751 + * Prior to Linux 6.5, struct xfs_attr_leaf_name_remote ended with 752 + * name[1], which was used as a flexarray. The layout of this struct 753 + * is 9 bytes of fixed-length fields followed by a __u8 flex array at 754 + * offset 9. 755 + * 756 + * On most architectures, struct xfs_attr_leaf_name_remote had two 757 + * bytes of implicit padding at the end of the struct to make the 758 + * struct length 12. After converting name[1] to name[], there are 759 + * three implicit padding bytes and the struct size remains 12. 760 + * However, there are compiler configurations that do not add implicit 761 + * padding at all (m68k) and have been broken for years. 762 + * 763 + * This entsize computation historically added (the xattr name length) 764 + * to (the padded struct length - 1) and rounded that sum up to the 765 + * nearest multiple of 4 (NAME_ALIGN). IOWs, round_up(11 + nlen, 4). 766 + * This is encoded in the ondisk format, so we cannot change this. 767 + * 768 + * Compute the entsize from offsetof of the flexarray and manually 769 + * adding bytes for the implicit padding. 770 + */ 771 + const size_t remotesize = 772 + offsetof(struct xfs_attr_leaf_name_remote, name) + 2; 773 + 774 + return round_up(remotesize + nlen, XFS_ATTR_LEAF_NAME_ALIGN); 762 775 } 763 776 764 777 static inline int xfs_attr_leaf_entsize_local(int nlen, int vlen) 765 778 { 766 - return round_up(sizeof(struct xfs_attr_leaf_name_local) - 1 + 767 - nlen + vlen, XFS_ATTR_LEAF_NAME_ALIGN); 779 + /* 780 + * Prior to Linux 6.5, struct xfs_attr_leaf_name_local ended with 781 + * nameval[1], which was used as a flexarray. The layout of this 782 + * struct is 3 bytes of fixed-length fields followed by a __u8 flex 783 + * array at offset 3. 784 + * 785 + * struct xfs_attr_leaf_name_local had zero bytes of implicit padding 786 + * at the end of the struct to make the struct length 4. On most 787 + * architectures, after converting nameval[1] to nameval[], there is 788 + * one implicit padding byte and the struct size remains 4. However, 789 + * there are compiler configurations that do not add implicit padding 790 + * at all (m68k) and would break. 791 + * 792 + * This entsize computation historically added (the xattr name and 793 + * value length) to (the padded struct length - 1) and rounded that sum 794 + * up to the nearest multiple of 4 (NAME_ALIGN). IOWs, the formula is 795 + * round_up(3 + nlen + vlen, 4). This is encoded in the ondisk format, 796 + * so we cannot change this. 797 + * 798 + * Compute the entsize from offsetof of the flexarray and manually 799 + * adding bytes for the implicit padding. 800 + */ 801 + const size_t localsize = 802 + offsetof(struct xfs_attr_leaf_name_local, nameval); 803 + 804 + return round_up(localsize + nlen + vlen, XFS_ATTR_LEAF_NAME_ALIGN); 768 805 } 769 806 770 807 static inline int xfs_attr_leaf_entsize_local_max(int bsize)
+2 -2
fs/xfs/libxfs/xfs_fs.h
··· 592 592 struct xfs_attrlist { 593 593 __s32 al_count; /* number of entries in attrlist */ 594 594 __s32 al_more; /* T/F: more attrs (do call again) */ 595 - __s32 al_offset[1]; /* byte offsets of attrs [var-sized] */ 595 + __s32 al_offset[]; /* byte offsets of attrs [var-sized] */ 596 596 }; 597 597 598 598 struct xfs_attrlist_ent { /* data from attr_list() */ 599 599 __u32 a_valuelen; /* number bytes in value of attr */ 600 - char a_name[1]; /* attr name (NULL terminated) */ 600 + char a_name[]; /* attr name (NULL terminated) */ 601 601 }; 602 602 603 603 typedef struct xfs_fsop_attrlist_handlereq {
+3 -2
fs/xfs/xfs_ondisk.h
··· 56 56 57 57 /* dir/attr trees */ 58 58 XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leaf_hdr, 80); 59 - XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leafblock, 88); 59 + XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leafblock, 80); 60 60 XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_rmt_hdr, 56); 61 61 XFS_CHECK_STRUCT_SIZE(struct xfs_da3_blkinfo, 56); 62 62 XFS_CHECK_STRUCT_SIZE(struct xfs_da3_intnode, 64); ··· 88 88 XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, valuelen, 4); 89 89 XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, namelen, 8); 90 90 XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, name, 9); 91 - XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t, 40); 91 + XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t, 32); 92 + XFS_CHECK_STRUCT_SIZE(struct xfs_attr_shortform, 4); 92 93 XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.totsize, 0); 93 94 XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.count, 2); 94 95 XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].namelen, 4);