FreeBSD/src 9bd048b — sbin/camcontrol nvfeature.c, sys/cam/nvme nvme_all.h nvme_all.c

camcontrol: Fix extended host identifier retrieval

The Get Features command for the host identifier always requested
the 64-bit form (cdw11 EXHID=0), but the decoding logic sized the
identifier from the controller's CTRATT extended host identifier
capability bit, or always treated it as 128 bits when -U was
given.  On a controller supporting the extended host identifier,
the printed value did not match what was requested from the
controller.

Fetch the controller data before issuing the command, request the
extended form when the controller supports it, and decode the form
that was requested.  Reject -U when the controller only supports
64-bit host identifiers, since an 8 byte value cannot be shown as
a UUID.

sys/cam/nvme/nvme_all.c,
sys/cam/nvme/nvme_all.h:
        Add an exhid argument to nvme_get_feature_hostid(),

    [19 lines not shown]
DeltaFile
+35-22sbin/camcontrol/nvfeature.c
+7-2sys/cam/nvme/nvme_all.c
+3-2sys/cam/nvme/nvme_all.h
+45-263 files

FreeBSD/src 2c19cd6 — sbin/camcontrol camcontrol.c

camcontrol: Don't close the CAM device in nvme_get_data()

nvme_get_data() closed the supplied CAM device on every error
path, but its callers either pass the device that main() opened
and closes, or close the device themselves, so an error resulted
in a double cam_close_device() and a double free.  Move the error
path close into print_dev_nvme(), the one caller that opens its
own device, and leave the device alone in nvme_get_data().

This predates the recent camcontrol NVMe additions, but they added
more callers.

Reported by:    llm-postcr
Fixes:          6ee13c54dad0
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit f7c24ef1e9a47b889eaaae8514c61e95d9738cf8)
DeltaFile
+3-3sbin/camcontrol/camcontrol.c
+3-31 files

FreeBSD/src 259b3ac — sbin/nvmecontrol format.c nvmecontrol.8

nvmecontrol: Range-check the format command's field values

The format command accepted any 32-bit value for -m, -p, -l and
--ses and passed it into the Format NVM command.  Before
eae727676169 an out-of-range value spilled into the adjacent cdw10
fields, which usually drew an error from the controller; after it,
the value is masked to the field width, so a mistyped value is
silently accepted with a different meaning.  Most seriously,
--ses 8 masked to SES=0 and performed a plain format with no erase
at all, exiting 0.  A value like --ses 10 masked to a cryptographic
erase while bypassing the FNA cryptographic erase capability check,
which compares the unmasked value.

Reject values outside the ranges nvmecontrol.8 documents, which are
the values the spec defines: 0-1 for -m and -l, 0-3 for -p, and
0-2 for --ses.  The checks run at option validation time, before
the device is opened, and the capability check now only ever sees
valid values.


    [12 lines not shown]
DeltaFile
+19-1sbin/nvmecontrol/nvmecontrol.8
+10-0sbin/nvmecontrol/format.c
+29-12 files

FreeBSD/src 7b1763b — sbin/nvmecontrol format.c

nvmecontrol: Mask the fields in the Format NVM command

The format command composed cdw10 by hand without masking any of
the fields and with no support for the LBAFU field.  Since commit
2c41f7d8a034 the LBA format index defaulted from FLBAS can exceed
15 on an NVMe 2.0 namespace using FIDXU, and such an index would
bleed into the MSET and PI fields.  An out of range index supplied
with -f for a whole-controller format was not caught either.

Build the command with nvme_admin_format_cmd(), which masks all of
the fields and encodes LBA format indexes above 15 in LBAFU, and
reject LBA format indexes greater than 63 for whole-controller
formats.  Per-namespace formats already validate the index against
NLBAF.

This is the same problem that llm-postcr reported in camcontrol's
copy of this code, fixed in 3892a6453fc6; the unmasked composition
originated here (635c517ae9ca).


    [9 lines not shown]
DeltaFile
+3-4sbin/nvmecontrol/format.c
+3-41 files

FreeBSD/src f64d611 — sbin/camcontrol nvres.c

