vfs_extattr: Allow extattr names up to the full max

Extattr names are allowed to be 255 bytes -- not 254 bytes plus trailing
NUL.  Provide a 256 buffer so that copyinstr() has room for the trailing
NUL.

Re-enable test for maximal name lengths.

PR:		208965
Reported by:	asomers
Reviewed by:	asomers
Differential Revision:	https://reviews.freebsd.org/D24584
This commit is contained in:
cem 2020-05-14 03:01:23 +00:00
parent 5f0a69f87f
commit 8df595b9ba
2 changed files with 14 additions and 17 deletions

View File

@ -82,7 +82,7 @@ sys_extattrctl(struct thread *td, struct extattrctl_args *uap)
struct vnode *filename_vp; struct vnode *filename_vp;
struct nameidata nd; struct nameidata nd;
struct mount *mp, *mp_writable; struct mount *mp, *mp_writable;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
int error; int error;
AUDIT_ARG_CMD(uap->cmd); AUDIT_ARG_CMD(uap->cmd);
@ -92,7 +92,7 @@ sys_extattrctl(struct thread *td, struct extattrctl_args *uap)
* invoke the VFS call so as to pass in NULL there if needed. * invoke the VFS call so as to pass in NULL there if needed.
*/ */
if (uap->attrname != NULL) { if (uap->attrname != NULL) {
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, error = copyinstr(uap->attrname, attrname, sizeof(attrname),
NULL); NULL);
if (error) if (error)
return (error); return (error);
@ -231,13 +231,13 @@ int
sys_extattr_set_fd(struct thread *td, struct extattr_set_fd_args *uap) sys_extattr_set_fd(struct thread *td, struct extattr_set_fd_args *uap)
{ {
struct file *fp; struct file *fp;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
cap_rights_t rights; cap_rights_t rights;
int error; int error;
AUDIT_ARG_FD(uap->fd); AUDIT_ARG_FD(uap->fd);
AUDIT_ARG_VALUE(uap->attrnamespace); AUDIT_ARG_VALUE(uap->attrnamespace);
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uap->attrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return (error); return (error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);
@ -293,11 +293,11 @@ kern_extattr_set_path(struct thread *td, const char *path, int attrnamespace,
const char *uattrname, void *data, size_t nbytes, int follow) const char *uattrname, void *data, size_t nbytes, int follow)
{ {
struct nameidata nd; struct nameidata nd;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
int error; int error;
AUDIT_ARG_VALUE(attrnamespace); AUDIT_ARG_VALUE(attrnamespace);
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uattrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return (error); return (error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);
@ -398,13 +398,13 @@ int
sys_extattr_get_fd(struct thread *td, struct extattr_get_fd_args *uap) sys_extattr_get_fd(struct thread *td, struct extattr_get_fd_args *uap)
{ {
struct file *fp; struct file *fp;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
cap_rights_t rights; cap_rights_t rights;
int error; int error;
AUDIT_ARG_FD(uap->fd); AUDIT_ARG_FD(uap->fd);
AUDIT_ARG_VALUE(uap->attrnamespace); AUDIT_ARG_VALUE(uap->attrnamespace);
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uap->attrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return (error); return (error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);
@ -458,11 +458,11 @@ kern_extattr_get_path(struct thread *td, const char *path, int attrnamespace,
const char *uattrname, void *data, size_t nbytes, int follow) const char *uattrname, void *data, size_t nbytes, int follow)
{ {
struct nameidata nd; struct nameidata nd;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
int error; int error;
AUDIT_ARG_VALUE(attrnamespace); AUDIT_ARG_VALUE(attrnamespace);
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uattrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return (error); return (error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);
@ -533,13 +533,13 @@ int
sys_extattr_delete_fd(struct thread *td, struct extattr_delete_fd_args *uap) sys_extattr_delete_fd(struct thread *td, struct extattr_delete_fd_args *uap)
{ {
struct file *fp; struct file *fp;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
cap_rights_t rights; cap_rights_t rights;
int error; int error;
AUDIT_ARG_FD(uap->fd); AUDIT_ARG_FD(uap->fd);
AUDIT_ARG_VALUE(uap->attrnamespace); AUDIT_ARG_VALUE(uap->attrnamespace);
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uap->attrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return (error); return (error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);
@ -590,11 +590,11 @@ kern_extattr_delete_path(struct thread *td, const char *path, int attrnamespace,
const char *uattrname, int follow) const char *uattrname, int follow)
{ {
struct nameidata nd; struct nameidata nd;
char attrname[EXTATTR_MAXNAMELEN]; char attrname[EXTATTR_MAXNAMELEN + 1];
int error; int error;
AUDIT_ARG_VALUE(attrnamespace); AUDIT_ARG_VALUE(attrnamespace);
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); error = copyinstr(uattrname, attrname, sizeof(attrname), NULL);
if (error) if (error)
return(error); return(error);
AUDIT_ARG_TEXT(attrname); AUDIT_ARG_TEXT(attrname);

View File

@ -75,9 +75,6 @@ long_name_body() {
atf_skip "Filesystem not reporting NAME_MAX; skipping testcase" atf_skip "Filesystem not reporting NAME_MAX; skipping testcase"
fi fi
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=208965
atf_expect_fail "BUG 208965 extattr(2) doesn't allow maxlen attr names"
ATTRNAME=`jot -b X -s "" $NAME_MAX 0` ATTRNAME=`jot -b X -s "" $NAME_MAX 0`
touch foo touch foo
atf_check -s exit:0 -o empty setextattr user $ATTRNAME myvalue foo atf_check -s exit:0 -o empty setextattr user $ATTRNAME myvalue foo