Repository navigation
Commit 74d4108
dm bufio: fix integer overflow when limiting maximum cache size
The default max_cache_size_bytes for dm-bufio is meant to be the lesser
of 25% of the size of the vmalloc area and 2% of the size of lowmem.
However, on 32-bit systems the intermediate result in the expression
(VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100
overflows, causing the wrong result to be computed. For example, on a
32-bit system where the vmalloc area is 520093696 bytes, the result is
1174405 rather than the expected 130023424, which makes the maximum
cache size much too small (far less than 2% of lowmem). This causes
severe performance problems for dm-verity users on affected systems.
Fix this by using mult_frac() to correctly multiply by a percentage. Do
this for all places in dm-bufio that multiply by a percentage. Also
replace (VMALLOC_END - VMALLOC_START) with VMALLOC_TOTAL, which contrary
to the comment is now defined in include/linux/vmalloc.h.
Depends-on: 9993bc6 ("sched/x86: Fix overflow in cyc2ns_offset")
Fixes: 95d402f ("dm: add bufio")
Cc: <stable@vger.kernel.org> # v3.2+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>1 parent 5d47c89 commit 74d4108
1 file changed
Lines changed: 6 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
974 | 974 | | |
975 | 975 | | |
976 | 976 | | |
977 | | - | |
| 977 | + | |
| 978 | + | |
978 | 979 | | |
979 | 980 | | |
980 | 981 | | |
| |||
1910 | 1911 | | |
1911 | 1912 | | |
1912 | 1913 | | |
1913 | | - | |
1914 | | - | |
| 1914 | + | |
| 1915 | + | |
1915 | 1916 | | |
1916 | 1917 | | |
1917 | 1918 | | |
1918 | 1919 | | |
1919 | 1920 | | |
1920 | | - | |
1921 | | - | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
1925 | | - | |
| 1921 | + | |
| 1922 | + | |
1926 | 1923 | | |
1927 | 1924 | | |
1928 | 1925 | | |
| |||
0 commit comments