camcontrol: Fix -Wcast-align errors in the NVMe reservation report

Casting the byte buffer that holds the Reservation Report payload to
the status structures trips -Wcast-align on strict-alignment
architectures, which broke the CI builds there.  Put the buffer in a
union with the two status structures instead, so it is properly
aligned and no casts are needed.

Reported by:    FreeBSD CI
Fixes:  ba75cf05727e ("camcontrol: Support NVMe reservations via the persist subcommand")
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>
MFC after:      1 week
Sponsored by:   Spectra Logic

(cherry picked from commit 68ba58a064d1004a031fac6f299f968dfc39241f)
DeltaFile
+11-7sbin/camcontrol/nvres.c
+11-71 files

FreeBSD/src 6a901f5 — sys/dev/nvme nvme.h

nvme: Fix the data length in the Reservation Report command builder

nvme_ns_resv_report_cmd() put its length argument, which callers
supply in bytes, directly into cdw10.  The NUMD field is a 0's
based count of dwords, so the command asked the controller to
transfer nearly four times the size of the supplied data buffer.
In practice controllers limit the transfer to the length described
by the PRP entries, which is why this worked in testing, but the
command was incorrect.

Convert the byte count to a 0's based dword count in the builder.

Reported by:    llm-postcr
Fixes:          7a9e4375316b
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit 86b9d629c68f6dc63543b9c0a6da6c96c857f3bc)
DeltaFile
+2-1sys/dev/nvme/nvme.h
+2-11 files

FreeBSD/src 85a6832 — sys/dev/nvme nvme.h

nvme: Byte-swap the nsid in the Get/Set Features command builders

nvme_admin_get_feature_cmd() and nvme_admin_set_feature_cmd() stored
the namespace ID in the command without converting it to little
endian, unlike the other command building functions.  Any caller
passing a non-zero namespace ID would send the wrong namespace ID on
big endian machines.

Reported by:    llm-postcr
Fixes:          7a9e4375316b
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit 3a6dbe77c39d3a88b6092cfcaa820fc727d1e61d)
DeltaFile
+2-2sys/dev/nvme/nvme.h
+2-21 files

FreeBSD/src 8678bd6 — sbin/camcontrol nvformat.c

camcontrol: Fix swapped protection information defaults in nvformat

When no -p or -l arguments are given, the nvformat subcommand fills
in the protection information type and location from the
namespace's current settings.  The two were swapped: pi was taken
from the DPS metadata location bit and pil from the protection
information type field.  Formatting a namespace with protection
information enabled would therefore silently change its PI
settings, and before the Format NVM command builder masked its
fields, a namespace with PI type 2 enabled would set bit 9 of
cdw10, turning the format into a user data erase.

Reported by:    llm-postcr
Fixes:          80f090111ae4
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit ef69484b4295e84c74877b439db5caf025906b0c)
DeltaFile
+4-4sbin/camcontrol/nvformat.c
+4-41 files

FreeBSD/src bcf4600 — sys/dev/nvme nvme_ctrlr.c

nvme: Restore the host memory buffer size calculation

When the nvme_ctrlr_cmd_set_feature() call in
nvme_ctrlr_hmb_enable() was rewritten for the widened Set Features
API, the HSIZE calculation reverted to dividing by a hard coded
4096 instead of the controller page size, undoing commit
3740a8db13ba.  The Host Memory Buffer Size field is in units of
the current memory page size (CC.MPS), so the wrong size would be
programmed on controllers configured with a page size other than
4KB.

Reported by:    llm-postcr
Fixes:          7a9e4375316b
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit f262bdcf24f1f946edcd01f5eb5dfa2910da9e7b)
DeltaFile
+1-1sys/dev/nvme/nvme_ctrlr.c
+1-11 files

FreeBSD/src 0ca07b1 — sbin/camcontrol nvres.c

camcontrol: Require a reservation type for reserve, preempt and release

res_type was initialized to 0, but the checks that enforce the -T
argument for the reserve, preempt and release reservation actions
compare it against -1, so they could never fire and camcontrol
silently sent a reservation type of 0, which is invalid.
Initialize res_type to -1 so the checks work, and default the
reservation type to 0 for the release action's clear variant,
which does not take -T and ignores the field.

