Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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>

authored by

Andreas Gruenbacher and committed by
Al Viro
971df15b e72a1a8b

+6 -18
+6 -18
net/socket.c
··· 469 469 static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode, 470 470 const char *name, void *value, size_t size) 471 471 { 472 - const char *proto_name; 473 - size_t proto_size; 474 - int error; 475 - 476 - error = -ENODATA; 477 - if (!strncmp(name, XATTR_NAME_SOCKPROTONAME, XATTR_NAME_SOCKPROTONAME_LEN)) { 478 - proto_name = dentry->d_name.name; 479 - proto_size = strlen(proto_name); 480 - 472 + if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) { 481 473 if (value) { 482 - error = -ERANGE; 483 - if (proto_size + 1 > size) 484 - goto out; 485 - 486 - strncpy(value, proto_name, proto_size + 1); 474 + if (dentry->d_name.len + 1 > size) 475 + return -ERANGE; 476 + memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); 487 477 } 488 - error = proto_size + 1; 478 + return dentry->d_name.len + 1; 489 479 } 490 - 491 - out: 492 - return error; 480 + return -EOPNOTSUPP; 493 481 } 494 482 495 483 static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,