Commit graph

751 commits

Author SHA1 Message Date
Konstantin Belousov c662306e19 Add kern_openatfp(9)
Reviewed by:	markj, pjd
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43529
2024-01-24 07:13:26 +02:00
Konstantin Belousov 3d59b93b20 kern_openat(): minor style fixes
Reviewed by:	markj, pjd
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43529
2024-01-24 07:13:25 +02:00
Konstantin Belousov 2a284076ec kern_openat(): rename fd argument to dirfd
Reviewed by:	markj, pjd
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43529
2024-01-24 07:13:25 +02:00
Konstantin Belousov b068bb09a1 Add vnode_pager_clean_{a,}sync(9)
Bump __FreeBSD_version for ZFS use.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43356
2024-01-11 18:44:53 +02:00
Warner Losh 29363fb446 sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Mariusz Zaborski 15a51d3aba copy_file_range: require CAP_SEEK capability
When using copy_file_range(2) with an offset parameter,
the CAP_SEEK capability should be required.
This requirement is similar to the behavior observed with
pread(2)/pwrite(2).

Reported by:	theraven
Reviewed by:    emaste, theraven, kib, markj
Approved by:	secteam
Differential Revision:  https://reviews.freebsd.org/D41967
2023-09-28 15:48:07 +02:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Konstantin Belousov 9c3bfe2ad0 Revert "VFS: Remove VV_READLINK flag" and "fdescfs: improve linrdlnk mount option"
This reverts commits 4a402dfe0b and
3bffa22623.

The fix will be implemented in somewhat different manner.  The semantic
adjustment is incompatible with linuxolator expectations.

Reported and reviewed by:	dchagin
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D40969
2023-07-13 04:14:12 +03:00
Konstantin Belousov 4a402dfe0b VFS: Remove VV_READLINK flag
since its only reason to exist is removed.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D40700
2023-06-27 13:43:25 +03:00
Konstantin Belousov a1d71cebc0 fstatat(2): restore AT_EMPTY_PATH handling
Fixes:	cb858340dc
Reported by:	markj
Sponsored by:	The FreeBSD Foundation
2023-05-02 18:11:39 +03:00
Dmitry Chagin cb858340dc linux(4): Add a dedicated statat() implementation
Get rid of calling Linux stat translation hook and specific to Linux
handling of non-vnode dirfd from kern_statat(),

Reviewed by:		kib, mjg
Differential revision:	https://reviews.freebsd.org/D35474
2023-04-28 11:55:04 +03:00
Mateusz Guzik 56da4aa554 vfs: stop using SAVESTART for rename
ni_startdir has never reached rename routines anyway

Reviewed by:	mckusick
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D34468
2022-12-19 08:09:37 +00:00
Mateusz Guzik a75d1ddd74 vfs: introduce V_PCATCH to stop abusing PCATCH 2022-09-17 15:41:37 +00:00
Mateusz Guzik 5b5b7e2ca2 vfs: always retain path buffer after lookup
This removes some of the complexity needed to maintain HASBUF and
allows for removing injecting SAVENAME by filesystems.

Reviewed by:	kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D36542
2022-09-17 09:10:38 +00:00
Mateusz Guzik 41a0a99f85 vfs: slightly reorganize error handling in chroot
This avoids duplicated NDFREE_NOTHING which will be of importance
later.
2022-09-17 09:08:34 +00:00
Mateusz Guzik 3e0b486886 vfs: flip a condition around in kern_statat
error tends to be 0.
2022-09-07 20:06:24 +00:00
Mateusz Guzik 84a0be4a23 vfs: plug a dead store in kern_linkat_vp
Reported by:	clang --analyze
2022-08-16 10:46:29 +00:00
Dmitry Chagin 31d1b816fe sysent: Get rid of bogus sys/sysent.h include.
Where appropriate hide sysent.h under proper condition.

MFC after:	2 weeks
2022-05-28 20:52:17 +03:00
Mateusz Guzik cdb337b097 vfs: fix copy-pasto in previous
Reported by:	dchagin
2022-05-20 20:58:11 +00:00
Mateusz Guzik ec3c225711 vfs: call vn_truncate_locked from kern_truncate
This fixes a bug where the syscall would not bump writecount.

PR:	263999
2022-05-20 17:25:51 +00:00
Mateusz Guzik 6b715687bd vfs: make sure truncate always calls NDFREE_*
While here convert it to NDFREE_NOTHING.
2022-05-20 17:25:51 +00:00
Konstantin Belousov 362ff9867e Revert rest of a5970a529c: use vrefact() when working on fp->f_vnode
Now, since O_PATH-opened file descriptors use use references instead
of the hold references, vrefact() chahges from that revision can be
reverted.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D34906
2022-04-15 16:56:20 +03:00
Konstantin Belousov bf13db086b Mostly revert a5970a529c: Make files opened with O_PATH to not block non-forced unmount
Problem is that open(O_PATH) on nullfs -o nocache is broken then,
because there is no reference on the vnode after the open syscall exits.

