Re: [PATCH v15 01/17] block: Add bio_add_folio()

Matthew Wilcox
2021-07-30T11:32:22Z

On Fri, Jul 30, 2021 at 04:25:17PM +0800, Ming Lei wrote:
> > +size_t bio_add_folio(struct bio *bio, struct folio *folio, size_t len,
> > + size_t off)
> > +{
> > + if (len > UINT_MAX || off > UINT_MAX)
> > + return 0;
>
> The added page shouldn't cross 4G boundary, so just wondering why not
> check 'if (len > UINT_MAX - off)'?

That check is going to be vulnerable to wrapping, eg
off = 2^32, len = 512

It would be less vulnerable to wrapping if we cast both sides to
signed long. But at that point, we're firmly into obscuring the
intent of the check.