Skip to content

Commit

Permalink
udf: Fix possible corruption when close races with write
Browse files Browse the repository at this point in the history
When we close a file, we remove preallocated blocks from it. But this
truncation was not protected by i_mutex and thus it could have raced with a
write through a different fd and cause crashes or even filesystem corruption.

Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
jankara committed Sep 14, 2009
1 parent 81056dd commit cbc8cc3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/udf/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
static int udf_release_file(struct inode *inode, struct file *filp)
{
if (filp->f_mode & FMODE_WRITE) {
mutex_lock(&inode->i_mutex);
lock_kernel();
udf_discard_prealloc(inode);
unlock_kernel();
mutex_unlock(&inode->i_mutex);
}
return 0;
}
Expand Down

0 comments on commit cbc8cc3

Please sign in to comment.