OSDN Git Service

xfs: synchronous buffer IO needs a reference
authorDave Chinner <dchinner@redhat.com>
Wed, 1 Oct 2014 23:04:11 +0000 (09:04 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 1 Oct 2014 23:04:11 +0000 (09:04 +1000)
commite11bb8052c3f500e66142f33579cc054d691a8fb
treea0a569a145631d37bd629a9c8a156e49515de626
parentcf53e99d192171a58791136d33fd3fea5d8bab35
xfs: synchronous buffer IO needs a reference

When synchronous IO runs IO completion work, it does so without an
IO reference or a hold reference on the buffer. The IO "hold
reference" is owned by the submitter, and released when the
submission is complete. The IO reference is released when both the
submitter and the bio end_io processing is run, and so if the io
completion work is run from IO completion context, it is run without
an IO reference.

Hence we can get the situation where the submitter can submit the
IO, see an error on the buffer and unlock and free the buffer while
there is still IO in progress. This leads to use-after-free and
memory corruption.

Fix this by taking a "sync IO hold" reference that is owned by the
IO and not released until after the buffer completion calls are run
to wake up synchronous waiters. This means that the buffer will not
be freed in any circumstance until all IO processing is completed.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_buf.c