extattr(2) claims that attribute names may be up to EXTATTR_MAXNAMELEN in length. However, in practice it only allows attribute names of up to EXTATTR_MAXNAMELEN - 1. [alans@alans-fbsd-head2 /tmp]$ touch foo [alans@alans-fbsd-head2 /tmp]$ ATTRNAME=`jot -b X -s "" 255 0` [alans@alans-fbsd-head2 /tmp]$ setextattr user $ATTRNAME myvalue foo setextattr: foo: failed: File name too long
(related to https://reviews.freebsd.org/D5889).
I believe this is due to copyinstr(), which works with NUL-terminated strings (and lengths), while the stack buffer in sys_extattr_set_fd(), etc, are only sized to EXTATTR_MAXNAMELEN. To fix this I think we just need to size the buffers one larger to allow for the trailing NUL copyinstr expects.
FWIW, UFS_EXTATTR only disables the crummy extattrs in UFS1. UFS2 extattrs are not controlled by that knob. https://reviews.freebsd.org/D24584 is a proposed patch; it compiles but I have not tested it.
A commit references this bug: Author: cem Date: Thu May 14 03:01:24 UTC 2020 New revision: 361021 URL: https://svnweb.freebsd.org/changeset/base/361021 Log: 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 Changes: head/sys/kern/vfs_extattr.c head/usr.sbin/extattr/tests/extattr_test.sh