freebsd-src/bin
Kyle Evans dcef4f65ae vfs: add restrictions to read(2) of a directory [1/2]
Historically, we've allowed read() of a directory and some filesystems will
accommodate (e.g. ufs/ffs, msdosfs). From the history department staffed by
Warner: <<EOF

pdp-7 unix seemed to allow reading directories, but they were weird, special
things there so I'm unsure (my pdp-7 assembler sucks).

1st Edition's sources are lost, mostly. The kernel allows it. The
reconstructed sources from 2nd or 3rd edition read it though.

V6 to V7 changed the filesystem format, and should have been a warning, but
reading directories weren't materially changed.

4.1b BSD introduced readdir because of UFS. UFS broke all directory reading
programs in 1983. ls, du, find, etc all had to be rewritten. readdir() and
friends were introduced here.

SysVr3 picked up readdir() in 1987 for the AT&T fork of Unix. SysVr4 updated
all the directory reading programs in 1988 because different filesystem
types were introduced.

In the 90s, these interfaces became completely ubiquitous as PDP-11s running
V7 faded from view and all the folks that initially started on V7 upgraded
to SysV. Linux never supported this (though I've not done the software
archeology to check) because it has always had a pathological diversity of
filesystems.
EOF

Disallowing read(2) on a directory has the side-effect of masking
application bugs from relying on other implementation's behavior
(e.g. Linux) of rejecting these with EISDIR across the board, but allowing
it has been a vector for at least one stack disclosure bug in the past[0].

By POSIX, this is implementation-defined whether read() handles directories
or not. Popular implementations have chosen to reject them, and this seems
sensible: the data you're reading from a directory is not structured in some
unified way across filesystem implementations like with readdir(2), so it is
impossible for applications to portably rely on this.

With this patch, we will reject most read(2) of a dirfd with EISDIR. Users
that know what they're doing can conscientiously set
bsd.security.allow_read_dir=1 to allow read(2) of directories, as it has
proven useful for debugging or recovery. A future commit will further limit
the sysctl to allow only the system root to read(2) directories, to make it
at least relatively safe to leave on for longer periods of time.

While we're adding logic pertaining to directory vnodes to vn_io_fault, an
additional assertion has also been added to ensure that we're not reaching
vn_io_fault with any write request on a directory vnode. Such request would
be a logical error in the kernel, and must be debugged rather than allowing
it to potentially silently error out.

Commented out shell aliases have been placed in root's chsrc/shrc to promote
awareness that grep may become noisy after this change, depending on your
usage.

A tentative MFC plan has been put together to try and make it as trivial as
possible to identify issues and collect reports; note that this will be
strongly re-evaluated. Tentatively, I will MFC this knob with the default as
it is in HEAD to improve our odds of actually getting reports. The future
priv(9) to further restrict the sysctl WILL NOT BE MERGED BACK, so the knob
will be a faithful reversion on stable/12. We will go into the merge
acknowledging that the sysctl default may be flipped back to restore
historical behavior at *any* point if it's warranted.

[0] https://www.freebsd.org/security/advisories/FreeBSD-SA-19:10.ufs.asc

PR:		246412
Reviewed by:	mckusick, kib, emaste, jilles, cy, phk, imp (all previous)
Reviewed by:	rgrimes (latest version)
MFC after:	1 month (note the MFC plan mentioned above)
Relnotes:	absolutely, but will amend previous RELNOTES entry
Differential Revision:	https://reviews.freebsd.org/D24596
2020-06-04 18:09:55 +00:00
..
cat Allow building bin/cat on non-FreeBSD systems 2020-01-16 14:15:00 +00:00
chflags
chio
chmod Correct wording around '-' masks. 2019-03-09 00:30:13 +00:00
cp
csh vfs: add restrictions to read(2) of a directory [1/2] 2020-06-04 18:09:55 +00:00
date Restore the -n flag parsing, but ignore it. 2019-04-24 05:24:10 +00:00
dd Add iflag=fullblock to dd 2019-09-30 22:00:48 +00:00
df
domainname
echo Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
ed Drop ed(1) "crypto" 2018-11-04 17:56:16 +00:00
expr
freebsd-version Convert freebsd-version to using -v 2019-05-23 17:19:00 +00:00
getfacl Avoid copying a struct stat for acl_from_stat() calls. 2018-11-01 17:45:29 +00:00
hostname
kenv
kill
ln
ls ls: fix WITHOUT_LS_COLORS build 2020-05-21 15:15:50 +00:00
mkdir
mv
pax Add a note that the use of -B option does not guarantee a size of fragment 2018-12-29 23:08:59 +00:00
pkill Clarify that /dev/kmem is not used. 2018-12-03 20:01:51 +00:00
ps ps: extend the non-standard option -d (tree view) to work with -p 2020-05-07 16:56:18 +00:00
pwait Remove unused include. 2020-02-02 20:51:28 +00:00
pwd pwd: mark usage as dead 2018-06-17 05:14:50 +00:00
realpath
rm Remove include of stdint.h. It was added in r241014 for uintmax_t, 2020-04-23 03:46:41 +00:00
rmail
rmdir
setfacl Don't set NFSv4 ACL inheritance flags on non-directories. 2018-10-26 21:17:06 +00:00
sh vfs: add restrictions to read(2) of a directory [1/2] 2020-06-04 18:09:55 +00:00
sleep Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0. 2018-06-19 23:43:14 +00:00
stty Some devices take undesired actions when RTS and DTR are 2019-06-12 18:07:04 +00:00
sync
test
tests
uuidgen pkgbase: Create a FreeBSD-utilities package and make it the default one 2019-09-05 14:15:47 +00:00
Makefile
Makefile.inc