summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruenba@redhat.com>2016-09-29 17:48:34 +0200
committerSeung-Woo Kim <sw0312.kim@samsung.com>2019-12-30 15:44:32 +0900
commitd949ccaf68479697f896a4c9462b4e5ff54d802d (patch)
tree52ceabdf2bc9fca428aa592c3633db8671906383
parent642b3f963d3dd9444c733f69a8a4e973a7827cc0 (diff)
downloadlinux-artik7-d949ccaf68479697f896a4c9462b4e5ff54d802d.tar.gz
linux-artik7-d949ccaf68479697f896a4c9462b4e5ff54d802d.tar.bz2
linux-artik7-d949ccaf68479697f896a4c9462b4e5ff54d802d.zip
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> [sw0312.kim: cherry-pick from stable linux-4.4.y commit c776cff6de52 for gcc 9 build] Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com> Change-Id: I86795bc2eb5eac9498341d6778a1a2195272f82a
-rw-r--r--net/socket.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/net/socket.c b/net/socket.c
index a4a5342c2f71..e32639b2d505 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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, struct inode *inode,
const char *name, void *value, size_t size)
{
- const char *proto_name;
- 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 (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
if (value) {
- error = -ERANGE;
- if (proto_size + 1 > size)
- goto out;
-
- strncpy(value, proto_name, proto_size + 1);
+ if (dentry->d_name.len + 1 > size)
+ return -ERANGE;
+ memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
}
- error = proto_size + 1;
+ return dentry->d_name.len + 1;
}
-
-out:
- return error;
+ return -EOPNOTSUPP;
}
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,