Skip to content

Commit c776cff

Browse files
Andreas Gruenbachergregkh
authored andcommitted
sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names
commit 971df15 upstream. The standard return value for unsupported attribute names is -EOPNOTSUPP, as opposed to undefined but supported attributes (-ENODATA). Also, fail for attribute names like "system.sockprotonameXXX" and simplify the code a bit. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> [removes a build warning on 4.4.y - gregkh] Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c8d6672 commit c776cff

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

net/socket.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,27 +470,15 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
470470
static ssize_t sockfs_getxattr(struct dentry *dentry,
471471
const char *name, void *value, size_t size)
472472
{
473-
const char *proto_name;
474-
size_t proto_size;
475-
int error;
476-
477-
error = -ENODATA;
478-
if (!strncmp(name, XATTR_NAME_SOCKPROTONAME, XATTR_NAME_SOCKPROTONAME_LEN)) {
479-
proto_name = dentry->d_name.name;
480-
proto_size = strlen(proto_name);
481-
473+
if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
482474
if (value) {
483-
error = -ERANGE;
484-
if (proto_size + 1 > size)
485-
goto out;
486-
487-
strncpy(value, proto_name, proto_size + 1);
475+
if (dentry->d_name.len + 1 > size)
476+
return -ERANGE;
477+
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
488478
}
489-
error = proto_size + 1;
479+
return dentry->d_name.len + 1;
490480
}
491-
492-
out:
493-
return error;
481+
return -EOPNOTSUPP;
494482
}
495483

496484
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,

0 commit comments

Comments
 (0)