]> Pileus Git - ~andy/linux/commit
ext4: punch_hole should wait for DIO writers
authorDmitry Monakhov <dmonakhov@openvz.org>
Mon, 1 Oct 2012 03:03:42 +0000 (23:03 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 1 Oct 2012 03:03:42 +0000 (23:03 -0400)
commit02d262dffcf4c74e5c4612ee736bdb94f18ed5b9
tree1afa479ec99369e739f789ff020df4fba9a4aab8
parent1f555cfa29e8f787d675e8390f88ce517a37271a
ext4: punch_hole should wait for DIO writers

punch_hole is the place where we have to wait for all existing writers
(writeback, aio, dio), but currently we simply flush pended end_io request
which is not sufficient. Other issue is that punch_hole performed w/o i_mutex
held which obviously result in dangerous data corruption due to
write-after-free.

This patch performs following changes:
- Guard punch_hole with i_mutex
- Recheck inode flags under i_mutex
- Block all new dio readers in order to prevent information leak caused by
  read-after-free pattern.
- punch_hole now wait for all writers in flight
  NOTE: XXX write-after-free race is still possible because new dirty pages
  may appear due to mmap(), and currently there is no easy way to stop
  writeback while punch_hole is in progress.

[ Fixed error return from ext4_ext_punch_hole() to make sure that we
  release i_mutex before returning EPERM or ETXTBUSY -- Ted ]

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/extents.c