From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Gruenbacher Subject: [PATCH v5 05/17] sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names Date: Wed, 28 Sep 2016 16:57:51 +0200 Message-ID: <1475074683-26971-6-git-send-email-agruenba@redhat.com> References: <1475074683-26971-1-git-send-email-agruenba@redhat.com> Return-path: In-Reply-To: <1475074683-26971-1-git-send-email-agruenba@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org To: Alexander Viro Cc: Andreas Gruenbacher , linux-fsdevel@vger.kernel.org, Tyler Hicks , ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, David Howells , Serge Hallyn , Dmitry Kasatkin , linux-ima-devel@lists.sourceforge.net, Paul Moore , Stephen Smalley , Eric Paris , Casey Schaufler , Oleg Drokin , Andreas Dilger List-Id: linux-unionfs@vger.kernel.org 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 --- net/socket.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/net/socket.c b/net/socket.c index a1bd161..9b3dca6 100644 --- a/net/socket.c +++ b/net/socket.c @@ -469,27 +469,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, -- 2.7.4