• Brian Foster's avatar
    xfs: detect and handle invalid iclog size set by mkfs · a70f9fe5
    Brian Foster authored
    XFS log records have separate fields for the record size and the iclog
    size used to write the record. mkfs.xfs zeroes the log and writes an
    unmount record to generate a clean log for the subsequent mount. The
    userspace record logging code has a bug where the iclog size (h_size)
    field of the log record is hardcoded to 32k, even if a log stripe unit
    is specified. The log record length is correctly extended to the stripe
    unit. Since the kernel log recovery code uses the h_size field to
    determine the log buffer size, this means that the kernel can attempt to
    read/process records larger than the buffer size and overrun the buffer.
    
    This has historically not been a problem because the kernel doesn't
    actually run through log recovery in the clean unmount case. Instead,
    the kernel detects that a single unmount record exists between the head
    and tail and pushes the tail forward such that the log is viewed as
    clean (head == tail). Once CRC verification is enabled, however, all
    records at the head of the log are verified for CRC errors and thus we
    are susceptible to overrun problems if the iclog field is not correct.
    
    While the core problem must be fixed in userspace, this is historical
    behavior that must be detected in the kernel to avoid severe side
    effects such as memory corruption and crashes. Update the log buffer
    size calculation code to detect this condition, warn the user and resize
    the log buffer based on the log stripe unit. Return a corruption error
    in cases where this does not look like a clean filesystem (i.e., the log
    record header indicates more than one operation).
    Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
    Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
    Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
    
    a70f9fe5
xfs_log_recover.c 133 KB