aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@suse.cz>2008-04-30 03:54:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-30 11:29:51 -0400
commit5559b8f4d1f630b8614b6c8e13b8bf6c9c45d7d7 (patch)
tree69db92193c0b27a493334ec1ecad456e75c8e257 /fs/fuse
parentb48badf013018ef2aa4a46416454bdb18f77fb01 (diff)
fuse: fix race in llseek
Fuse doesn't use i_mutex to protect setting i_size, and so generic_file_llseek() can be racy: it doesn't use i_size_read(). So do a fuse specific llseek method, which does use i_size_read(). [akpm@linux-foundation.org: make `retval' loff_t] Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/fuse')
-rw-r--r--fs/fuse/file.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 2d3649e42599..9ced35b00686 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1431,8 +1431,33 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
1431 return err ? 0 : outarg.block; 1431 return err ? 0 : outarg.block;
1432} 1432}
1433 1433
1434static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
1435{
1436 loff_t retval;
1437 struct inode *inode = file->f_path.dentry->d_inode;
1438
1439 mutex_lock(&inode->i_mutex);
1440 switch (origin) {
1441 case SEEK_END:
1442 offset += i_size_read(inode);
1443 break;
1444 case SEEK_CUR:
1445 offset += file->f_pos;
1446 }
1447 retval = -EINVAL;
1448 if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
1449 if (offset != file->f_pos) {
1450 file->f_pos = offset;
1451 file->f_version = 0;
1452 }
1453 retval = offset;
1454 }
1455 mutex_unlock(&inode->i_mutex);
1456 return retval;
1457}
1458
1434static const struct file_operations fuse_file_operations = { 1459static const struct file_operations fuse_file_operations = {
1435 .llseek = generic_file_llseek, 1460 .llseek = fuse_file_llseek,
1436 .read = do_sync_read, 1461 .read = do_sync_read,
1437 .aio_read = fuse_file_aio_read, 1462 .aio_read = fuse_file_aio_read,
1438 .write = do_sync_write, 1463 .write = do_sync_write,
@@ -1448,7 +1473,7 @@ static const struct file_operations fuse_file_operations = {
1448}; 1473};
1449 1474
1450static const struct file_operations fuse_direct_io_file_operations = { 1475static const struct file_operations fuse_direct_io_file_operations = {
1451 .llseek = generic_file_llseek, 1476 .llseek = fuse_file_llseek,
1452 .read = fuse_direct_read, 1477 .read = fuse_direct_read,
1453 .write = fuse_direct_write, 1478 .write = fuse_direct_write,
1454 .open = fuse_open, 1479 .open = fuse_open,