Whamcloud - gitweb
LU-13528 llite: prevent MAX_DIO_SIZE 32-bit truncation 26/38526/4
authorSebastien Buisson <sbuisson@ddn.com>
Thu, 7 May 2020 06:59:40 +0000 (08:59 +0200)
committerOleg Drokin <green@whamcloud.com>
Wed, 27 May 2020 05:04:20 +0000 (05:04 +0000)
On 4kB PAGE_SIZE systems, kmalloc can allocate up to 4MB, which makes
MAX_DIO_SIZE up to 682MB. This number can fit into 32 bits.
But on 64kB PAGE_SIZE systems, kmalloc can allocate up to 512MB, which
then makes MAX_DIO_SIZE up to 1365GB. This needs 64 bits to fit.
Make sure that for every platform MAX_DIO_SIZE is not abusively
truncated, by casting it to size_t.

Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: I9d2c8c4a1ccf0abf0b7647e569b8454365369e8a
Reviewed-on: https://review.whamcloud.com/38526
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/llite/rw26.c

index 2dc2f16..5c4dd7b 100644 (file)
@@ -384,7 +384,7 @@ ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, size_t size,
  * then truncate this to be a full-sized RPC.  For 4kB PAGE_SIZE this is
  * up to 22MB for 128kB kmalloc and up to 682MB for 4MB kmalloc. */
 #define MAX_DIO_SIZE ((MAX_MALLOC / sizeof(struct brw_page) * PAGE_SIZE) & \
-                     ~(DT_MAX_BRW_SIZE - 1))
+                     ~((size_t)DT_MAX_BRW_SIZE - 1))
 
 static ssize_t
 ll_direct_IO_impl(struct kiocb *iocb, struct iov_iter *iter, int rw)