• Eric Biggers's avatar
    dm bufio: fix integer overflow when limiting maximum cache size · 6609a3cd
    Eric Biggers authored
    commit 74d4108d upstream.
    
    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...
    6609a3cd
dm-bufio.c 47.1 KB