Reported and tested by:	ambrisko
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2022-04-14 02:47:04 +03:00
Dmitry Chagin c6487446d7 getdirentries: return ENOENT for unlinked but still open directory.
To be more compatible to IEEE Std 1003.1-2008 (“POSIX.1”).

Reviewed by:		mjg, Pau Amma (doc)
Differential revision:  https://reviews.freebsd.org/D34680
MFC after:		2 weeks
2022-04-11 23:30:16 +03:00
Mateusz Guzik b7262756e2 vfs: fixup WANTIOCTLCAPS on open
In some cases vn_open_cred overwrites cn_flags, effectively nullifying
initialisation done in NDINIT. This will have to be fixed.

In the meantime make sure the flag is passed.

Reported by:	jenkins
Noted by:	Mathieu <sigsys@gmail.com>
2022-04-02 20:49:01 +02:00
Mateusz Guzik 0c805718cb vfs: fix memory leak on lookup with fds with ioctl caps
Reviewed by:	markj
PR:		262515
Noted by:	firk@cantconnect.ru
Differential Revision:	https://reviews.freebsd.org/D34667
2022-04-02 12:09:07 +00:00
Mateusz Guzik bb92cd7bcd vfs: NDFREE(&nd, NDF_ONLY_PNBUF) -> NDFREE_PNBUF(&nd) 2022-03-24 10:20:51 +00:00
Mateusz Guzik 513c7a6e0c fd: make fget_unlocked take a thread argument
Just like other fget routines. This enables embedding fd table pointer
in struct thread, avoiding taking a trip through proc.
2022-02-11 12:29:26 +00:00
Mark Johnston 300cfb96fc file: Make fget*() and getvnode*() consistent about initializing *fpp
Most fget*() functions initialize the output parameter to NULL.  Make
the externally visible interface behave consistently, and make
fget_unlocked_seq() private to kern_descrip.c.

This fixes at least one bug in a consumer, _filemon_wrapper_openat(),
which assumes that getvnode() sets the output file pointer to NULL upon
an error.

Reported by:	syzbot+01c0459408f896a5933a@syzkaller.appspotmail.com
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34190
2022-02-08 12:40:41 -05:00
John Baldwin 2cee586189 sys/kern: Use C99 fixed-width integer types.
No functional change.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D33630
2021-12-28 09:41:08 -08:00
Mateusz Guzik 7e1d3eefd4 vfs: remove the unused thread argument from NDINIT*
See b4a58fbf64 ("vfs: remove cn_thread")

Bump __FreeBSD_version to 1400043.
2021-11-25 22:50:42 +00:00
Brooks Davis 6eefabd4ca syscalls: improve nstat, nfstat, nlstat
Optionally return errors when truncating dev_t, ino_t, and nlink_t.
In the interest of code reuse, use freebsd11_cvtstat() to perform the
truncation and error handling and then convert the resulting struct
freebsd11_stat to struct nstat.

Add missing freebsd32 compat syscalls. These syscalls require
translation because struct nstat contains four instances of struct
timespec which in turn contains a time_t and a long.

Reviewed by:	kib
2021-11-22 22:36:56 +00:00
Brooks Davis 2b9d052d3e freebsd32: fix getfsstat sign extension bugs
Add freebsd32 versions of getfsstat and freebsd11_getfsstat so that
bufsize is properly sign-extended if a negative value is passed.
Reject negative values before passing to kern_getfsstat as a size_t.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis b7fd86118f syscalls: sprinkle in const values
Add missing const qualifiers to a number of syscall arguments.

Obtained from:	CheriBSD

Reviewed by:	kevans
2021-11-17 20:12:21 +00:00
John Baldwin 57093f9366 vfs: Consistently validate AT_* flags in kern_* functions.
Some syscalls checked for invalid AT_* flags in sys_* and others in
kern_*.