Reported by:    llm-postcr
Fixes:          ba75cf05727e
MFC after:      1 week
Sponsored by:   Spectra Logic
Co-authored-by: Claude Fable 5 <noreply at anthropic.com>

(cherry picked from commit b95e2b2ce907cde89bc3e7be2ffeae03cfed55ab)
DeltaFile
+4-1sbin/camcontrol/nvres.c
+4-11 files

FreeBSD/src 94434cd — sbin/camcontrol nvformat.c, sys/dev/nvme nvme.h

nvme: Mask the fields in the Format NVM command builder

nvme_admin_format_cmd() did not mask any of the fields it composes
into cdw10, so an out of range value in one field would corrupt
neighboring fields.  In particular, an LBA format index greater
than 15 would bleed into the metadata settings and protection
information fields.  It also had no support for LBA format indexes
above 15, which NVMe 2.0 encodes via the separate LBAFU field.

Mask all of the fields, and encode bits 5:4 of the LBA format index
in the LBAFU field (cdw10 bits 13:12).

Also reject out of range LBA format indexes in camcontrol's
nvformat global (-G) mode, which has no namespace data to validate
against.  The per-namespace mode already validates the index
against NLBAF.

sys/dev/nvme/nvme.h:
        Mask the SES, PIL, PI, MSET and LBAF fields in

    [14 lines not shown]
DeltaFile
+6-0sbin/camcontrol/nvformat.c
+3-2sys/dev/nvme/nvme.h
+9-22 files

FreeBSD/src d4f7280 — sys/cam/nvme nvme_all.h nvme_all.c

cam: Add NVMe reservation, format and features CCB building functions

Add NVMe CCB (union ccb / struct ccb_nvmeio) building functions for
the four NVMe reservation opcodes, Format NVM, and Get Features /
Set Features.  These use the nvme_command building blocks added to
sys/dev/nvme/nvme.h, and are used by the new camcontrol(8) nvres,
nvformat and nvfeature subcommands that will be added separately.

sys/cam/nvme/nvme_all.c:
        Add NVMe CCB building functions for the four NVMe reservation
        opcodes: nvme_resv_report(), nvme_resv_register(),
        nvme_resv_acquire() and nvme_resv_release().  Data direction
        is set internally (CAM_DIR_IN or CAM_DIR_OUT as appropriate),
        so no flags parameter is needed.

        Add a new nvme_format() CCB building function.

        Add nvme_get_feature() and nvme_set_feature() CCB building
        functions, along with nvme_get_feature_hostid() and

    [18 lines not shown]
DeltaFile
+201-0sys/cam/nvme/nvme_all.c
+42-0sys/cam/nvme/nvme_all.h
+243-02 files

FreeBSD/src 2ebb10d — sbin/nvmecontrol Makefile resv.c, sys/dev/nvme nvme_ctrlr.c nvme_util.c

nvme: Add reservation, format and features command building support

Add command (struct nvme_command) building functions for the four
NVMe reservation opcodes (Report, Register, Acquire and Release),
Format NVM, and Get Features / Set Features, along with the
enumerations and data structures that go with them.  These are
shared between the kernel and userland, and are the underpinnings
for new camcontrol(8) subcommands (nvres, nvformat, nvfeature) that
will be added separately.

The reservation type names are intentionally similar to the SCSI
names for the same reservation types.

sys/dev/nvme/nvme.h:
  Add NVMe command building functions for the four NVMe
  reservation opcodes: nvme_ns_resv_report_cmd(),
  nvme_ns_resv_register_cmd(), nvme_ns_resv_acquire_cmd() and
  nvme_ns_resv_release_cmd().


    [70 lines not shown]
DeltaFile
+180-10sys/dev/nvme/nvme.h
+13-20sys/dev/nvme/nvme_ctrlr_cmd.c
+16-0sys/dev/nvme/nvme_util.c
+4-5sys/dev/nvme/nvme_ctrlr.c
+5-4sbin/nvmecontrol/resv.c
+1-1sbin/nvmecontrol/Makefile
+219-406 files

