* [bug report] block: integer overflow in __bvec_gap_to_prev()
@ 2024-06-11 14:23 Roman Smirnov
2024-06-11 15:15 ` Keith Busch
0 siblings, 1 reply; 3+ messages in thread
From: Roman Smirnov @ 2024-06-11 14:23 UTC (permalink / raw)
To: axboe, linux-kernel, linux-block
Cc: Karina Yankevich, lvc-patches, Sergey Shtylyov
Hello.
There is a case of integer overflow in __bvec_gap_to_prev():
((bprv->bv_offset + bprv->bv_len) & lim->virt_boundary_mask);
bio_vec can cross multiple pages:
https://lore.kernel.org/lkml/20190215111324.30129-1-ming.lei@redhat.com/t/
So, in case bio has one bio_vec bv_len can have a maximum value of UINT_MAX.
The check happens in bio_full(). In the case when bv_len is equal to
UINT_MAX and bv_offset is greater than zero, an overflow may occur.
Found by Linux Verification Center (linuxtesting.org) with Svace.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] block: integer overflow in __bvec_gap_to_prev()
2024-06-11 14:23 [bug report] block: integer overflow in __bvec_gap_to_prev() Roman Smirnov
@ 2024-06-11 15:15 ` Keith Busch
2024-06-13 15:27 ` Roman Smirnov
0 siblings, 1 reply; 3+ messages in thread
From: Keith Busch @ 2024-06-11 15:15 UTC (permalink / raw)
To: Roman Smirnov
Cc: axboe, linux-kernel, linux-block, Karina Yankevich, lvc-patches,
Sergey Shtylyov
On Tue, Jun 11, 2024 at 02:23:48PM +0000, Roman Smirnov wrote:
> Hello.
>
> There is a case of integer overflow in __bvec_gap_to_prev():
>
> ((bprv->bv_offset + bprv->bv_len) & lim->virt_boundary_mask);
>
> bio_vec can cross multiple pages:
>
> https://lore.kernel.org/lkml/20190215111324.30129-1-ming.lei@redhat.com/t/
>
> So, in case bio has one bio_vec bv_len can have a maximum value of UINT_MAX.
> The check happens in bio_full(). In the case when bv_len is equal to
> UINT_MAX and bv_offset is greater than zero, an overflow may occur.
Does it matter? The lower bits checked against the mask should be the
same regardless of overflow.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] block: integer overflow in __bvec_gap_to_prev()
2024-06-11 15:15 ` Keith Busch
@ 2024-06-13 15:27 ` Roman Smirnov
0 siblings, 0 replies; 3+ messages in thread
From: Roman Smirnov @ 2024-06-13 15:27 UTC (permalink / raw)
To: kbusch
Cc: Karina Yankevich, lvc-patches, axboe, linux-kernel, linux-block,
Sergey Shtylyov
On Tue, 2024-06-11 at 09:15 -0600, Keith Busch wrote:
> On Tue, Jun 11, 2024 at 02:23:48PM +0000, Roman Smirnov wrote:
> > Hello.
> >
> > There is a case of integer overflow in __bvec_gap_to_prev():
> >
> > ((bprv->bv_offset + bprv->bv_len) & lim->virt_boundary_mask);
> >
> > bio_vec can cross multiple pages:
> >
> > https://lore.kernel.org/lkml/20190215111324.30129-1-ming.lei@redhat.com/t/
> >
> > So, in case bio has one bio_vec bv_len can have a maximum value of UINT_MAX.
> > The check happens in bio_full(). In the case when bv_len is equal to
> > UINT_MAX and bv_offset is greater than zero, an overflow may occur.
>
> Does it matter? The lower bits checked against the mask should be the
> same regardless of overflow.
There are several other places where this kind of thing happens:
https://elixir.bootlin.com/linux/latest/source/block/blk-merge.c#L292
https://elixir.bootlin.com/linux/latest/source/block/blk.h#L331
I think in those cases overflow would make a difference.
I also found a comment before __bio_add_page(). It says that the
caller should watch out for free space in bio:
https://elixir.bootlin.com/linux/latest/source/block/bio.c#L1075
But what happens if it doesn't keep a check on it? Such code
won't get into the kernel?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-13 15:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11 14:23 [bug report] block: integer overflow in __bvec_gap_to_prev() Roman Smirnov
2024-06-11 15:15 ` Keith Busch
2024-06-13 15:27 ` Roman Smirnov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®