• Andrew Morton's avatar
    [PATCH] readv/writev bounds checking fixes · d4872de3
    Andrew Morton authored
    - writev currently returns -EFAULT if _any_ of the segments has an
    invalid address.  We should only return -EFAULT if the first segment
    has a bad address.
    
    If some of the first segments have valid addresses we need to write
    them and return a partial result.
    
    - The current code only checks if the sum-of-lengths is negative.  If
    individual segments have a negative length but the result is positive
    we miss that.
    
    So rework the code to detect this, and to be immune to odd wrapping
    situations.
    
    As a bonus, we save one pass across the iovec.
    
    - ditto for readv.
    
    The check for "does any segment have a negative length" has already
    been performed in do_readv_writev(), but it's basically free here, and
    we need to do it for generic_file_read/write anyway.
    
    This all means that the iov_length() function is unsafe because of
    wrap/overflow isues.  It should only be used after the
    generic_file_read/write or do_readv_writev() checking has been
    performed.  Its callers have been reviewed and they are OK.
    
    The code now passes LTP testing and has been QA'd by Janet's team.
    d4872de3
filemap.c 57.7 KB