sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names

commit 971df15bd54ad46e907046ff33750a137b2f0096 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>
This commit is contained in:
Andreas Gruenbacher 2016-09-29 17:48:34 +02:00 committed by Greg Kroah-Hartman
parent c8d66722d8
commit c776cff6de

View file

@ -470,27 +470,15 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
static ssize_t sockfs_getxattr(struct dentry *dentry, static ssize_t sockfs_getxattr(struct dentry *dentry,
const char *name, void *value, size_t size) const char *name, void *value, size_t size)
{ {
const char *proto_name; if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
size_t proto_size;
int error;
error = -ENODATA;
if (!strncmp(name, XATTR_NAME_SOCKPROTONAME, XATTR_NAME_SOCKPROTONAME_LEN)) {
proto_name = dentry->d_name.name;
proto_size = strlen(proto_name);
if (value) { if (value) {
error = -ERANGE; if (dentry->d_name.len + 1 > size)
if (proto_size + 1 > size) return -ERANGE;
goto out; memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
strncpy(value, proto_name, proto_size + 1);
} }
error = proto_size + 1; return dentry->d_name.len + 1;
} }
return -EOPNOTSUPP;
out:
return error;
} }
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,