diff options
author | Jeff Mahoney <jeffm@suse.com> | 2014-04-02 14:40:26 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2014-04-02 18:06:14 -0400 |
commit | 01d8885785a60ae8f4c37b0ed75bdc96d0fc6a44 (patch) | |
tree | 212ac3940dc154fc2cffe0917c18e15e6e685ee3 /fs/reiserfs | |
parent | 3e0d8a01043ded18711fe4a0a320e4491f580ce1 (diff) |
reiserfs: fix race in readdir
jdm-20004 reiserfs_delete_xattrs: Couldn't delete all xattrs (-2)
The -ENOENT is due to readdir calling dir_emit on the same entry twice.
If the dir_emit callback sleeps and the tree is changed underneath us,
we won't be able to trust deh_offset(deh) anymore. We need to save
next_pos before we might sleep so we can find the next entry.
CC: stable@vger.kernel.org
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/reiserfs')
-rw-r--r-- | fs/reiserfs/dir.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c index 1fd2051109a3..af677353a3f5 100644 --- a/fs/reiserfs/dir.c +++ b/fs/reiserfs/dir.c | |||
@@ -125,6 +125,7 @@ int reiserfs_readdir_inode(struct inode *inode, struct dir_context *ctx) | |||
125 | int d_reclen; | 125 | int d_reclen; |
126 | char *d_name; | 126 | char *d_name; |
127 | ino_t d_ino; | 127 | ino_t d_ino; |
128 | loff_t cur_pos = deh_offset(deh); | ||
128 | 129 | ||
129 | if (!de_visible(deh)) | 130 | if (!de_visible(deh)) |
130 | /* it is hidden entry */ | 131 | /* it is hidden entry */ |
@@ -196,8 +197,9 @@ int reiserfs_readdir_inode(struct inode *inode, struct dir_context *ctx) | |||
196 | if (local_buf != small_buf) { | 197 | if (local_buf != small_buf) { |
197 | kfree(local_buf); | 198 | kfree(local_buf); |
198 | } | 199 | } |
199 | // next entry should be looked for with such offset | 200 | |
200 | next_pos = deh_offset(deh) + 1; | 201 | /* deh_offset(deh) may be invalid now. */ |
202 | next_pos = cur_pos + 1; | ||
201 | 203 | ||
202 | if (item_moved(&tmp_ih, &path_to_entry)) { | 204 | if (item_moved(&tmp_ih, &path_to_entry)) { |
203 | set_cpu_key_k_offset(&pos_key, | 205 | set_cpu_key_k_offset(&pos_key, |