Message ID | 20200831130423.136509-2-cmaiolino@redhat.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | Clean up xfs_attr_sf_entry | expand |
On 8/31/20 8:04 AM, Carlos Maiolino wrote: > #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ > - ((1 << (NBBY*(int)sizeof(uint8_t))) - 1) > + (1 << (NBBY*(int)sizeof(uint8_t))) This probably is not correct. :) This would cut the max size of attr (name+value) in half. -Eric
On 8/31/20 9:53 AM, Eric Sandeen wrote: > On 8/31/20 8:04 AM, Carlos Maiolino wrote: >> #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ >> - ((1 << (NBBY*(int)sizeof(uint8_t))) - 1) >> + (1 << (NBBY*(int)sizeof(uint8_t))) > > This probably is not correct. :) > > This would cut the max size of attr (name+value) in half. Whoops other way around. ;) this would double XFS_ATTR_SF_ENTSIZE_MAX. In any case, just drop that change. -Eric
On Mon, Aug 31, 2020 at 03:04:20PM +0200, Carlos Maiolino wrote: > nameval is a variable-size array, so, define it as it, and remove all > the -1 magic number subtractions. > > Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> > --- > fs/xfs/libxfs/xfs_attr_leaf.c | 6 ++---- > fs/xfs/libxfs/xfs_attr_sf.h | 6 +++--- > fs/xfs/libxfs/xfs_da_format.h | 2 +- > 3 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c > index 305d4bc073370..7bbc97e0e4d4a 100644 > --- a/fs/xfs/libxfs/xfs_attr_leaf.c > +++ b/fs/xfs/libxfs/xfs_attr_leaf.c > @@ -992,7 +992,7 @@ xfs_attr_shortform_allfit( > return 0; > if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX) > return 0; > - bytes += sizeof(struct xfs_attr_sf_entry) - 1 > + bytes += sizeof(struct xfs_attr_sf_entry) > + name_loc->namelen > + be16_to_cpu(name_loc->valuelen); > } > @@ -1036,10 +1036,8 @@ xfs_attr_shortform_verify( > * struct xfs_attr_sf_entry has a variable length. > * Check the fixed-offset parts of the structure are > * within the data buffer. > - * xfs_attr_sf_entry is defined with a 1-byte variable > - * array at the end, so we must subtract that off. > */ > - if (((char *)sfep + sizeof(*sfep) - 1) >= endp) > + if (((char *)sfep + sizeof(*sfep)) >= endp) > return __this_address; > > /* Don't allow names with known bad length. */ > diff --git a/fs/xfs/libxfs/xfs_attr_sf.h b/fs/xfs/libxfs/xfs_attr_sf.h > index bb004fb7944a7..d93012a0be4d0 100644 > --- a/fs/xfs/libxfs/xfs_attr_sf.h > +++ b/fs/xfs/libxfs/xfs_attr_sf.h > @@ -28,11 +28,11 @@ typedef struct xfs_attr_sf_sort { > } xfs_attr_sf_sort_t; > > #define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen) /* space name/value uses */ \ > - (((int)sizeof(xfs_attr_sf_entry_t)-1 + (nlen)+(vlen))) > + (((int)sizeof(xfs_attr_sf_entry_t) + (nlen)+(vlen))) > #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ > - ((1 << (NBBY*(int)sizeof(uint8_t))) - 1) > + (1 << (NBBY*(int)sizeof(uint8_t))) The maximum space for the name and value is still UINT8_MAX, right? I don't think this should change to 256. I also kind of wonder if this should also get changed to be more direct: #define XFS_ATTR_SF_ENTSIZE_MAX (UINT8_MAX) but it's working code, we could/should just leave it be... > #define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \ > - ((int)sizeof(xfs_attr_sf_entry_t)-1 + (sfep)->namelen+(sfep)->valuelen) > + ((int)sizeof(xfs_attr_sf_entry_t) + (sfep)->namelen+(sfep)->valuelen) Can this (and ENTSIZE_BYNAME) use struct_sizeof? --D > #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ > ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep))) > #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \ > diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h > index 059ac108b1b39..e86185a1165b3 100644 > --- a/fs/xfs/libxfs/xfs_da_format.h > +++ b/fs/xfs/libxfs/xfs_da_format.h > @@ -589,7 +589,7 @@ typedef struct xfs_attr_shortform { > uint8_t namelen; /* actual length of name (no NULL) */ > uint8_t valuelen; /* actual length of value (no NULL) */ > uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ > - uint8_t nameval[1]; /* name & value bytes concatenated */ > + uint8_t nameval[]; /* name & value bytes concatenated */ > } list[1]; /* variable sized array */ > } xfs_attr_shortform_t; > > -- > 2.26.2 >
Hi. > > #define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \ > > - ((int)sizeof(xfs_attr_sf_entry_t)-1 + (sfep)->namelen+(sfep)->valuelen) > > + ((int)sizeof(xfs_attr_sf_entry_t) + (sfep)->namelen+(sfep)->valuelen) > > Can this (and ENTSIZE_BYNAME) use struct_sizeof? Regarding our talk on #xfs, I've been playing with it a while today, and IMHO, converting xfs_attr_sf_entsize to use struct_size() is ok, although, entsize_byname, I don't think it's worth it. entsize_byname doesn't get a xfs_attr_sf_entry as argument, so it will require to change the callers to actually pass a struct xfs_attr_sf_entry, and the respective sizes, but, some callers actually don't even have a xfs_attr_sf_entry to pass into it, so IMHO, I don't think it's worth to change it, but by any means, I'll send today a V2 of my patchset containing the changes from V1, and adding the struct_size() into xfs_attr_sf_entry. Cheers. > > --D > > > #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ > > ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep))) > > #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \ > > diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h > > index 059ac108b1b39..e86185a1165b3 100644 > > --- a/fs/xfs/libxfs/xfs_da_format.h > > +++ b/fs/xfs/libxfs/xfs_da_format.h > > @@ -589,7 +589,7 @@ typedef struct xfs_attr_shortform { > > uint8_t namelen; /* actual length of name (no NULL) */ > > uint8_t valuelen; /* actual length of value (no NULL) */ > > uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ > > - uint8_t nameval[1]; /* name & value bytes concatenated */ > > + uint8_t nameval[]; /* name & value bytes concatenated */ > > } list[1]; /* variable sized array */ > > } xfs_attr_shortform_t; > > > > -- > > 2.26.2 > > >
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 305d4bc073370..7bbc97e0e4d4a 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -992,7 +992,7 @@ xfs_attr_shortform_allfit( return 0; if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX) return 0; - bytes += sizeof(struct xfs_attr_sf_entry) - 1 + bytes += sizeof(struct xfs_attr_sf_entry) + name_loc->namelen + be16_to_cpu(name_loc->valuelen); } @@ -1036,10 +1036,8 @@ xfs_attr_shortform_verify( * struct xfs_attr_sf_entry has a variable length. * Check the fixed-offset parts of the structure are * within the data buffer. - * xfs_attr_sf_entry is defined with a 1-byte variable - * array at the end, so we must subtract that off. */ - if (((char *)sfep + sizeof(*sfep) - 1) >= endp) + if (((char *)sfep + sizeof(*sfep)) >= endp) return __this_address; /* Don't allow names with known bad length. */ diff --git a/fs/xfs/libxfs/xfs_attr_sf.h b/fs/xfs/libxfs/xfs_attr_sf.h index bb004fb7944a7..d93012a0be4d0 100644 --- a/fs/xfs/libxfs/xfs_attr_sf.h +++ b/fs/xfs/libxfs/xfs_attr_sf.h @@ -28,11 +28,11 @@ typedef struct xfs_attr_sf_sort { } xfs_attr_sf_sort_t; #define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen) /* space name/value uses */ \ - (((int)sizeof(xfs_attr_sf_entry_t)-1 + (nlen)+(vlen))) + (((int)sizeof(xfs_attr_sf_entry_t) + (nlen)+(vlen))) #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ - ((1 << (NBBY*(int)sizeof(uint8_t))) - 1) + (1 << (NBBY*(int)sizeof(uint8_t))) #define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \ - ((int)sizeof(xfs_attr_sf_entry_t)-1 + (sfep)->namelen+(sfep)->valuelen) + ((int)sizeof(xfs_attr_sf_entry_t) + (sfep)->namelen+(sfep)->valuelen) #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep))) #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \ diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 059ac108b1b39..e86185a1165b3 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -589,7 +589,7 @@ typedef struct xfs_attr_shortform { uint8_t namelen; /* actual length of name (no NULL) */ uint8_t valuelen; /* actual length of value (no NULL) */ uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ - uint8_t nameval[1]; /* name & value bytes concatenated */ + uint8_t nameval[]; /* name & value bytes concatenated */ } list[1]; /* variable sized array */ } xfs_attr_shortform_t;
nameval is a variable-size array, so, define it as it, and remove all the -1 magic number subtractions. Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> --- fs/xfs/libxfs/xfs_attr_leaf.c | 6 ++---- fs/xfs/libxfs/xfs_attr_sf.h | 6 +++--- fs/xfs/libxfs/xfs_da_format.h | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-)