Commit Graph

300189 Commits

Author SHA1 Message Date
thorpej 8ff22ec6c6 Document the error code when O_REGULAR is specified and the last
path component is not a regular file.
2023-03-05 16:24:31 +00:00
riastradh 41e8c661e5 open(2): Don't map ERESTART to EINTR.
If a file or device's open function returns ERESTART, respect that --
restart the syscall; don't pretend a signal has been delivered when
it was not.  If an SA_RESTART signal was delivered, POSIX does not
allow it to fail with EINTR:

    SA_RESTART
        This flag affects the behavior of interruptible functions;
        that is, those specified to fail with errno set to [EINTR].
        If set, and a function specified as interruptible is
        interrupted by this signal, the function shall restart and
        shall not fail with [EINTR] unless otherwise specified.  If
        an interruptible function which uses a timeout is restarted,
        the duration of the timeout following the restart is set to
        an unspecified value that does not exceed the original
        timeout value.  If the flag is not set, interruptible
        functions interrupted by this signal shall fail with errno
        set to [EINTR].

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html

Nothing in the POSIX definition of open specifies otherwise.

In 1990, Kirk McKusick added these lines with a mysterious commit
message:

Author: Kirk McKusick <mckusick>
Date:   Tue Apr 10 19:36:33 1990 -0800

    eliminate longjmp from the kernel (for karels)

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 7bc7b39bbf..d572d3a32d 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *	@(#)vfs_syscalls.c	7.42 (Berkeley) 3/26/90
+ *	@(#)vfs_syscalls.c	7.43 (Berkeley) 4/10/90
  */

 #include "param.h"
@@ -530,8 +530,10 @@ copen(scp, fmode, cmode, ndp, resultfd)
 	if (error = vn_open(ndp, fmode, (cmode & 07777) &~ S_ISVTX)) {
 		crfree(fp->f_cred);
 		fp->f_count--;
-		if (error == -1)	/* XXX from fdopen */
-			return (0);	/* XXX from fdopen */
+		if (error == EJUSTRETURN)	/* XXX from fdopen */
+			return (0);		/* XXX from fdopen */
+		if (error == ERESTART)
+			error = EINTR;
 		scp->sc_ofile[indx] = NULL;
 		return (error);
 	}

(found via this git import of the CSRG history:
cce2869b7a)

This change appears to have served two related purposes:

1. The fdopen function (the erstwhile open routine for /dev/fd/N)
   used to return -1 as a hack to mean it had just duplicated the fd;
   it was recently changed by Mike Karels, in kern_descrip.c 7.9, to
   return EJUSTRETURN, now defined to be -2, presumably to avoid a
   conflict with ERESTART, defined to be -1.  So this change finished
   part of the change by Mike Karels to use a different magic return
   code from fdopen.

   Of course, today we use still another disgusting hack, EDUPFD, for
   the same purpose, so none of this is relevant any more.

2. Prior to April 1990, the kernel handled signals during tsleep(9)
   by longjmping out to the system call entry point or similar.  In
   April 1990, Mike Karels worked to convert all of that into
   explicit unwind logic by passing through EINTR or ERESTART as
   appropriate, instead of setjmp at each entry point.

However, it's not clear to me why this setjmp/longjmp and
fdopen/-1/EJUSTRETURN renovation justifies unconditional logic to map
ERESTART to EINTR in open(2).  I suspect it was a mistake.

In 2013, the corresponding logic to map ERESTART to EINTR in open(2)
was removed from FreeBSD:

   r246472 | kib | 2013-02-07 14:53:33 +0000 (Thu, 07 Feb 2013) | 11 lines

   Stop translating the ERESTART error from the open(2) into EINTR.
   Posix requires that open(2) is restartable for SA_RESTART.

   For non-posix objects, in particular, devfs nodes, still disable
   automatic restart of the opens. The open call to a driver could have
   significant side effects for the hardware.

   Noted and reviewed by:  jilles
   Discussed with: bde
   MFC after:      2 weeks

Index: vfs_syscalls.c
===================================================================
--- vfs_syscalls.c	(revision 246471)
+++ vfs_syscalls.c	(revision 246472)
@@ -1106,8 +1106,6 @@
 				goto success;
 		}

-		if (error == ERESTART)
-			error = EINTR;
 		goto bad;
 	}
 	td->td_dupfd = 0;

https://cgit.freebsd.org/src/commit/sys/kern/vfs_syscalls.c?id=2ca49983425886121b506cb5126b60a705afc38c

