• Martin Schwidefsky's avatar
    mm: do_xip_mapping_read: fix length calculation · 58984ce2
    Martin Schwidefsky authored
    The calculation of the value nr in do_xip_mapping_read is incorrect.  If
    the copy required more than one iteration in the do while loop the copies
    variable will be non-zero.  The maximum length that may be passed to the
    call to copy_to_user(buf+copied, xip_mem+offset, nr) is len-copied but the
    check only compares against (nr > len).
    
    This bug is the cause for the heap corruption Carsten has been chasing
    for so long:
    
    *** glibc detected *** /bin/bash: free(): invalid next size (normal): 0x00000000800e39f0 ***
    ======= Backtrace: =========
    /lib64/libc.so.6[0x200000b9b44]
    /lib64/libc.so.6(cfree+0x8e)[0x200000bdade]
    /bin/bash(free_buffered_stream+0x32)[0x80050e4e]
    /bin/bash(close_buffered_stream+0x1c)[0x80050ea4]
    /bin/bash(unset_bash_input+0x2a)[0x8001c366]
    /bin/bash(make_child+0x1d4)[0x8004115c]
    /bin/bash[0x8002fc3c]
    /bin/bash(execute_command_internal+0x656)[0x8003048e]
    /bin/bash(execute_command+0x5e)[0x80031e1e]
    /bin/bash(execute_command_internal+0x79a)[0x80030...
    58984ce2
filemap_xip.c 11 KB