From: Damien Le Moal <Damien.LeMoal@wdc.com>
To: "hch@lst.de" <hch@lst.de>, "mpatocka@redhat.com" <mpatocka@redhat.com>
Cc: "tom.ty89@gmail.com" <tom.ty89@gmail.com>,
"dm-devel@redhat.com" <dm-devel@redhat.com>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"gmazyland@gmail.com" <gmazyland@gmail.com>,
"axboe@fb.com" <axboe@fb.com>,
"axboe@kernel.dk" <axboe@kernel.dk>
Subject: Re: [dm-devel] [BUG] BLKZEROOUT on dm-crypt container cause OOM / kernel panic
Date: Mon, 14 Aug 2017 04:04:50 +0000 [thread overview]
Message-ID: <1502683489.903.1.camel@wdc.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1708132245190.18210@file01.intranet.prod.int.rdu2.redhat.com>
On Sun, 2017-08-13 at 22:47 -0400, Mikulas Patocka wrote:
>
> On Wed, 9 Aug 2017, hch@lst.de wrote:
>
> > Does commit 615d22a51c04856efe62af6e1d5b450aaf5cc2c0
> > "block: Fix __blkdev_issue_zeroout loop" fix the issue for you?
> >
> > --
> > dm-devel mailing list
> > dm-devel@redhat.com
> > https://www.redhat.com/mailman/listinfo/dm-devel
>
> I think that patch is incorrect. sector_t may be a 32-bit type and
> nr_sects << 9 may overflow.
>
> static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects)
> {
> sector_t bytes = (nr_sects << 9) + PAGE_SIZE - 1;
>
> return min(bytes >> PAGE_SHIFT, (sector_t)BIO_MAX_PAGES);
> }
>
> Mikulas
Mikulas,
Does the follwing patch fix the problem ?
From 947b3cf41e759b2b23f684e215e651d0c8037f88 Mon Sep 17 00:00:00 2001
From: Damien Le Moal <damien.lemoal@wdc.com>
Date: Mon, 14 Aug 2017 13:01:16 +0900
Subject: [PATCH] block: Fix __blkdev_sectors_to_bio_pages()
On 32bit systems where sector_t is a 32bits type, the calculation of
bytes may overflow. Use the u64 type for the local calculation to avoid
overflows.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
block/blk-lib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 3fe0aec90597..ccf22dba21f0 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -269,9 +269,9 @@ static int __blkdev_issue_write_zeroes(struct block_device
*bdev,
*/
static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects)
{
- sector_t bytes = (nr_sects << 9) + PAGE_SIZE - 1;
+ u64 bytes = ((u64)nr_sects << 9) + PAGE_SIZE - 1;
- return min(bytes >> PAGE_SHIFT, (sector_t)BIO_MAX_PAGES);
+ return min(bytes >> PAGE_SHIFT, (u64)BIO_MAX_PAGES);
}
/**
--
2.13.4
--
Damien Le Moal
Western Digital
next prev parent reply other threads:[~2017-08-14 4:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 10:23 [BUG] BLKZEROOUT on dm-crypt container cause OOM / kernel panic Tom Yan
2017-08-09 13:38 ` hch
2017-08-09 18:21 ` [dm-devel] " Ondrej Kozina
2017-08-09 23:27 ` Tom Yan
2017-08-10 10:14 ` Tom Yan
2017-08-14 2:47 ` [dm-devel] " Mikulas Patocka
2017-08-14 4:04 ` Damien Le Moal [this message]
2017-08-15 0:01 ` [PATCH] fix an integer overflow in __blkdev_sectors_to_bio_pages Mikulas Patocka
2017-08-15 3:43 ` Damien Le Moal
2017-09-11 14:58 ` Mike Snitzer
2017-09-11 15:47 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1502683489.903.1.camel@wdc.com \
--to=damien.lemoal@wdc.com \
--cc=axboe@fb.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=gmazyland@gmail.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=tom.ty89@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox