Skip to contentSkip to conversation

nfs: Fix listxattr regression

PATCH In review Andreas Gruenbacher 2 participants 5 messages Dec 11, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs: Fix listxattr regression

Al,

the xattr cleanup patches which are meanwhile in your for-next branch broke listxattr on nfs. Could you please add this fix?

Thanks,
Andreas

--

In removing the list operation of nfs4_xattr_nfs4_label_handler, commit d77ae742 has introduced a NULL pointer dereference in generic_listxattr. Fix by checking for NULL list operations. In addition, skip prefix (as opposed to full-name) xattr handlers there: listing a prefix is not meaningful.

---
 fs/xattr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/xattr.c +6 -3
index bfd4a85..477bda2 100644
@@ -723,15 +723,18 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 
 	if (!buffer) {
 		for_each_xattr_handler(handlers, handler) {
-			if (handler->list(dentry))
-				size += strlen(handler->name) + 1;
+			if (!handler->name ||
+			    (handler->list && !handler->list(dentry)))
+				continue;
+			size += strlen(handler->name) + 1;
 		}
 	} else {
 		char *buf = buffer;
 		size_t len;
 
 		for_each_xattr_handler(handlers, handler) {
-			if (!handler->list(dentry))
+			if (!handler->name ||
+			    (handler->list && !handler->list(dentry)))
 				continue;
 			len = strlen(handler->name);
 			if (len + 1 > buffer_size)
Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 4 lines · Andreas Gruenbacher

Al,

the xattr cleanup patches which are meanwhile in your for-next branch broke listxattr on nfs. Could you please add this fix?

Umm... Would you be OK with folding that into commit in question? I'd rather not introduce a bisect hazard in the first place...

#2 lore raw
Quoted 8 lines · Al Viro
Quoted 4 lines · Andreas Gruenbacher

Al,

the xattr cleanup patches which are meanwhile in your for-next branch broke listxattr on nfs. Could you please add this fix?

Umm... Would you be OK with folding that into commit in question? I'd rather not introduce a bisect hazard in the first place...

Yes sure, if you are okay with rebasing.

I assume that there is no point in reposting the xattr cleanups with this fix included; if you would prefer a repost, let me know.

Thanks,
Andreas

#3 lore raw

PATCH 1/1 nfs: Fix listxattr regression (2)

Al,

here is another fix for the same botched nfs commit. Could you please also merge / fold that? Sorry for the mess.

Thanks,
Andreas

--

Fix another regression introduced in d77ae742: listxattr ended up always failing with -ERANGE on NFSv4.2 mounts with security label support.

---
 fs/nfs/nfs4proc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +2 -2
index e9db118..c57d133 100644
@@ -6296,8 +6296,8 @@ nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
 	int len = 0;
 
 	if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
-		len = security_inode_listsecurity(inode, list, len);
-		if (len > list_len)
+		len = security_inode_listsecurity(inode, list, list_len);
+		if (list_len && len > list_len)
 			return -ERANGE;
 	}
 	return len;
Signature · 1 line
2.5.0
#4 lore raw

Re: [PATCH] nfs: Fix listxattr regression (2)

Quoted 4 lines · Andreas Gruenbacher

Al,

here is another fix for the same botched nfs commit. Could you please also merge / fold that? Sorry for the mess.

I've pushed a branch with those two fixes here:

git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux xattr-wip2

This is your work.xattr branch with the fixes folded in and with your Signed-off-by tags removed from the two commits that have been modified:

nfs: Move call to security_inode_listsecurity into nfs_listxattr xattr handlers: Simplify list operation

Diff between work.xattr and xattr-wip2 below.

Thanks,
Andreas

fs/nfs/nfs4proc.c +2 -2
index e9db118..c57d133 100644
@@ -6296,8 +6296,8 @@ nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
 	int len = 0;
 
 	if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
-		len = security_inode_listsecurity(inode, list, len);
-		if (len > list_len)
+		len = security_inode_listsecurity(inode, list, list_len);
+		if (list_len && len > list_len)
 			return -ERANGE;
 	}
 	return len;
fs/xattr.c +7 -5
index bfd4a85..d7f5037 100644
@@ -723,21 +723,23 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 
 	if (!buffer) {
 		for_each_xattr_handler(handlers, handler) {
-			if (handler->list(dentry))
-				size += strlen(handler->name) + 1;
+			if (!handler->name ||
+			    (handler->list && !handler->list(dentry)))
+				continue;
+			size += strlen(handler->name) + 1;
 		}
 	} else {
 		char *buf = buffer;
 		size_t len;
 
 		for_each_xattr_handler(handlers, handler) {
-			if (!handler->list(dentry))
+			if (!handler->name ||
+			    (handler->list && !handler->list(dentry)))
 				continue;
 			len = strlen(handler->name);
 			if (len + 1 > buffer_size)
 				return -ERANGE;
-			memcpy(buf, handler->name, len);
-			buf[len] = 0;
+			memcpy(buf, handler->name, len + 1);
 			buf += len + 1;
 			buffer_size -= len + 1;
 		}