* [PATCH] dm-stripe: fix a possible integer overflow
@ 2025-07-07 10:39 Mikulas Patocka
2025-07-07 13:15 ` John Garry
2025-07-07 13:21 ` Dongsheng Yang
0 siblings, 2 replies; 4+ messages in thread
From: Mikulas Patocka @ 2025-07-07 10:39 UTC (permalink / raw)
To: Alasdair Kergon, Mike Snitzer, John Garry; +Cc: dm-devel
There's a possible integer overflow in stripe_io_hints if we have too
large chunk size. Test if the overflow happened, and if it did, don't set
limits->io_min and limits->io_opt;
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
---
drivers/md/dm-stripe.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
Index: linux-2.6/drivers/md/dm-stripe.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-stripe.c 2025-07-06 15:02:23.000000000 +0200
+++ linux-2.6/drivers/md/dm-stripe.c 2025-07-07 12:32:49.000000000 +0200
@@ -456,10 +456,14 @@ static void stripe_io_hints(struct dm_ta
struct queue_limits *limits)
{
struct stripe_c *sc = ti->private;
- unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT;
+ unsigned int io_min = sc->chunk_size << SECTOR_SHIFT;
+ unsigned int io_opt = io_min * sc->stripes;
- limits->io_min = chunk_size;
- limits->io_opt = chunk_size * sc->stripes;
+ if (io_min >> SECTOR_SHIFT == sc->chunk_size &&
+ io_opt / sc->stripes == io_min) {
+ limits->io_min = io_min;
+ limits->io_opt = io_opt;
+ }
}
static struct target_type stripe_target = {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dm-stripe: fix a possible integer overflow
2025-07-07 10:39 [PATCH] dm-stripe: fix a possible integer overflow Mikulas Patocka
@ 2025-07-07 13:15 ` John Garry
2025-07-07 13:21 ` Dongsheng Yang
1 sibling, 0 replies; 4+ messages in thread
From: John Garry @ 2025-07-07 13:15 UTC (permalink / raw)
To: Mikulas Patocka, Alasdair Kergon, Mike Snitzer; +Cc: dm-devel, martin.petersen
On 07/07/2025 11:39, Mikulas Patocka wrote:
> There's a possible integer overflow in stripe_io_hints if we have too
> large chunk size. Test if the overflow happened, and if it did, don't set
> limits->io_min and limits->io_opt;
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
>
Seems fine, I cc'ed Martin as I asked him about this earlier:
Reviewed-by: John Garry <john.g.garry@oracle.com>
And this will conflict with
https://lore.kernel.org/linux-xfs/20250707131135.1572830-1-john.g.garry@oracle.com/T/#t,
as to be expected
> ---
> drivers/md/dm-stripe.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/drivers/md/dm-stripe.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-stripe.c 2025-07-06 15:02:23.000000000 +0200
> +++ linux-2.6/drivers/md/dm-stripe.c 2025-07-07 12:32:49.000000000 +0200
> @@ -456,10 +456,14 @@ static void stripe_io_hints(struct dm_ta
> struct queue_limits *limits)
> {
> struct stripe_c *sc = ti->private;
> - unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT;
> + unsigned int io_min = sc->chunk_size << SECTOR_SHIFT;
> + unsigned int io_opt = io_min * sc->stripes;
>
> - limits->io_min = chunk_size;
> - limits->io_opt = chunk_size * sc->stripes;
> + if (io_min >> SECTOR_SHIFT == sc->chunk_size &&
> + io_opt / sc->stripes == io_min) {
> + limits->io_min = io_min;
> + limits->io_opt = io_opt;
> + }
> }
>
> static struct target_type stripe_target = {
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dm-stripe: fix a possible integer overflow
2025-07-07 10:39 [PATCH] dm-stripe: fix a possible integer overflow Mikulas Patocka
2025-07-07 13:15 ` John Garry
@ 2025-07-07 13:21 ` Dongsheng Yang
2025-07-07 13:30 ` Mikulas Patocka
1 sibling, 1 reply; 4+ messages in thread
From: Dongsheng Yang @ 2025-07-07 13:21 UTC (permalink / raw)
To: Mikulas Patocka, Alasdair Kergon, Mike Snitzer, John Garry; +Cc: dm-devel
在 7/7/2025 6:39 PM, Mikulas Patocka 写道:
> There's a possible integer overflow in stripe_io_hints if we have too
> large chunk size. Test if the overflow happened, and if it did, don't set
> limits->io_min and limits->io_opt;
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
>
> ---
> drivers/md/dm-stripe.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/drivers/md/dm-stripe.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-stripe.c 2025-07-06 15:02:23.000000000 +0200
> +++ linux-2.6/drivers/md/dm-stripe.c 2025-07-07 12:32:49.000000000 +0200
> @@ -456,10 +456,14 @@ static void stripe_io_hints(struct dm_ta
> struct queue_limits *limits)
> {
> struct stripe_c *sc = ti->private;
> - unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT;
> + unsigned int io_min = sc->chunk_size << SECTOR_SHIFT;
> + unsigned int io_opt = io_min * sc->stripes;
>
> - limits->io_min = chunk_size;
> - limits->io_opt = chunk_size * sc->stripes;
> + if (io_min >> SECTOR_SHIFT == sc->chunk_size &&
> + io_opt / sc->stripes == io_min) {
> + limits->io_min = io_min;
> + limits->io_opt = io_opt;
> + }
Hi Mikulas,
What about using check_xxx_overflow() ? something like:
if (check_shl_overflow(sc->chunk_size, SECTOR_SHIFT, &io_min))
return;
if (check_mul_overflow(io_min, sc->stripes, &io_opt))
return;
limits->io_min = io_min;
limits->io_opt = io_opt;
> }
>
> static struct target_type stripe_target = {
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dm-stripe: fix a possible integer overflow
2025-07-07 13:21 ` Dongsheng Yang
@ 2025-07-07 13:30 ` Mikulas Patocka
0 siblings, 0 replies; 4+ messages in thread
From: Mikulas Patocka @ 2025-07-07 13:30 UTC (permalink / raw)
To: Dongsheng Yang; +Cc: Alasdair Kergon, Mike Snitzer, John Garry, dm-devel
[-- Attachment #1: Type: text/plain, Size: 1861 bytes --]
On Mon, 7 Jul 2025, Dongsheng Yang wrote:
>
> 在 7/7/2025 6:39 PM, Mikulas Patocka 写道:
> > There's a possible integer overflow in stripe_io_hints if we have too
> > large chunk size. Test if the overflow happened, and if it did, don't set
> > limits->io_min and limits->io_opt;
> >
> > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > Cc: stable@vger.kernel.org
> >
> > ---
> > drivers/md/dm-stripe.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > Index: linux-2.6/drivers/md/dm-stripe.c
> > ===================================================================
> > --- linux-2.6.orig/drivers/md/dm-stripe.c 2025-07-06 15:02:23.000000000
> > +0200
> > +++ linux-2.6/drivers/md/dm-stripe.c 2025-07-07 12:32:49.000000000 +0200
> > @@ -456,10 +456,14 @@ static void stripe_io_hints(struct dm_ta
> > struct queue_limits *limits)
> > {
> > struct stripe_c *sc = ti->private;
> > - unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT;
> > + unsigned int io_min = sc->chunk_size << SECTOR_SHIFT;
> > + unsigned int io_opt = io_min * sc->stripes;
> > - limits->io_min = chunk_size;
> > - limits->io_opt = chunk_size * sc->stripes;
> > + if (io_min >> SECTOR_SHIFT == sc->chunk_size &&
> > + io_opt / sc->stripes == io_min) {
> > + limits->io_min = io_min;
> > + limits->io_opt = io_opt;
> > + }
>
>
> Hi Mikulas,
>
> What about using check_xxx_overflow() ? something like:
>
>
> if (check_shl_overflow(sc->chunk_size, SECTOR_SHIFT, &io_min))
> return;
>
>
> if (check_mul_overflow(io_min, sc->stripes, &io_opt))
> return;
>
> limits->io_min = io_min;
> limits->io_opt = io_opt;
>
> > }
> > static struct target_type stripe_target = {
> >
> >
Yes, that's a good idea.
I changed the patch to use these macros.
Mikulas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-07 13:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 10:39 [PATCH] dm-stripe: fix a possible integer overflow Mikulas Patocka
2025-07-07 13:15 ` John Garry
2025-07-07 13:21 ` Dongsheng Yang
2025-07-07 13:30 ` Mikulas Patocka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.