Whamcloud - gitweb
LU-4856 obdclass: check val in proc_max_dirty_pages_in_mb() 69/12269/4
authorJian Yu <jian.yu@intel.com>
Fri, 10 Oct 2014 19:39:26 +0000 (12:39 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 4 Nov 2014 17:54:13 +0000 (17:54 +0000)
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 <jian.yu@intel.com>
Change-Id: I838b5bab283a0068f72a86f5a990d909c892a9d9
Reviewed-on: http://review.whamcloud.com/12269
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
lustre/obdclass/linux/linux-sysctl.c

index 7287e0b..1723f05 100644 (file)
@@ -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];