Whamcloud - gitweb
libext2fs: don't memcpy identical pointers when writing a cache block
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 4 Nov 2014 16:43:08 +0000 (11:43 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 4 Nov 2014 16:43:08 +0000 (11:43 -0500)
commit8d5324c43f51ac7dc797501cf94270a1c339cb5a
treea17399745b7fa93945a0a0e2812682ea46c76206
parentdab7435917698bb490cce61fc8be1be0a862cf66
libext2fs: don't memcpy identical pointers when writing a cache block

Sami Liedes found a scenario where we could memcpy incorrectly:

If a block read fails during an e2fsck run, the UNIX IO manager will
call the io->read_error routine with a pointer to the internal block
cache.  The e2fsck read error handler immediately tries to write the
buffer back out to disk(!), at which point the block write code will
try to copy the buffer contents back into the block cache.  Normally
this is fine, but not when the write buffer is the cache itself!

So, plumb in a trivial check for this condition.  A more thorough
solution would pass a duplicated buffer to the IO error handlers, but
I don't know if that happens frequently enough to be worth the extra
point of failure.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/unix_io.c