libiconv/gbk2k: Handle GB18030SUPP correctly.
According to https://en.wikipedia.org/wiki/GB_18030#Mapping, the code
above 0x90308130 is mapped linearly to unicode 0x10000 to 0x10FFFF. It
is not handled in our iconv implemenation. We implement such mapping in
here and add some tests.
Reviewed by: kevans
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61153
libiconv: Respect RFC 3629
RFC 3629 limits UTF-8 to U+10FFFF, which our iconv doesn't follow but
has been correctly handled in libc. As iconv is the default locale
implementation now. We should respect the standard in here.
Reviewed by: kevans
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61152
acpi/tz: Resync cooler device after resume
A acpi_fan under tz domain can inconisist after resume. The device now
switch between D3 and D0 in suspend and resume. However, if a tz turn
off the cooler before resume, the device will still run after resume as
there is no mechanism in tz to resync activity and the cooler can
by default enter D0.
Reported by: llm-postcr
membarrier(2): do not call smp_rendezvous_cpus() with an empty mask
If the caller migrates while the mask is computed and no other thread
of the process is running, the mask is empty, and smp_rendezvous_cpus()
panics.
PR: 301240
Fixes: 4a69fc16a583 ("Add membarrier(2)")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
membarrier(2): issue the leading fence before reading other CPUs' state
There are two problems:
- The old fence ran after the mask was computed, so a store the caller
made before the syscall could still be in its store buffer when it read
another CPU's state. A thread switched in right after that read then got
neither the IPI nor the store.
- MEMBARRIER_CMD_GLOBAL had no fence before its first pass, which marks
idle CPUs done immediately.
Fixes: 4a69fc16a583 ("Add membarrier(2)")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
acpi/fan: Always call _FSL
Fan device can adjust the fan level itself and propogate to the APCI
Table. This however is opaque to the driver as there is no interrupt
to notify us that the fan level is chaged.
This can cause problem if we want to set the same value as the cached
one, which is all in all short-circuited.
As a result, we call _FSL unconditionally. Also, the condition is also
racy if two writes reach kernel. The value doesn't reflect the last
one. Therefore, we enlarge the critical section and use sx to protect
frequently read case.
Reported by: llm-postcr
Fixes: 116216477e8a ("acpi: Add acpi_fan")
snp(4): for snp_read(), check tty_gone() under tty lock before cv_wait()
Otherwise snp_read() might lose the wakeup from a gone tty.
Keep the unlocked tty_gone() check on entry, so that a non-blocking
read on a gone tty with an empty snoop queue returns EIO instead of
EWOULDBLOCK.
A sleeping reader whose wakeup races with the tty going away now returns
the output captured before that, instead of EIO.
Reported by: llm-postcr
Fixes: d8569724dc0d ("snp(4): wake up the readers and pollers when the tty is gone")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
xprt_verbs.c: Add reconnect support for 2 additional cm events
This patch adds RDMA_CM_EVENT_DEVICE_REMOVAL and
RDMA_CM_EVENT_ADDR_CHANGE to RDMA_CM_EVENT_DISCONNECTED
to force a new QP.
Reported by: llm-postcr
MFC after: 1 month
Fixes: 80bee4d83637 ("nfsclrdma: Add code to support client side NFS over RDMA")
tests/sys/kern/procdesc: test pddupfd(PD_DUPFD_EXECUTABLE)
Check that the returned file descriptor references the process binary,
both for the calling process and for a child whose binary was unlinked
after exec, and that it is close-on-exec, readable and lacks the write
capability right.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
tests/sys/kern/procdesc: test pddupfd(PD_DUPFD_ME)
Check that the descriptor of the calling process is duplicated with
O_CLOEXEC set and the file shared, and that a closed descriptor
gives EBADF.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
ptrace_test: use PD_NOWAITPID in procdesc_reparent_wait_child
The test expects that, after a debugger collected the exit status of
a child created by pdfork(2), the parent cannot collect the child with
wait(2). With the zombie references, a child created without
PD_NOWAITPID is waitable by its parent, and the test only passed
because the debugger's waitpid(2) dropped the parent's reference.
proc_reap() no longer lets the debugger take the exit status away
from the parent, so the parent's wait(2) now collects the child.
Create the child with PD_NOWAITPID, which is what hides it from
wait(2) now. Since waitpid(2) does not see it either, wait for its
stop with pdwait(2). The debugger's waitpid(2) in the test then also
covers collecting a tracee that has no waitpid reference.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62051
procfdcat(1): utility to read content of a file opened by process
It reads the content of a regular file opened by another process, or of
its executable, using pddupfd(2) and pread(2).
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
tmpfs: VOP_OPEN() should be allowed on unlinked files
There is no reason for such restriction, and other file systems do not
impose it.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
pddupfd(2): allow to open the executable
One of the common uses for sysctl kern.proc.<pid>.pathname is to
immediately open(2) the returned path to parse the image, e.g. to read
the symbols. This operation was made more reliable since introduction
of p_textdvp, but still rename or unlink of the binary cause unnecessary
failures for that.
Introduce pddupfd(pfd, PD_DUPFD_EXECUTABLE) special case that returns
read-only file descriptor to the process executable image.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
ptrace_test: test that the debugger does not steal a pdfork child
Add ptrace__procdesc_reparent_wait_child_waitable, the counterpart of
ptrace__procdesc_reparent_wait_child for a child that pdfork(2)
created without PD_NOWAITPID. After the debugger collected the exit
status, the child must be back with its parent, which must still be
able to collect the status with wait(2).
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62051
tests/sys/kern/procdesc: test exit of a non-reaper tracer
Check that the reaper can waitpid(2) for a PD_NOWAITPID child, after
the child's parent traced it and exited with the descriptor open.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62051
exit1(): clear P_TRACED before reparenting a traced child
When the exiting process traced a child, exit1() handed the child to
its real parent or to its reaper with P_TRACED still set, and cleared
the flag only afterwards. proc_reparent() does not re-enable
waitpid(2) for a traced child. A PD_NOWAITPID child whose last
process descriptor was closed while it was traced has no other zombie
reference, so after the SIGKILL that follows, nobody could reap it,
and with init as the reaper, the zombie and its pid leaked for good.
The tracer's own exit is enough to close the descriptor, since
fdescfree() runs before the children are reparented.
Clear P_TRACED before calling proc_reparent(), as PT_DETACH does.
This also keeps proc_reparent() from linking the child onto the orphan
list of the exiting process, so the explicit proc_clear_orphan() is no
longer needed.
Reported by: llm-postcr
Fixes: bcdb6ba94d08 ("processes: add zombie references, each of them prevents reap")
[3 lines not shown]
tests/sys/kern/procdesc: test the debugger's wait for its tracee
Check that a debugger, which is not the reaper, can waitpid(2) for its
killed PD_NOWAITPID tracee after closing the last process descriptor,
and that the reaper collects the child afterwards.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62051
proc_to_reap(): let the debugger wait for its exited tracee
exit1() clears P_TRACED of the exiting process, while proc_to_reap()
accepts a child without the PZOMBIEREF_PARENT reference only if the
waiter traces it. A PD_NOWAITPID process whose last process
descriptor was closed while it was traced has no zombie references at
all, so once it exited, its debugger got ECHILD from waitpid(2), and
the zombie stayed with the debugger until the debugger exited. Before
the zombie references, the debugger's wait collected the status and
gave the zombie back to the real parent, which proc_reap() still does.
For a zombie, recognize the debugger as the parent which is not the
real parent, and let it wait. The debugger holds none of the child's
zombie references, so proc_reap() now gives the child back without
dropping any. Otherwise a reference held elsewhere, e.g. by a process
descriptor, would leave the zombie on the debugger's children list,
and every later waitpid(2) would collect it again. For a child that
can be waited for, PZOMBIEREF_PARENT is now kept over the give-back
instead of being dropped.
[6 lines not shown]
snp(4): drain the users of the tty before detaching it
Since SNPSTTY can detach the tty, snp_tty can change while other
threads use the snoop device. snp_read(), snp_write(), snp_poll(),
and the FIONREAD, SNPGTTY and SNPGTYY_32DEV ioctls read snp_tty
without snp_register_lock and then used the tty. The detach
unregisters the hook, and if the tty is already gone, tty_rel_free()
schedules tty_dealloc(), which frees the tty without waiting for the
snp threads. snp_read() is exposed for as long as it sleeps for data
or copies out with the tty unlocked, and the detach also freed the
output queue under it. The attach path sized the queue after
dropping snp_register_lock, with the same exposure.
Hold snp_register_lock in the paths that use the tty only briefly:
snp_poll(), the ioctls, and the queue sizing on attach. snp_read()
and snp_write(), which sleep or drop the tty lock, take a use
reference counted in snp_busy under the tty lock. The new
snp_detach(), used by SNPSTTY and snp_dtor(), clears snp_tty and
wakes up the readers under the tty lock, waits for the references to
[12 lines not shown]
snp(4): a wakeup from snp_getc_capture() can be lost
snp_poll() checks ttyoutq_bytesused() while holding the tty lock.
It then calls tty_unlock(), and only after that calls selrecord().
snp_getc_capture() can run in that window, queue data and call
selwakeup() before the poller is on si_tdlist. If that happens, the
poller sleeps even though data is already queued.
Call selrecord() under the tty lock.
Reported by: llm-postcr
Fixes: 932ef5b5cdfd ("Reintroduce the snp(4) driver")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61973
snp(4): wake up the readers and pollers when the tty is gone
snp(4) did not register th_close, and snp_poll() only reported queued
data. When the snooped tty went away, nothing woke up a thread
sleeping in select(2) or poll(2) on the snoop device, and a rescan
would not report the gone tty anyway. watch(8) waits in select(2)
and only then asks FIONREAD, which returns SNP_TTYCLOSE, so it hung
once the tty stopped producing output.
Register th_close, which also runs when the tty is gone, to wake up
the readers and the pollers, and return POLLHUP from snp_poll() for a
gone tty. select(2) treats POLLHUP as readable.
Fixes: 932ef5b5cdfd ("Reintroduce the snp(4) driver")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61973
watch(8): detach the gone tty before attaching again
snp(4) keeps a gone tty attached until it is detached or the snoop
device is closed. On SNP_TTYCLOSE, watch(8) asked for a new device,
or reconnected with -c, without detaching the old tty first. SNPSTTY
then failed with EBUSY, and watch exited with "cannot attach to tty".
Detach the gone tty before attaching again.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61973
tty: call the close hook when the TTY is gone
tty_rel_gone() wakes up the threads that wait on the TTY itself, but
does not notify the hook, which only hears about the last close from
ttydisc_close(). The TTY often becomes gone after its last close,
e.g. when the master side of a pts is closed after the slave, so a
hook consumer has no way to learn that the TTY went away.
Call th_close from tty_rel_gone() too. A consumer may now see
th_close twice, on the last close and when the TTY is gone, in either
order. There are no in-tree consumers of th_close yet.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61973
x86: Restore CR0.TS in the Skylake MDS handlers
The Skylake variants of the MDS software sequence save CR0 in %rax
(%eax on i386) and then reuse %eax for the clflushopt loop and the
stosb fill byte. The final test of CR0_TS always sees zero and CR0 is
never restored, so the return to user mode leaves TS clear even when
the thread does not own the FPU. The thread then takes no trap to load
its own FPU state, runs with whatever the registers hold, and its FPU
state is not saved on the next context switch. Only hw.mds_disable=2,
or 3 on a CPU without MD_CLEAR, selects these handlers.
Keep the saved CR0 in %rsi on amd64 and in %esi on i386, which the
handlers do not otherwise use.
Reported by: llm-postcr
Reviewed by: kib
Fixes: 7355a02bdd81 ("Mitigations for Microarchitectural...")
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D62238
bsnmp: drop messages with an unsupported SNMP version
snmp_pdu_decode_header() returned SNMP_CODE_BADENC for an unknown
version. snmp_input_start() treats BADENC as a bad value in a SET and
carries on, so its version check, which runs only for SNMP_CODE_OK, was
skipped. The message then reached snmp_pdu_auth_access(), which with
snmp_vacm loaded switched on pdu->version and called abort() for
SNMP_Verr. A single unauthenticated packet could stop bsnmpd.
Return SNMP_CODE_BADVERS instead, as bsnmplib(3) documents, so the
message is counted in snmpInBadVersions and dropped. Remove the
mapping in snmp_pdu_decode() that tried to do this but was never
reached, and have snmp_pdu_auth_access() deny an unknown version
rather than abort.
Reported by: Hila Cohen, Apiiro (hillalee on github)
Reviewed by: harti
MFC after: 3 days
(cherry picked from commit 72d7d152c2ff4708928ae1f94b940b5528ba5013)