Reviewed by:	kib
Obtained from:	CheriBSD
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D32864
2021-11-09 09:42:12 -08:00
Mateusz Guzik 2b68eb8e1d vfs: remove thread argument from VOP_STAT
and fo_stat.
2021-10-11 13:22:32 +00:00
Mateusz Guzik 93e0523499 vfs: add predicts to getvnode and getvnode_path 2021-10-10 18:24:29 +00:00
Konstantin Belousov 5fb54d2fc8 readlinkat(2): allow O_PATH fd
PR:	258856
Reported by:	ashish
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32390
2021-10-09 22:31:37 +03:00
Konstantin Belousov 9446d9e88f fstatat(2): handle non-vnode file descriptors for AT_EMPTY_PATH
Set NIRES_EMPTYPATH earlies, to have use of EMPTYPATH recorded even if
we are going to return error.  When namei_setup() refused to accept dirfd,
which is not of the vnode type, and indicated by ENOTDIR error return,
fall back to kern_fstat(dirfd).

Reported by:	dchagin
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31530
2021-08-14 00:17:18 +03:00
Mark Johnston eca9ac5a32 vfs: Avoid a comparison with an uninitialized field in setutimes()
Some filesystems, e.g., devfs, do not populate va_birthtime in their
GETATTR implementations.  To handle this, make sure that va_birthtime is
initialized to the quasi-standard value of { VNOVAL, 0 } before calling
VOP_GETATTR.

Reported by:	KMSAN
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31468
2021-08-09 13:27:20 -04:00
Konstantin Belousov 0ef5eee9d9 Add vn_lktype_write()
and remove repetetive code that calculates vnode locking type for write.

Reviewed by:	khng, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31405
2021-08-04 19:40:13 +03:00
Edward Tomasz Napierala a40cf4175c Implement unprivileged chroot
This builds on recently introduced NO_NEW_PRIVS flag to implement
unprivileged chroot, enabled by `security.bsd.unprivileged_chroot`.
It allows non-root processes to chroot(2), provided they have the
NO_NEW_PRIVS flag set.

The chroot(8) utility gets a new flag, -n, which sets NO_NEW_PRIVS
before chrooting.

Reviewed By:	kib
Sponsored By:	EPSRC
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D30130
2021-07-20 08:57:53 +00:00
Konstantin Belousov 802cf4ab0e namei: add NDPREINIT() macro
Its intent is to do the initialization of the future part of struct nameidata
which should be used across several namei() and VOPs.  Right now it is NOP.

Reviewed by:	mckusick
Discussed with:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D30041
2021-06-23 23:46:15 +03:00
Jason A. Harmening a4b07a2701 VFS_QUOTACTL(9): allow implementation to indicate busy state changes
Instead of requiring all implementations of vfs_quotactl to unbusy
the mount for Q_QUOTAON and Q_QUOTAOFF, add an "mp_busy" in/out param
to VFS_QUOTACTL(9).  The implementation may then indicate to the caller
whether it needed to unbusy the mount.

Also, add stbool.h to libprocstat modules which #define _KERNEL
before including sys/mount.h.  Otherwise they'll pull in sys/types.h
before defining _KERNEL and therefore won't have the bool definition
they need for mp_busy.

Reviewed By:	kib, markj
Differential Revision: https://reviews.freebsd.org/D30556
2021-05-30 14:53:47 -07:00
Jason A. Harmening 271fcf1c28 Revert commits 6d3e78ad6c and 54256e7954
Parts of libprocstat like to pretend they're kernel components for the
sake of including mount.h, and including sys/types.h in the _KERNEL
case doesn't fix the build for some reason.  Revert both the
VFS_QUOTACTL() change and the follow-up "fix" for now.
2021-05-29 17:48:02 -07:00
Jason A. Harmening 6d3e78ad6c VFS_QUOTACTL(9): allow implementation to indicate busy state changes
Instead of requiring all implementations of vfs_quotactl to unbusy
the mount for Q_QUOTAON and Q_QUOTAOFF, add an "mp_busy" in/out param
to VFS_QUOTACTL(9).  The implementation may then indicate to the caller
whether it needed to unbusy the mount.

Reviewed By:	kib, markj
Differential Revision: https://reviews.freebsd.org/D30218
2021-05-29 14:05:39 -07:00
Mateusz Guzik a269183875 vfs: elide vnode locking when it is only needed for audit if possible 2021-05-23 19:37:16 +00:00
Edward Tomasz Napierala 5d1d844a77 kern_linkat: modify to accept AT_ flags instead of FOLLOW/NOFOLLOW
This makes this API match other kern_xxxat() functions.

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29776
2021-04-25 14:13:12 +01:00
Konstantin Belousov 578c26f31c linkat(2): check NIRES_EMPTYPATH on the first fd arg
Reported by:	arichardson
Reviewed by:	markj
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29834
2021-04-19 21:32:01 +03:00
Konstantin Belousov bbf7a4e878 O_PATH: allow vnode kevent filter on such files
if VREAD access is checked as allowed during open

Requested by:	wulf
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29323
2021-04-15 12:49:18 +03:00