It's not clear to me that there's any reason to treat device nodes
specially here; in fact, if a driver's .d_open routine sleeps and is
woken by a concurrent revoke without a signal pending or with an
SA_RESTART signal pending, it is wrong for it to fail with EINTR.
But it MUST restart the whole system call rather than continue
sleeping in a loop or just exit the loop and continue to open,
because it is mandatory in the security model of revoke for open(2)
to retry the permissions check at that point.

PR kern/57260

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-05 14:40:32 +00:00
thorpej bfed668024 In the HUP-wait path in ucomopen():
- Use cv_timedwait() rather than cv_timedwait_sig(); the wait here is
  bounded (and fairly short besides) and seems appropriate to treat like
  other uninterruptible waits.  The behavior is now consistent with com(4)
  in this regard.
- Map EWOULDBLOCK return from cv_timedwait() to 0, as the successful passage
  of time is not an error in this case.
- If the HUP-wait time has passed, clear the HUP-wait timestamp.

kern/57259 (although insufficient -- another change to vfs_syscalls.c
is required)
2023-03-05 13:49:12 +00:00
rillig 927cc0eddb tests/make: improve explanations in test for 'empty' function 2023-03-04 21:15:30 +00:00
rillig 33e3d3862c tests/make: use proper variable names in short-circuit test
The previous variable names V42, V66, iV1 and iV2 didn't carry enough
information to be readily readable, making the test hard to understand.

Rename the variables to be more expressive.  While here, properly
explain what happened behind the scenes in 2020 and how the evaluation
of conditions was fixed after discovering the actual cause of the
unexpected error messages.
2023-03-04 13:42:36 +00:00
skrll c20016a774 Trailing whitespace 2023-03-04 08:52:19 +00:00
rillig 4b1bcb1179 tests/make: test very small and very large numbers in conditions 2023-03-04 08:07:29 +00:00
jschauma 160de92249 add CMC (Certificate Management over CMS, RFC5272)
add CMS (Cryptographic Message Syntax, RFC5652)
2023-03-03 15:29:48 +00:00
riastradh a4ca83ca25 x86/fpu: Align savefpu to 64 bytes in fpuinit_mxcsr_mask.
16 bytes is not enough.

(Is this why it never worked on Xen some years back?  Got lucky and
accidentally had 64-byte alignment on native x86, but not in the call
stack in Xen?)

XXX pullup-10
2023-03-03 14:40:16 +00:00
riastradh f9112e4de0 x86: Call fpuinit_mxcsr_mask only once.
No need to call it again and again on the secondary CPUs to compute
what should be the same mxcsr mask.  (If it's not, we have deeper
problems!)
2023-03-03 14:40:00 +00:00
riastradh 32723a3bac Revert "x86: Add kthread_fpu_enter/exit support, take two."
kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
2023-03-03 14:32:48 +00:00
riastradh 1a7b1b3e34 Revert "x86/fpu.c: Sprinkle KNF."
kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
2023-03-03 14:32:38 +00:00
riastradh deea633283 Revert "x86: Add kthread_fpu_enter/exit support, take two -- forgot i386 bits."
kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
2023-03-03 14:32:27 +00:00
riastradh 0670f81a19 mremap(2): Note MAP_REMAPDUP bug.
XXX pullup-10, unless we fix the bug first
2023-03-03 12:53:04 +00:00
riastradh 30c052bdf9 entropy(9): Allow changing flags on all entropy sources at once.
Entropy sources should all have nonempty names, and this will enable
an operator to, for example, disable all but a specific entropy
source.

XXX pullup-10
2023-03-03 12:52:49 +00:00
hannken f8079ac547 Fix genfs_can_chtimes() to also handle the condition:
If the time pointer is null, then write permission
  on the file is also sufficient.

From FreeBSD.

Should fix PR kern/57246 "NFS group permissions regression"
2023-03-03 10:02:51 +00:00
hannken 7c7014518c Adapt zfs_netbsd_access() to ACL support. As ZFS itself only
handles VREAD, VWRITE, VEXEC and VAPPEND we use kauth_authorize_vnode()
to handle VADMIN.

From FreeBSD.
2023-03-03 10:01:31 +00:00
nia 188cf0e1a1 delete attribution per request of contributor 2023-03-01 21:06:41 +00:00
riastradh 0119a38611 mremap(2): Fix example to use MAP_PRIVATE.
It is a historical accident that MAP_PRIVATE is assumed when neither
it nor MAP_SHARED is specified.

XXX pullup-9
XXX pullup-10
2023-03-01 20:08:41 +00:00
riastradh 6ecb13cd73 fs/hfs: Avoid undefined pointer arith in hfslib_reada_node_offsets.
XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 16:21:26 +00:00
riastradh f9833f6744 fs/hfs: Avoid buffer overrun in hfslib_reada_node_offsets.
XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 16:21:14 +00:00
fcambus 60dcde39a0 Add RTTI (run-time type information). 2023-03-01 15:45:00 +00:00
kre 5747acc12f Fix a typo in a newly added comment.
Someone please tell me why these things become obvious only after
the code has been committed!

NFC
2023-03-01 15:18:18 +00:00
kre 5a71a00fea When processing swapon -a (or swapctl -A, or swapctl -U) ignore lines in
fstab that have nothing to do with swapping (fs_type is neither "sw" nor "dp")
before running getfsspecname() on the fs_spec field of the line.

This avoids entries like this:

NAME=OFTEN_UNCONNECTED   /local/archived ffs     rw,log,noauto    0 0

in fstab from generating spurious error messages when the wedge named
is not currently connected to the system - that is the drive on which the
wedge exists is not connected, or not powered on.   "noauto" handles that
for some other uses, the "0"s in fs_freq and fs_passno work for other uses,
but swap{on,ctl} never look at those fields (not for this purpose).

Non "sw"/"dp" lines were being ignored anyway, but not until (a little) later.
2023-03-01 15:15:56 +00:00
uwe af2cb705a7 mmap(2): minor markup tweaks 2023-03-01 15:11:28 +00:00
fcambus cce6686bc2 Add TU (translation unit). 2023-03-01 14:45:26 +00:00
fcambus db76d1da91 Add RAII (resource acquisition is initialization). 2023-03-01 11:12:56 +00:00
fcambus edba1610ca Add IR (intermediate representation) and MLIR (multi-level IR). 2023-03-01 11:08:03 +00:00
riastradh afe5f4042f nouveau: Kick out genfb on firmware framebuffer before initializing.
PR kern/53126
2023-03-01 08:42:33 +00:00
riastradh 72ab6728b4 x86: Expand on comments on ordering around stores to ci_curlwp.
No functional change intended.

PR kern/57240
2023-03-01 08:38:50 +00:00
riastradh e87fcc4564 sparc64: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 08:18:39 +00:00
riastradh 04dd39c83e riscv: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240
2023-03-01 08:18:24 +00:00
riastradh 819618f6c8 powerpc: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 08:18:13 +00:00
riastradh 63f356be21 mips: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 08:18:03 +00:00
riastradh ca865cda72 arm32: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 08:17:53 +00:00
riastradh ac9544107f aarch64: Optimization: Omit needless membar when triggering softint.
When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-9
XXX pullup-10
2023-03-01 08:17:24 +00:00
riastradh ef7f915eda amdgpu: Fix bogus loop invariant assertions in amdgpu_gart_map. 2023-03-01 08:14:13 +00:00
riastradh a816c0f978 random(4): Report number of bytes ready to read, not number of bits.
Only affects systems with the diagnostic and testing option
kern.entropy.depletion=1.

XXX pullup-10
2023-03-01 08:13:54 +00:00
riastradh 49e7470743 xen/x86: Need kpreempt_disable/enable around curcpu() access.
This is called with `hardware' interrupts enabled (between sti and
cli), so presumably preemption is possible here.

XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-03-01 08:13:44 +00:00
thorpej ba9eab13f6 Add NHACP (NABU HCCA Application Communication Protocol) 2023-03-01 04:04:54 +00:00
fcambus 0a454e5a3d Add DWARF (Debugging With Attributed Record Formats). 2023-02-28 20:42:55 +00:00
fcambus 88a2d5c095 Add PE (portable executable).
We have an entry for COFF, so it makes sense to add PE as well.
2023-02-28 19:08:37 +00:00
fcambus 84e6b598fc Add KASAN (Kernel Address Sanitizer). 2023-02-28 16:48:00 +00:00
fcambus be90390822 Add GUS (Gravis UltraSound). 2023-02-28 15:01:53 +00:00
fcambus a967fbeab2 Remove duplicate entry for RCS, keep the capitalized version to match CVS. 2023-02-28 14:32:59 +00:00
fcambus 320e5a87f9 Add GCC (GNU Compiler Collection). 2023-02-28 12:50:49 +00:00
fcambus baff57d7e0 Remove sanitizer mention for CFI, it's a general term. 2023-02-28 08:36:03 +00:00
sjg 18e5949a8d Use inline function rather that macro BM 2023-02-28 06:04:28 +00:00
rillig eaf30a03e7 lint: split platform-specific test for loss of accuracy
Lint distinguishes between platforms where size_t is unsigned int and
platforms where size_t is unsigned long.
2023-02-27 23:07:53 +00:00
andvar 19c1490f61 fix some typos in comments. 2023-02-27 22:00:25 +00:00