FreeBSD/src ec4b7f6 — sbin/camcontrol Makefile camcontrol.h

camcontrol: Support NVMe namespace formatting via the format subcommand

Support formatting NVMe namespaces through the existing format
subcommand.  The format subcommand now dispatches on the device
protocol, in the same way the identify and persist subcommands do,
and issues the NVMe FORMAT NVM command for NVMe devices.

The SCSI syntax and behavior are unchanged.  The NVMe-specific
options are -e (secure erase setting), -G (format all namespaces),
-f (LBA format), -l (protection information location), -m (metadata
setting) and -p (protection information type).  The -q and -y options
work for both protocols; NVMe formats gain the same confirmation
question that SCSI formats have always had.  The -r and -w options
are SCSI only; -r returns an error for NVMe devices and -w has no
effect, since the NVMe format command does not complete until the
format is finished.

The default timeout for NVMe is 30 seconds for a cryptographic erase
and 30 minutes otherwise; the generic -t option overrides it.

    [25 lines not shown]
DeltaFile
+313-0sbin/camcontrol/nvformat.c
+114-1sbin/camcontrol/camcontrol.8
+30-8sbin/camcontrol/camcontrol.c
+3-0sbin/camcontrol/camcontrol.h
+1-1sbin/camcontrol/Makefile
+461-105 files

FreeBSD/src c1e5a1f — sbin/camcontrol camcontrol.h camcontrol.8

camcontrol: Add support for NVMe namespace Identify

Add a -N argument to camcontrol identify.  This will fetch and
display namespace Identify data for NVMe drives, using
nvme_print_namespace() from nvmecontrol(8).

This gets the namespace Identify data via XPT_DEV_ADVINFO (i.e.
data cached in the kernel) like the standard NVMe identify command
does, and so works even on NVMe devices that do not support NVMe
Namespace Management.

sbin/camcontrol/camcontrol.c:
        Add a -N argument to camcontrol identify.

        Rename nvme_get_cdata() to nvme_get_data(), and give it the
        ability to fetch controller or namespace Identify data.
        While here, improve its error reporting with
        cam_error_print(), and only look at the CAM status bits of
        the returned CCB.

    [24 lines not shown]
DeltaFile
+87-26sbin/camcontrol/camcontrol.c
+12-2sbin/camcontrol/camcontrol.8
+2-0sbin/camcontrol/camcontrol.h
+101-283 files

FreeBSD/src ff00bbd — sbin/camcontrol Makefile camcontrol.h

camcontrol: Add a feature subcommand for NVMe Get/Set Features

Add a feature subcommand for the NVMe Get Features and Set Features
commands:

  camcontrol feature ndaX -a <get|set> -f feature [-d data]
      [-s num] [-U]

There is no transport-specific prefix in the name: SCSI has no
feature command (the closest equivalents are mode pages), and the
ATA SET FEATURES subcommands are already exposed through dedicated
camcontrol subcommands (apm, aam, epc and the power commands), so
the name is unclaimed.  The subcommand returns an error for
non-NVMe devices.

Currently, only the hostid feature is fully implemented.  The
hostid value for set is specified with -d as a UUID or an integer
in decimal, hex, or octal, and -U outputs the hostid as a UUID on
get.

    [38 lines not shown]
DeltaFile
+539-0sbin/camcontrol/nvfeature.c
+182-0sbin/camcontrol/camcontrol.8
+32-1sbin/camcontrol/camcontrol.c
+3-0sbin/camcontrol/camcontrol.h
+1-1sbin/camcontrol/Makefile
+757-25 files

FreeBSD/src 7c9cb9c — sbin/camcontrol Makefile camcontrol.h

camcontrol: Support NVMe reservations via the persist subcommand

The NVMe reservation model is closely patterned after SCSI Persistent
Reservations, so support NVMe devices through the existing persist
subcommand rather than adding a transport-specific subcommand.  The
persist subcommand now dispatches on the device protocol, in the same
way the identify subcommand does.

