Skip to contentSkip to conversation

reiserfs: fix spurious multiple-fill in reiserfs_readdir_dentry

PATCH In review Jeff Mahoney 3 participants 4 messages May 31, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reiserfs: fix spurious multiple-fill in reiserfs_readdir_dentry

After sleeping for filldir(), we check to see if the file system has changed and research. The next_pos pointer is updated but its value isn't pushed into the key used for the search itself. As a result, the search returns the same item that the last cycle of the loop did and filldir() is called multiple times with the same data.

The end result is that the buffer can contain the same name multiple times. This can be returned to userspace or used internally in the xattr code where it can manifest with the following warning:

jdm-20004 reiserfs_delete_xattrs: Couldn't delete all xattrs (-2)

reiserfs_for_each_xattr uses reiserfs_readdir_dentry to iterate over the xattr names and ends up trying to unlink the same name twice. The second attempt fails with -ENOENT and the error is returned. At some point I'll need to add support into reiserfsck to remove the orphaned directories left behind when this occurs.

The fix is to push the value into the key before researching.

---
 fs/reiserfs/dir.c |    2 ++
 1 file changed, 2 insertions(+)
fs/reiserfs/dir.c +2 -0
@@ -204,6 +204,8 @@ int reiserfs_readdir_dentry(struct dentr
 				next_pos = deh_offset(deh) + 1;
 
 				if (item_moved(&tmp_ih, &path_to_entry)) {
+					set_cpu_key_k_offset(&pos_key,
+							     next_pos);
 					goto research;
 				}
 			}	/* for */
Signature · 1 line
Jeff Mahoney
#1 lore raw
Quoted 12 lines · Jeff Mahoney

After sleeping for filldir(), we check to see if the file system has changed and research. The next_pos pointer is updated but its value isn't pushed into the key used for the search itself. As a result, the search returns the same item that the last cycle of the loop did and filldir() is called multiple times with the same data.

The end result is that the buffer can contain the same name multiple times. This can be returned to userspace or used internally in the xattr code where it can manifest with the following warning:

jdm-20004 reiserfs_delete_xattrs: Couldn't delete all xattrs (-2)

Quoted 7 lines

reiserfs_for_each_xattr uses reiserfs_readdir_dentry to iterate over the xattr names and ends up trying to unlink the same name twice. The second attempt fails with -ENOENT and the error is returned. At some point I'll need to add support into reiserfsck to remove the orphaned directories left behind when this occurs.

The fix is to push the value into the key before researching.

The patch looks good. I've added it to my tree.

Honza

Quoted 21 lines
---
 fs/reiserfs/dir.c |    2 ++
 1 file changed, 2 insertions(+)
fs/reiserfs/dir.c +2 -0
@@ -204,6 +204,8 @@ int reiserfs_readdir_dentry(struct dentr
 				next_pos = deh_offset(deh) + 1;
 
 				if (item_moved(&tmp_ih, &path_to_entry)) {
+					set_cpu_key_k_offset(&pos_key,
+							     next_pos);
 					goto research;
 				}
 			}	/* for */
Signature · 2 lines
-- 
Jeff Mahoney
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 13 lines · Jan Kara
Quoted 12 lines · Jeff Mahoney

After sleeping for filldir(), we check to see if the file system has changed and research. The next_pos pointer is updated but its value isn't pushed into the key used for the search itself. As a result, the search returns the same item that the last cycle of the loop did and filldir() is called multiple times with the same data.

The end result is that the buffer can contain the same name multiple times. This can be returned to userspace or used internally in the xattr code where it can manifest with the following warning:

jdm-20004 reiserfs_delete_xattrs: Couldn't delete all xattrs (-2)

Quoted 8 lines
Quoted 7 lines

reiserfs_for_each_xattr uses reiserfs_readdir_dentry to iterate over the xattr names and ends up trying to unlink the same name twice. The second attempt fails with -ENOENT and the error is returned. At some point I'll need to add support into reiserfsck to remove the orphaned directories left behind when this occurs.

The fix is to push the value into the key before researching.

The patch looks good. I've added it to my tree.

Thanks, Jan.

I have a few other fixes that we've had in SLE11 for a while that should probably make it into the next release as well.

I've published them at:
git://jeffreymahoney.com/linux/linux-upstream reiserfs-for-3.10

There are 3 patches, HEAD is 7c769dbb (reiserfs: fix problems with chowning setuid file w/ xattrs)

It includes this fix.

-Jeff

Quoted 23 lines

Honza

Quoted 21 lines
---
 fs/reiserfs/dir.c |    2 ++
 1 file changed, 2 insertions(+)
fs/reiserfs/dir.c +2 -0
@@ -204,6 +204,8 @@ int reiserfs_readdir_dentry(struct dentr
 				next_pos = deh_offset(deh) + 1;
 
 				if (item_moved(&tmp_ih, &path_to_entry)) {
+					set_cpu_key_k_offset(&pos_key,
+							     next_pos);
 					goto research;
 				}
 			}	/* for */
Signature · 2 lines
-- 
Jeff Mahoney
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#3 lore raw
Quoted 28 lines · Jeff Mahoney
Quoted 13 lines · Jan Kara
Quoted 12 lines · Jeff Mahoney

After sleeping for filldir(), we check to see if the file system has changed and research. The next_pos pointer is updated but its value isn't pushed into the key used for the search itself. As a result, the search returns the same item that the last cycle of the loop did and filldir() is called multiple times with the same data.

The end result is that the buffer can contain the same name multiple times. This can be returned to userspace or used internally in the xattr code where it can manifest with the following warning:

jdm-20004 reiserfs_delete_xattrs: Couldn't delete all xattrs (-2)

Quoted 8 lines
Quoted 7 lines

reiserfs_for_each_xattr uses reiserfs_readdir_dentry to iterate over the xattr names and ends up trying to unlink the same name twice. The second attempt fails with -ENOENT and the error is returned. At some point I'll need to add support into reiserfsck to remove the orphaned directories left behind when this occurs.

The fix is to push the value into the key before researching.

The patch looks good. I've added it to my tree.

Thanks, Jan.

I have a few other fixes that we've had in SLE11 for a while that should probably make it into the next release as well.

Quoted 7 lines

I've published them at:
git://jeffreymahoney.com/linux/linux-upstream reiserfs-for-3.10

There are 3 patches, HEAD is 7c769dbb (reiserfs: fix problems with chowning setuid file w/ xattrs)

It includes this fix.

I've pulled the other two patches into my tree as well. Thanks!

Honza

Quoted 26 lines
Quoted 20 lines
Quoted 20 lines
---
 fs/reiserfs/dir.c |    2 ++
 1 file changed, 2 insertions(+)
fs/reiserfs/dir.c +2 -0
@@ -204,6 +204,8 @@ int reiserfs_readdir_dentry(struct dentr
 				next_pos = deh_offset(deh) + 1;
 
 				if (item_moved(&tmp_ih, &path_to_entry)) {
+					set_cpu_key_k_offset(&pos_key,
+							     next_pos);
 					goto research;
 				}
 			}	/* for */
Signature · 2 lines
-- 
Jeff Mahoney
Signature · 2 lines
Jeff Mahoney
SUSE Labs
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR