From: Jian Yu Date: Fri, 10 Oct 2014 19:39:26 +0000 (-0700) Subject: LU-4856 obdclass: check val in proc_max_dirty_pages_in_mb() X-Git-Tag: 2.6.90~26 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=7ea002253e1fe5ad46165cd89d9a06fdfb7d83b1;p=fs%2Flustre-release.git LU-4856 obdclass: check val in proc_max_dirty_pages_in_mb() In proc_max_dirty_pages_in_mb(), assigning "__u64 val" to "unsigned long obd_max_dirty_pages" will cause values over 2^32 to be truncated on a 32-bit client (where "unsigned long" is 32 bits, and not 64 bits). This patch fixes the above issue by checking "val" in an acceptable range before assigning it to obd_max_dirty_pages. Signed-off-by: Jian Yu Change-Id: I838b5bab283a0068f72a86f5a990d909c892a9d9 Reviewed-on: http://review.whamcloud.com/12269 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jinshan Xiong --- diff --git a/lustre/obdclass/linux/linux-sysctl.c b/lustre/obdclass/linux/linux-sysctl.c index 7287e0b..1723f05 100644 --- a/lustre/obdclass/linux/linux-sysctl.c +++ b/lustre/obdclass/linux/linux-sysctl.c @@ -183,18 +183,19 @@ proc_max_dirty_pages_in_mb(struct ctl_table *table, int write, if (write) { rc = lprocfs_write_frac_u64_helper(buffer, *lenp, &val, 1 << (20 - PAGE_CACHE_SHIFT)); - obd_max_dirty_pages = (unsigned long)val; /* Don't allow them to let dirty pages exceed 90% of system * memory and set a hard minimum of 4MB. */ - if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) { - CERROR("Refusing to set max dirty pages to %lu, which " - "is more than 90%% of available RAM; setting " - "to %lu\n", obd_max_dirty_pages, + if (val > ((totalram_pages / 10) * 9)) { + CERROR("Refusing to set max dirty pages to "LPU64", " + "which is more than 90%% of available RAM; " + "setting to %lu\n", val, ((totalram_pages / 10) * 9)); obd_max_dirty_pages = ((totalram_pages / 10) * 9); - } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) { + } else if (val < 4 << (20 - PAGE_CACHE_SHIFT)) { obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT); + } else { + obd_max_dirty_pages = val; } } else { char buf[21];