The SCSI syntax is unchanged.  For NVMe devices, the -i modes all map
to the Reservation Report command (read_full_status requests the
extended data structure, which contains 128-bit Host Identifiers), and
the -o service actions map to the corresponding NVMe reservation
operations: register, register_ignore, reserve, preempt,
preempt_abort, release and clear, plus two NVMe-only actions,
unregister and replace.  The reservation type names for -T are shared
between SCSI and NVMe.  A new -c option gives explicit control over
the NVMe Persist Through Power Loss State; -p is equivalent to
-c enable.  SCSI-only options return an error for NVMe devices.


    [34 lines not shown]
DeltaFile
+674-0sbin/camcontrol/nvres.c
+107-7sbin/camcontrol/camcontrol.8
+23-9sbin/camcontrol/camcontrol.c
+3-0sbin/camcontrol/camcontrol.h
+1-1sbin/camcontrol/Makefile
+808-175 files

FreeBSD/src 8af3223 — sbin/nvmecontrol identify.c format.c, sys/cam/nvme nvme_da.c

nvme: honor FLBAS Format Index Upper when selecting the LBA format

Added nvme_ns_data_format_index() in the nvme, nda, and nvmf
host paths as well as nvmecontrol and camdd.

Reviewed by:    imp, adrian
Differential Revision:  https://reviews.freebsd.org/D59627

(cherry picked from commit 2c41f7d8a034ee64a0aaa69a1aa5cb07748a1a32)
DeltaFile
+18-0sys/dev/nvme/nvme.h
+2-3sys/dev/nvme/nvme_ns.c
+1-1usr.sbin/camdd/camdd.c
+1-1sys/cam/nvme/nvme_da.c
+1-1sbin/nvmecontrol/identify.c
+1-1sbin/nvmecontrol/format.c
+24-71 files not shown
+25-87 files

FreeBSD/src 1f7ba14 — sbin/nvmecontrol nvmecontrol.h nvmecontrol_ext.h

nvmecontrol: Factor out namespace Identify printing

Move print_namespace() from identify.c to identify_ext.c and rename
it to nvme_print_namespace(), to match nvme_print_controller().
This allows other consumers (notably camcontrol(8)) to print NVMe
namespace Identify data.

No functional changes intended.

sbin/nvmecontrol/identify.c:
        Remove print_namespace(), and call nvme_print_namespace()
        instead.

sbin/nvmecontrol/identify_ext.c:
        Add nvme_print_namespace(), moved here from identify.c.

sbin/nvmecontrol/nvmecontrol.h:
        Remove the print_namespace() prototype.


    [14 lines not shown]
DeltaFile
+1-128sbin/nvmecontrol/identify.c
+127-0sbin/nvmecontrol/identify_ext.c
+2-1sbin/nvmecontrol/ns.c
+0-1sbin/nvmecontrol/nvmecontrol.h
+1-0sbin/nvmecontrol/nvmecontrol_ext.h
+131-1305 files

FreeBSD/src d546356 — tests/sys/pmc Makefile pmc_row_test.c

tests/sys/pmc: add PERF, RDPMC, row, sampling and unload tests

- pmc_perf_test: the pmc.perf(3) class (MPERF, APERF, IRPERF).
- pmc_rdpmc_test: pmc_get_msr() and RDPMC.
- pmc_row_test: row disposition per mode; system sampling needs a log.
- pmc_ss_test: system sampling into a log, and its interrupt accounting.
- pmc_unload_test: unloading hwpmc.ko leaks no memory.

Reviewed by:    mhorne
Sponsored by:   Advanced Micro Devices, Inc.
Signed-off-by:  Osvaldo Janeri Filho <ojanerif at amd.com>
Signed-off-by:  Davi C.A <davi.chavesazevedo at amd.com>
Differential Revision:  https://reviews.freebsd.org/D61062
DeltaFile
+333-0tests/sys/pmc/pmc_perf_test.c
+311-0tests/sys/pmc/pmc_ss_test.c
+172-0tests/sys/pmc/pmc_rdpmc_test.c
+129-0tests/sys/pmc/pmc_unload_test.c
+123-0tests/sys/pmc/pmc_row_test.c
+10-0tests/sys/pmc/Makefile
+1,078-06 files

