Skip to content

Commit

Permalink
UBIFS: fix oops when R/O file-system is fsync'ed
Browse files Browse the repository at this point in the history
This patch fixes severe UBIFS bug: UBIFS oopses when we 'fsync()' an
file on R/O-mounter file-system. We (the UBIFS authors) incorrectly
thought that VFS would not propagate 'fsync()' down to the file-system
if it is read-only, but this is not the case.

It is easy to exploit this bug using the following simple perl script:

use strict;
use File::Sync qw(fsync sync);

die "File path is not specified" if not defined $ARGV[0];
my $path = $ARGV[0];

open FILE, "<", "$path" or die "Cannot open $path: $!";
fsync(\*FILE) or die "cannot fsync $path: $!";
close FILE or die "Cannot close $path: $!";

Thanks to Reuben Dowle <Reuben.Dowle@navico.com> for reporting about this
issue.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reported-by: Reuben Dowle <Reuben.Dowle@navico.com>
Cc: stable@kernel.org
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Apr 13, 2011
1 parent a6360dd commit 78530bf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/ubifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,9 @@ int ubifs_fsync(struct file *file, int datasync)

dbg_gen("syncing inode %lu", inode->i_ino);

if (inode->i_sb->s_flags & MS_RDONLY)
return 0;

/*
* VFS has already synchronized dirty pages for this inode. Synchronize
* the inode unless this is a 'datasync()' call.
Expand Down

0 comments on commit 78530bf

Please sign in to comment.