]> git.baikalelectronics.ru Git - kernel.git/commitdiff
block: fix get_max_segment_size() overflow on 32bit arch
authorMing Lei <ming.lei@redhat.com>
Sat, 11 Jan 2020 12:57:43 +0000 (20:57 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 14 Jan 2020 20:37:40 +0000 (13:37 -0700)
Commit e03d37072c90 starts to take account of segment's start dma address
when computing max segment size, and data type of 'unsigned long'
is used to do that. However, the segment mask may be 0xffffffff, so
the figured out segment size may be overflowed in case of zero physical
address on 32bit arch.

Fix the issue by returning queue_max_segment_size() directly when that
happens.

Fixes: e03d37072c90 ("block: fix splitting segments on boundary masks")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Cc: Christoph Hellwig <hch@lst.de>
Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-merge.c

index 347782a24a3563266bcba9725c48355ab82f2faf..1534ed736363fd807998525d3ddd828e566004f8 100644 (file)
@@ -164,8 +164,13 @@ static inline unsigned get_max_segment_size(const struct request_queue *q,
        unsigned long mask = queue_segment_boundary(q);
 
        offset = mask & (page_to_phys(start_page) + offset);
-       return min_t(unsigned long, mask - offset + 1,
-                    queue_max_segment_size(q));
+
+       /*
+        * overflow may be triggered in case of zero page physical address
+        * on 32bit arch, use queue's max segment size when that happens.
+        */
+       return min_not_zero(mask - offset + 1,
+                       (unsigned long)queue_max_segment_size(q));
 }
 
 /**