FreeBSD/src ea390ec — tests/sys/netinet ip_reass_test.c

tests/netinet/ip_reass: skip when IP reassembly is disabled
DeltaFile
+17-0tests/sys/netinet/ip_reass_test.c
+17-01 files

FreeBSD/src 002594c — lib/libpmc pmc.soft.3

pmc.soft(3): fixup table formatting

The default indent did not serve well. No content change.

MFC after:      3 days
DeltaFile
+1-1lib/libpmc/pmc.soft.3
+1-11 files

FreeBSD/src bf7bb73 — sys/compat/linux linux_fork.c, sys/kern kern_kthread.c

hwpmc: call the thread-create hook for Linux and kernel threads

linux_clone_thread() and kthread_add() did not call the
PMC_FN_THR_CREATE hook.  Their new threads had no hwpmc thread
descriptor.  If the process had a sampling PMC, the first switch-in
of such a thread hit KASSERT(pt != NULL) in pmc_process_csw_in().
An unprivileged user could panic an INVARIANTS kernel with
"pmcstat -P" on a threaded Linux program.

Call the hook in both functions, as thread_create() does.

kern_kthread.c did not include opt_hwpmc_hooks.h, so its hwpmc code
never compiled.  Include it, and use newtd in kthread_add1().
Remove the exit log call from kthread_exit(), because thread_exit()
already logs the exit.

Reported by:    llm-postcr
Reviewed by:    kib, mhorne
Fixes:          6161b98c9935 ("hwpmc: Implement per-thread counters for PMC sampling")
Differential Revision:  https://reviews.freebsd.org/D61524
DeltaFile
+9-6sys/kern/kern_kthread.c
+11-0sys/compat/linux/linux_fork.c
+20-62 files

FreeBSD/src 125b88f — sys/amd64/vmm/io vrtc.c

vmm: release the lock when vrtc_snapshot() fails

The error path of the SNAPSHOT_*_OR_LEAVE() macros jumped past
VRTC_UNLOCK() and returned with the vrtc lock held.

Signed-off-by: Wanpeng Qian <wanpengqian at gmail.com>

Reviewed by:    bnovkov, markj, jhb
Sponsored by:   keelos.dev
Differential Revision:  https://reviews.freebsd.org/D60232
DeltaFile
+1-2sys/amd64/vmm/io/vrtc.c
+1-21 files

FreeBSD/src 018bd70 — sys/amd64/vmm/io vrtc.c

vmm: do not let the RTC's periodic interrupt drift

The callout of the periodic interrupt was rearmed from its handler with
a timeout of one period from the time the handler ran.  Each period was
longer than programmed by the latency of the callout, so the interrupt
came at a lower rate than the guest asked for.  A guest that counts
these interrupts to keep its time runs slow.

Give the callout absolute deadlines one period apart, as vatpit does.
If a deadline has already passed when it is computed, for instance
after the VM was paused, start again from the current time.

Signed-off-by: Wanpeng Qian <wanpengqian at gmail.com>

Reviewed by:    jhb
Sponsored by:   keelos.dev
Differential Revision:  https://reviews.freebsd.org/D60233
DeltaFile
+21-7sys/amd64/vmm/io/vrtc.c
+21-71 files

FreeBSD/src 611046b — sbin/ipfw nat.c, tests/sys/netpfil/ipfw Makefile nat.sh

ipfw: print the log, not the config, for "nat <name> show log"

Add a test too.

Reviewed by:    ae
Fixes:          d6164b77f8b7 ("Make ipfw_nat module use IP_FW3 codes.")
Found with:     Claude Opus 4.8
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D61588
DeltaFile
+66-0tests/sys/netpfil/ipfw/nat.sh
+4-1sbin/ipfw/nat.c
+1-0tests/sys/netpfil/ipfw/Makefile
+71-13 files

FreeBSD/src 1c8725c — sys/netpfil/ipfw ip_fw_nat.c, tests/sys/netpfil/ipfw Makefile nat_getlog.c

