Skip to contentSkip to conversation

"signed < sizeof()" bug in xfs_attr_shortform_verify() ?

DISCUSSION Alexey Dobriyan 3 participants 3 messages Aug 25, 2020 – Aug 27, 2020

lore
Share & tools
lore
#0 lore raw

xfs_attr_shortform_verify() contains the following code:

	int64_t size = ifp->if_bytes;
        /*
         * Give up if the attribute is way too short.
         */
        if (size < sizeof(struct xfs_attr_sf_hdr))
                return __this_address;

In general "if (signed < sizeof())" is wrong because of how type promotions work. Such check won't catch small negative values.

I don't know XFS well enough to know if negative values were excluded somewhere above the callchain, but maybe someone else does.

#1 lore raw
Quoted 11 lines · Alexey Dobriyan

xfs_attr_shortform_verify() contains the following code:

	int64_t size = ifp->if_bytes;
        /*
         * Give up if the attribute is way too short.
         */
        if (size < sizeof(struct xfs_attr_sf_hdr))
                return __this_address;
Quoted 5 lines

In general "if (signed < sizeof())" is wrong because of how type promotions work. Such check won't catch small negative values.

I don't know XFS well enough to know if negative values were excluded somewhere above the callchain, but maybe someone else does.

The initial allocations are always positive and the subsequent xfs_idata_realloc are checked to prevent if_bytes from going negative, but it does seem funny to me that if_bytes is declared int64_t...

--D

#2 lore raw
Quoted 15 lines · Darrick J. Wong
Quoted 14 lines · Alexey Dobriyan

xfs_attr_shortform_verify() contains the following code:

	int64_t size = ifp->if_bytes;
        /*
         * Give up if the attribute is way too short.
         */
        if (size < sizeof(struct xfs_attr_sf_hdr))
                return __this_address;

In general "if (signed < sizeof())" is wrong because of how type promotions work. Such check won't catch small negative values.

Quoted 6 lines
Quoted 2 lines

I don't know XFS well enough to know if negative values were excluded somewhere above the callchain, but maybe someone else does.

The initial allocations are always positive and the subsequent xfs_idata_realloc are checked to prevent if_bytes from going negative, but it does seem funny to me that if_bytes is declared int64_t...

Yes, the int64_t is weird. IIRC the signednes was done to simplify some arithmertics in the reallocation case, but that shouldn't really leak out..