Skip to content

Commit 03b5bb3

Browse files
Wang Sheng-Huijankara
authored andcommitted
ext2: check xattr name_len before acquiring xattr_sem in ext2_xattr_get
In ext2_xattr_get(), the code will acquire xattr_sem first, later checks the length of xattr name_len > 255. It's unnecessarily time consuming and also ext2_xattr_set() checks the length before other checks. So move the check before acquiring xattr_sem to make these two functions consistent. Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent c878c73 commit 03b5bb3

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎fs/ext2/xattr.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
161161

162162
if (name == NULL)
163163
return -EINVAL;
164+
name_len = strlen(name);
165+
if (name_len > 255)
166+
return -ERANGE;
167+
164168
down_read(&EXT2_I(inode)->xattr_sem);
165169
error = -ENODATA;
166170
if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +185,8 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
181185
error = -EIO;
182186
goto cleanup;
183187
}
184-
/* find named attribute */
185-
name_len = strlen(name);
186188

187-
error = -ERANGE;
188-
if (name_len > 255)
189-
goto cleanup;
189+
/* find named attribute */
190190
entry = FIRST_ENTRY(bh);
191191
while (!IS_LAST_ENTRY(entry)) {
192192
struct ext2_xattr_entry *next =

0 commit comments

Comments
 (0)