]>
Commit | Line | Data |
---|---|---|
f36f0171 GKH |
1 | From 971df15bd54ad46e907046ff33750a137b2f0096 Mon Sep 17 00:00:00 2001 |
2 | From: Andreas Gruenbacher <agruenba@redhat.com> | |
3 | Date: Thu, 29 Sep 2016 17:48:34 +0200 | |
4 | Subject: sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names | |
5 | ||
6 | From: Andreas Gruenbacher <agruenba@redhat.com> | |
7 | ||
8 | commit 971df15bd54ad46e907046ff33750a137b2f0096 upstream. | |
9 | ||
10 | The standard return value for unsupported attribute names is | |
11 | -EOPNOTSUPP, as opposed to undefined but supported attributes | |
12 | (-ENODATA). | |
13 | ||
14 | Also, fail for attribute names like "system.sockprotonameXXX" and | |
15 | simplify the code a bit. | |
16 | ||
17 | Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> | |
18 | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> | |
19 | [removes a build warning on 4.4.y - gregkh] | |
20 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
21 | ||
22 | --- | |
23 | net/socket.c | 24 ++++++------------------ | |
24 | 1 file changed, 6 insertions(+), 18 deletions(-) | |
25 | ||
26 | --- a/net/socket.c | |
27 | +++ b/net/socket.c | |
28 | @@ -470,27 +470,15 @@ static struct socket *sockfd_lookup_ligh | |
29 | static ssize_t sockfs_getxattr(struct dentry *dentry, | |
30 | const char *name, void *value, size_t size) | |
31 | { | |
32 | - const char *proto_name; | |
33 | - size_t proto_size; | |
34 | - int error; | |
35 | - | |
36 | - error = -ENODATA; | |
37 | - if (!strncmp(name, XATTR_NAME_SOCKPROTONAME, XATTR_NAME_SOCKPROTONAME_LEN)) { | |
38 | - proto_name = dentry->d_name.name; | |
39 | - proto_size = strlen(proto_name); | |
40 | - | |
41 | + if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) { | |
42 | if (value) { | |
43 | - error = -ERANGE; | |
44 | - if (proto_size + 1 > size) | |
45 | - goto out; | |
46 | - | |
47 | - strncpy(value, proto_name, proto_size + 1); | |
48 | + if (dentry->d_name.len + 1 > size) | |
49 | + return -ERANGE; | |
50 | + memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); | |
51 | } | |
52 | - error = proto_size + 1; | |
53 | + return dentry->d_name.len + 1; | |
54 | } | |
55 | - | |
56 | -out: | |
57 | - return error; | |
58 | + return -EOPNOTSUPP; | |
59 | } | |
60 | ||
61 | static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, |