ipfw_nat: fix the buffer length check in IP_FW_NAT44_XGETLOG

nat44_get_log() compared the user buffer length against the request
header plus another ipfw_obj_header instead of the request header plus
the log buffer.  A buffer that passed this check but was shorter than
the full reply left too little room in the sockopt window, so
ipfw_get_sopt_space() returned NULL and the following memcpy() of the
log wrote through a NULL pointer, panicking the kernel.

The handler was cloned from nat44_get_cfg() in the commit below, under
the convention of that time where ucfg->size held the payload only and
the ipfw_obj_header was added back in the length check.  9f925e8a920e
("Fix IP_FW_NAT44_LIST_NAT size calculation.") later switched
nat44_get_cfg() to count the header in ucfg->size and reduced its check
to "valsize < size", but nat44_get_log() was not updated.  It kept the
stale idiom, whose check counts the header twice, and by coincidence of
the struct sizes that never leaves room for the log.

Compare against the full reply length and check the result of

    [18 lines not shown]
DeltaFile
+226-0tests/sys/netpfil/ipfw/nat_getlog.c
+6-2sys/netpfil/ipfw/ip_fw_nat.c
+2-0tests/sys/netpfil/ipfw/Makefile
+234-23 files

FreeBSD/src 596a470 — usr.sbin/bhyve pci_e82545.c

bhyve: e82545: deassert the interrupt when its last cause is masked

A write to IMC only cleared the bits in the mask.  If the device was
asserting INTx for a cause that the write masked, the line stayed up
until the guest cleared the cause in ICR.  The hardware deasserts INTx
as soon as no unmasked cause is left, and a guest may rely on that:
Windows masks all causes and unloads its driver when it shuts down, and
then spends its time in the handlers of whatever shares the interrupt.

Do what the comment in the code asked for.

Signed-off-by: Wanpeng Qian <wanpengqian at gmail.com>

Reviewed by:    jhb
Sponsored by:   keelos.dev
Differential Revision:  https://reviews.freebsd.org/D60230
DeltaFile
+3-2usr.sbin/bhyve/pci_e82545.c
+3-21 files

FreeBSD/src b9e45c2 — sys/netipsec ipsec.h xform_ipcomp.c

netipsec: Clear the crypto error before dispatching a request again

When a crypto driver unregisters, a request on one of its sessions
completes with EAGAIN.  The ESP, AH and IPComp callbacks then move the
SA to the new session and pass the same request to crypto_dispatch()
again, with crp_etype still set to EAGAIN.

crypto_dispatch() requires a request without an error.  A kernel with
INVARIANTS panics there with "incoming crp with error".  The other
consumers that dispatch a request again after EAGAIN clear the field
first.

The six callbacks prepare the request for the retry with the same
code.  Move that code to a new function, ipsec_crypto_retry(), and
clear the error there.  ipsec_updateid() has no other callers and
becomes static.  The callbacks still dispatch the request themselves,
because the input callbacks have to release the sahtree lock first.

Reviewed by:            markj, kib

    [4 lines not shown]
DeltaFile
+18-1sys/netipsec/ipsec.c
+2-12sys/netipsec/xform_ipcomp.c
+2-12sys/netipsec/xform_esp.c
+2-12sys/netipsec/xform_ah.c
+4-1sys/netipsec/ipsec.h
+28-385 files

FreeBSD/src c27f0ee — sys/security/mac mac_syscalls.h mac_syscalls.c

mac: Fix a couple of bugs in prison label handling

In mac_get_prison(), mac.m_string points to a user address; the
string is copied in by mac_label_copyin_string().  If an error occurs
before that copyin, we end up freeing a user-controlled pointer.

In mac_set_prison_prepare(), the string is leaked.

Fix both problems.  While here, make free_copied_label() a bit more
robust to bugs in callers.

Fixes:          bd55cbb50c58 ("kern: add a mac.label jail parameter")
Reviewed by:    olce, kevans
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D61596
DeltaFile
+18-7sys/security/mac/mac_syscalls.c
+1-1sys/security/mac/mac_syscalls.h
+19-82 files