Bug 208965 - extattr(2) doesn't allow attribute names of length EXTATTR_MAXNAMELEN
Summary: extattr(2) doesn't allow attribute names of length EXTATTR_MAXNAMELEN
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Conrad Meyer
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-04-21 22:21 UTC by Alan Somers
Modified: 2020-05-14 03:02 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2016-04-21 22:21:20 UTC
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
Comment 1 Enji Cooper freebsd_committer freebsd_triage 2016-04-21 22:27:28 UTC
(related to https://reviews.freebsd.org/D5889).
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2020-04-27 02:02:55 UTC
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.
Comment 3 Conrad Meyer freebsd_committer freebsd_triage 2020-04-27 02:14:31 UTC
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.
Comment 4 commit-hook freebsd_committer freebsd_triage 2020-05-14 03:02:05 UTC
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