Skip to contentSkip to conversation

ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get

PATCH In review Wang Sheng-Hui 2 participants 2 messages Jul 22, 2011 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get

Quoted 1 line

From 667173a18b671896f933c5952fa211601d2e5ab0 Mon Sep 17 00:00:00 2001

From: Wang Sheng-Hui <[email protected]>
Date: Fri, 22 Jul 2011 08:50:13 -0500
Subject: [PATCH] ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get

The patch is against 3.0.

In ext2_xattr_get, the code will acquire sem lock first, later check the length of xattr name_len > 255. It's kind of time consuming, and we should do the basic check before the time consuming acquiring sem lock.

---
 fs/ext2/xattr.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
fs/ext2/xattr.c +5 -5
index 5299706..d27b71f 100644
@@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
 
 	if (name == NULL)
 		return -EINVAL;
+	name_len = strlen(name);
+	if (name_len > 255)
+		return -ERANGE;
+
 	down_read(&EXT2_I(inode)->xattr_sem);
 	error = -ENODATA;
 	if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +185,8 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
 		error = -EIO;
 		goto cleanup;
 	}
-	/* find named attribute */
-	name_len = strlen(name);
 
-	error = -ERANGE;
-	if (name_len > 255)
-		goto cleanup;
+	/* find named attribute */
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		struct ext2_xattr_entry *next =
Signature · 1 line
1.7.1
#1 lore raw

Hello,

Quoted 11 lines · Wang Sheng-Hui

From 667173a18b671896f933c5952fa211601d2e5ab0 Mon Sep 17 00:00:00 2001
From: Wang Sheng-Hui <[email protected]>
Date: Fri, 22 Jul 2011 08:50:13 -0500
Subject: [PATCH] ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get

The patch is against 3.0.

In ext2_xattr_get, the code will acquire sem lock first, later check the length of xattr name_len > 255. It's kind of time consuming, and we should do the basic check before the time consuming acquiring sem lock.

Well, but the check name_len > 255 is almost never true so it does not
really make a difference... But I see ext2_xattr_set() also checks the length first so it probably makes sense from consistency point of view. So I'll take the patch into my tree.

Honza

Quoted 38 lines
---
 fs/ext2/xattr.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
fs/ext2/xattr.c +5 -5
index 5299706..d27b71f 100644
@@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
 
 	if (name == NULL)
 		return -EINVAL;
+	name_len = strlen(name);
+	if (name_len > 255)
+		return -ERANGE;
+
 	down_read(&EXT2_I(inode)->xattr_sem);
 	error = -ENODATA;
 	if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +185,8 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
 		error = -EIO;
 		goto cleanup;
 	}
-	/* find named attribute */
-	name_len = strlen(name);
 
-	error = -ERANGE;
-	if (name_len > 255)
-		goto cleanup;
+	/* find named attribute */
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		struct ext2_xattr_entry *next =
Signature · 1 line
1.7.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR