]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
5 months agobsdinstall partedit: Apply changes from scripted installs
John Baldwin [Mon, 16 Oct 2023 22:13:31 +0000 (15:13 -0700)]
bsdinstall partedit: Apply changes from scripted installs

I got a check inverted in a previous cleanup commit and as a result
partedit was only applying GEOM changes (and generating an /etc/fstab)
if it got an error reading the current GEOM mesh.  Instead, it needed
to do those actions if it succeeded in reading the mesh.

The lack of /etc/fstab meant that bsdinstall mount didn't mount
anything in a scripted install.

PR: 273723
Reported by: Andrey Fesenko <andrey@bsdnir.info>
Reported by: Michal Nowak <mnowak@startmail.com>
Reviewed by: cognet, brooks
Fixes: 230990991965 bsdinstall: Handle errors from geom_gettree.
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D42236

(cherry picked from commit 5307bbcc038f878b4b3714f03a2c824a0caeba4f)

5 months agobsdinstall: Handle errors from geom_gettree.
John Baldwin [Wed, 28 Jun 2023 18:11:00 +0000 (11:11 -0700)]
bsdinstall: Handle errors from geom_gettree.

geom_gettree probably never fails, and if it does there isn't much of
a fallback other than aborting partitioning.  However, a few places
were checking the return value and not doing anything with it
triggering a unused-but-set-variable warning.  Checking the errors
resolves the warning.

While here, check for errors in other places that weren't checking for
them at all, remove a spurious double call (the second call overwrote
the mesh structure leaking all the pointers from the first), and close
a few resource leaks on error paths.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D40779

(cherry picked from commit 23099099196548550461ba427dcf09dcfb01878d)

5 months agobsdinstall: Replace correct, but fragile, string builder with open_memstream.
John Baldwin [Tue, 27 Jun 2023 17:19:32 +0000 (10:19 -0700)]
bsdinstall: Replace correct, but fragile, string builder with open_memstream.

The old one triggered a false positive -Warray-bounds from GCC (the
compiler assumed len was always 0), but it was also fragile with
manually computed lengths paired with strcat vs using a string
builder.

Differential Revision: https://reviews.freebsd.org/D40658

(cherry picked from commit f66a8328c3effcb4fbd7807b798d0288b865421d)

5 months agoagp_amd64: Use <machine/pci_cfgreg.h> rather than bare prototypes
John Baldwin [Wed, 29 Nov 2023 18:31:16 +0000 (10:31 -0800)]
agp_amd64: Use <machine/pci_cfgreg.h> rather than bare prototypes

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D42826

(cherry picked from commit 71ac18a84df2771fb9bd91e2349eae91602c4e46)

5 months agoatrtc: Add a required include
Mark Johnston [Thu, 28 Dec 2023 20:16:39 +0000 (15:16 -0500)]
atrtc: Add a required include

PR: 275867
MFC after: 1 week

(cherry picked from commit c63dda466a5ba6a9ec0a5de18f9180683f9af982)

5 months agoiommu: fix build on stable/13 with the DDB option
Konstantin Belousov [Thu, 4 Jan 2024 03:54:17 +0000 (05:54 +0200)]
iommu: fix build on stable/13 with the DDB option

Sponsored by: The FreeBSD Foundation

5 months agovfs_vnops.c: Fix cherry-pick of e7044084cf81
Rick Macklem [Wed, 3 Jan 2024 15:40:15 +0000 (07:40 -0800)]
vfs_vnops.c: Fix cherry-pick of e7044084cf81

Oops, my bad.  When I did the cherry-pick of e7044084cf81
I missed changing outsize to va.va_size.

This direct commit fixes it.

PR: 276045

5 months agocamcontrol: add support for Toshiba drive firmware update
Kenneth D. Merry [Fri, 29 Dec 2023 19:23:51 +0000 (14:23 -0500)]
camcontrol: add support for Toshiba drive firmware update

Thanks to Toshiba for providing the SCSI spec for their latest
generation drives so I could confirm how they operate.

The firmware download works in a pretty standard way, so this
is a straightforward table addition.

sbin/camcontrol/camcontrol.8:
Document that Toshiba drives are supported for fwdownload,
and that it was tested on TOSHIBA MG10SFA22TE 22TB drives.

sbin/camcontrol/fwdownload.c:
Add TOSHIBA to the known SCSI vendors list for fwdownload.

Sponsored by: Spectra Logic

(cherry picked from commit cd95f18c477ca30c3ba6f98577d321f56b1e8439)

5 months agocamcontrol: Add a sense subcommand
Kenneth D. Merry [Thu, 28 Dec 2023 21:23:16 +0000 (16:23 -0500)]
camcontrol: Add a sense subcommand

As the name suggests, this sends a SCSI REQUEST SENSE to a device,
and prints out decoded sense information.  It can also print out a
hexdump of the sense data.

sbin/camcontrol/camcontrol.c:
Add the new sense subcommand.

sbin/camcontrol/camcontrol.8:
Document camcontrol sense.

Sponsored by: Spectra Logic
Reviewed by: mav
Differential Revision:  https://reviews.freebsd.org/D43225

(cherry picked from commit 40a492d38ee10ecf9d9a099c5cdecc072e24d2d1)

5 months agoloader: lua: remove the default kernel if it doesn't exist
Kyle Evans [Wed, 13 Dec 2023 16:52:14 +0000 (10:52 -0600)]
loader: lua: remove the default kernel if it doesn't exist

The `kernel` env var provides the default kernel, usually "kernel".  It
may be the case that the user doesn't have a "kernel" kernel, just
"kernel.*" kernels, but have left `kernel` to the default because we
autodetect entries by default anyways.

If we're doing autodetection, take note of whether the default kernel
exists or not and remove it from the list if it doesn't and we had found
any other kernels.  We avoid it in the #kernels == 1 case because
something fishy has likely happened and we should just trust the
configuration.

Reviewed by: imp, manu
Differential Revision: https://reviews.freebsd.org/D42967

(cherry picked from commit d04415c520b031fb8eb93cb252e4acee66149c87)

5 months agokdump: use print_mask_arg0 appropriately
Kyle Evans [Wed, 13 Dec 2023 16:49:03 +0000 (10:49 -0600)]
kdump: use print_mask_arg0 appropriately

Some callers are using print_mask_arg() when they should be using
print_mask_arg0(); the latter should be used when all flags are optional
and there's not a flag to be decoded with a 0-mask.  This turns:

nmount(0x6991e009000,0x8,0<><invalid>0)

into:

nmount(0x6991e009000,0x8,0)

Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D43007

(cherry picked from commit a206524709bdfbd577bcfe76676da80b8250f84c)

5 months agoloader: provide a features table for binary compatibility advertisement
Kyle Evans [Fri, 8 Dec 2023 21:36:06 +0000 (15:36 -0600)]
loader: provide a features table for binary compatibility advertisement

liblua now provides a loader.has_feature() function to probe the loader
binary for features advertised.  name => desc mappings are provided in
loader.features to get a list of all of the features loader *can*
support.  core.hasFeature is provided as a shim to loader.has_feature
so that individual consumers don't need to think about the logic of the
loader module not providing has_feature; we know that means the feature
isn't enabled.

The first consumer of this will be EARLY_ACPI to advertise that the
loader binary probes for ACPI presence before the interpreter has
started, so that we know whether we can trust the presence of acpi.rsdp
as relatively authoritative.  In general, it's intended to be used to
avoid breaking new scripts on older loaders within reason.

This will be used in lua as `core.hasFeature("EARLY_ACPI")`, while the
C bits of loader will `feature_enable(FEATURE_EARLY_ACPI)`.

Reviewed by: imp

(cherry picked from commit 1631382cf2820245cc72965498ff174bb548dd63)

5 months agovfs_vnops.c: Fix vn_generic_copy_file_range() for truncation
Rick Macklem [Sun, 31 Dec 2023 23:55:24 +0000 (15:55 -0800)]
vfs_vnops.c: Fix vn_generic_copy_file_range() for truncation

When copy_file_range(2) was first being developed,
*inoffp + len had to be <= infile_size or an error was
returned. This semantic (as defined by Linux) changed
to allow *inoffp + len to be greater than infile_size and
the copy would end at *inoffp + infile_size.

Unfortunately, the code that decided if the outfd should
be truncated in length did not get updated for this
semantics change.
As such, if a copy_file_range(2) is done, where infile_size - *inoffp
is less that outfile_size but len is large, the outfd file is truncated
when it should not be. (The semantics for this for Linux is to not
truncate outfd in this case.)

This patch fixes the problem. I believe the calculation is safe
for all non-negative values of outsize, *outoffp, *inoffp and insize,
which should be ok, since they are all guaranteed to be non-negative.

Note that this bug is not observed over NFSv4.2, since it truncates
len to infile_size - *inoffp.

PR: 276045

(cherry picked from commit 2319ca6a01816f7fc85d623097c639f239e18c6a)

6 months agotcp: always set tcp_tun_port to a correct value
Gleb Smirnoff [Tue, 19 Dec 2023 19:24:17 +0000 (11:24 -0800)]
tcp: always set tcp_tun_port to a correct value

The tcp_tun_port field that is used to pass port value between UDP
and TCP in case of tunneling is a generic field that used to pass
data between network layers.  It can be contaminated on entry, e.g.
by a VLAN tag set by a NIC driver.  Explicily set it, so that it
is zeroed out in a normal not-tunneled TCP.  If it contains garbage,
tcp_twcheck() later can enter wrong block of code and treat the packet
as incorrectly tunneled one.  On main and stable/14 that will end up
with sending incorrect responses, but on stable/13 with ipfw(8) and
pcb-matching rules it may end up in a panic.

This is a minimal conservative patch to be merged to stable branches.
Later we may redesign this.

PR: 275169
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D43065

(cherry picked from commit 513f2e2e7180202167ca2963d815d2a4c3ac0af9)

6 months agonfscl: Fix handling of expired Kerberos credentials (NFSv4.1/4.2)
Rick Macklem [Tue, 26 Dec 2023 22:33:39 +0000 (14:33 -0800)]
nfscl: Fix handling of expired Kerberos credentials (NFSv4.1/4.2)

If the NFS server detects that the Kerberos credentials provided
by a NFSv4.1/4.2 mount using sec=krb5[ip] have expired, the NFS
server replies with a krpc layer error of RPC_AUTHERROR.
When this happened, the client erroneously left the NFSv4.1/4.2
session slot busy, so that it could not be used by other RPCs.
If this happened for all session slots, the mount point would
hang.

This patch fixes the problem by releasing the session slot
and resetting its sequence# upon receiving a RPC_AUTHERROR
reply.

This bug only affects NFSv4.1/4.2 mounts using sec=krb5[ip],
but has existed since NFSv4.1 client support was added to
FreeBSD.

So, why has the bug remained undetected for so long?
I cannot be sure, but I suspect that, often, the client detected
the Kerberos credential expiration before attempting the RPC.
For this case, the client would not do the RPC and, as such,
there would be no busy session slot.  Also, no hang would
occur until all session slots are busied (64 for a FreeBSD
client/server), so many cases of the bug probably went undetected?
Also, use of sec=krb5[ip] mounts are not that common.

PR: 275905

(cherry picked from commit a558130881e9d574dc5f37827fe2284667d5aba8)

6 months agomips: Add a return value to cpu_set_upcall()
Mark Johnston [Tue, 2 Jan 2024 00:55:27 +0000 (19:55 -0500)]
mips: Add a return value to cpu_set_upcall()

This is a direct commit to stable/13.

6 months agocompat_freebsd4: Fix handling of errors from subyte()
Mark Johnston [Tue, 26 Dec 2023 01:43:38 +0000 (20:43 -0500)]
compat_freebsd4: Fix handling of errors from subyte()

Upon failure, subyte() returns -1, not an errno value.

MFC after: 1 week

(cherry picked from commit c38df501ce2ed7da128448f815ec627c39fd3bad)

6 months agoiscsi: Check for copyout errors in iscsi_ioctl_daemon_receive()
Mark Johnston [Tue, 26 Dec 2023 01:43:31 +0000 (20:43 -0500)]
iscsi: Check for copyout errors in iscsi_ioctl_daemon_receive()

Reviewed by: jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43148

(cherry picked from commit 74e713804fa4767991c5f20e6b85da4235107122)

6 months agonmount: Ignore errors when copying out an error string
Mark Johnston [Tue, 26 Dec 2023 01:43:21 +0000 (20:43 -0500)]
nmount: Ignore errors when copying out an error string

In general we copy error strings as part of reporting an error from
lower layers, so if the copyout() fails there's nothing to do since we'd
prefer to preserve the original error.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43147

(cherry picked from commit 099d25c354d93d9cd9c9cd261428f5ab0547a194)

6 months agogeom: Report copyout() errors in g_ctl_ioctl_ctl()
Mark Johnston [Tue, 26 Dec 2023 01:43:06 +0000 (20:43 -0500)]
geom: Report copyout() errors in g_ctl_ioctl_ctl()

Despite the name, req->serror is used in some cases to copy non-error
messages to userspace.  So, report errors when copying out so long as
they don't clobber an earlier error.

Reviewed by: mav, imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43146

(cherry picked from commit bbf221e3e822d15dafb37bd8e200a9864f2636b4)

6 months agogntdev: Handle errors from suword32() in gntdev_alloc_gref()
Mark Johnston [Tue, 26 Dec 2023 01:42:58 +0000 (20:42 -0500)]
gntdev: Handle errors from suword32() in gntdev_alloc_gref()

Try to copy out output values before handling errors, and check that we
did so successfully.  In particular, it doesn't seem sensible to ignore
errors here, otherwise userspace won't have any way to refer to the
allocations.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: royger
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43145

(cherry picked from commit 6cdff09c0d70f780a738dbd3d87deb3b13ec8446)

6 months agompr: Handle errors from copyout() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:42:49 +0000 (20:42 -0500)]
mpr: Handle errors from copyout() in ioctl handlers

In preparation for adding a __result_use_check annotation to copyin()
and related functions, start checking for errors from copyout() in
the mpr(4) user command handler.  This should make it easier to catch
bugs.

Reviewed by: imp, asomers
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D43177

(cherry picked from commit 68cc77a3b73ffda1e8ac891b9852faca833e11b7)

6 months agomps: Handle errors from copyout() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:42:33 +0000 (20:42 -0500)]
mps: Handle errors from copyout() in ioctl handlers

In preparation for adding a __result_use_check annotation to copyin()
and related functions, start checking for errors from copyout() in
the mps(4) user command handler.  This should make it easier to catch
bugs.

Reviewed by: imp, asomers
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D43176

(cherry picked from commit bcf4a7c7ace21a01d10003de9c7692f0887526c1)

6 months agoumtx: Check for errors from suword32()
Mark Johnston [Tue, 26 Dec 2023 01:42:17 +0000 (20:42 -0500)]
umtx: Check for errors from suword32()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D43144

(cherry picked from commit 3379d9b5de4c4876a317d25ca008e66b1111b701)

6 months agothread: Ignore errors when copying out during thr_exit()
Mark Johnston [Tue, 26 Dec 2023 01:42:04 +0000 (20:42 -0500)]
thread: Ignore errors when copying out during thr_exit()

It does not seem reasonable to return to userspace after calling
umtx_thread_exit().

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43143

(cherry picked from commit f450277f7a608f26624384e046c1987490c51296)

6 months agojail: Ignore errors from copyout() while copying the error string
Mark Johnston [Tue, 26 Dec 2023 01:41:54 +0000 (20:41 -0500)]
jail: Ignore errors from copyout() while copying the error string

Reviewed by: zlei, jamie
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43142

(cherry picked from commit abbc260f74b203646dd108ad4038627fcfb0ded7)

6 months agosendfile: Explicitly ignore errors from copyout()
Mark Johnston [Tue, 26 Dec 2023 01:41:32 +0000 (20:41 -0500)]
sendfile: Explicitly ignore errors from copyout()

There is a documented bug in sendfile.2 which notes that sendfile(2)
does not raise an error if it fails to copy out the number of bytes
written.  Explicitly ignore the error from copyout() calls in
preparation for annotating copyout() with __result_use_check.

Reviewed by: glebius, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43129

(cherry picked from commit d0adc2f283ad5db6b568ca533a056c9f635551cd)

6 months agoses: Add error checking for copyout() calls
Mark Johnston [Tue, 26 Dec 2023 01:40:33 +0000 (20:40 -0500)]
ses: Add error checking for copyout() calls

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: mav, imp, asomers
Tested by: asomers
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43130

(cherry picked from commit 771501e96ffd7e314c338300a351ad76d28a2f69)

6 months agopowerpc: Avoid ignoring copyin()'s return value
Mark Johnston [Tue, 26 Dec 2023 01:40:16 +0000 (20:40 -0500)]
powerpc: Avoid ignoring copyin()'s return value

A recent change made it possible for cpu_set_upcall() to return an
error.  Do that here instead of ignoring an error from copyin().

Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43105

(cherry picked from commit bdf03b4bcc4a9aa0be503dbc64415e6b0b845fbc)

6 months agolinux: Check for copyout errors in linux_fixup()
Mark Johnston [Tue, 26 Dec 2023 01:40:05 +0000 (20:40 -0500)]
linux: Check for copyout errors in linux_fixup()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, dchagin
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43104

(cherry picked from commit 3fde275167ce1f1455a03586d29840546d06d97a)

6 months agothread: Add a return value to cpu_set_upcall()
Mark Johnston [Tue, 26 Dec 2023 01:39:39 +0000 (20:39 -0500)]
thread: Add a return value to cpu_set_upcall()

Some implementations copy data to userspace, an operation which can in
principle fail.  In preparation for adding a __result_use_check
annotation to copyin() and related functions, let implementations of
cpu_set_upcall() return an error, and check for errors when copying data
to user memory.

Reviewed by: kib, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43100

(cherry picked from commit 7b68fb5ab2a276ccd081cc1a43cebf0fb315e952)

6 months agocompat_freebsd4: Check for errors from subyte() in freebsd4_uname()
Mark Johnston [Tue, 26 Dec 2023 01:39:21 +0000 (20:39 -0500)]
compat_freebsd4: Check for errors from subyte() in freebsd4_uname()

This is in preparation for adding a __result_use_check annotation to
copyin() and related functions.

Reviewed by: imp, kib, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43099

(cherry picked from commit 4f35450ce52a7b141e7ae8d37fa257b5f8971dda)

6 months agoocs: Check for copyin errors in the ioctl handler
Mark Johnston [Tue, 26 Dec 2023 01:38:57 +0000 (20:38 -0500)]
ocs: Check for copyin errors in the ioctl handler

If copyin() fails, the driver will blindly proceed with whatever had
been in the uninitialized DMA buffer.  This is not what we want.  Check
for copyin failures.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: ram
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43097

(cherry picked from commit a01ff11cb73d7a1988f6241f63d141371ff23717)

6 months agouhid: Check for errors from copyin() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:38:04 +0000 (20:38 -0500)]
uhid: Check for errors from copyin() in ioctl handlers

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: wulf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43103

(cherry picked from commit b2caed2f8d699d6dc59ecf8810d945cdea148c44)

6 months agohid: Handle errors from copyin() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:37:49 +0000 (20:37 -0500)]
hid: Handle errors from copyin() in ioctl handlers

If copyin() fails, the driver will proceed blindly with a zeroed buffer,
which is not what we want.  In preparation for annotating copyin() with
__result_use_check, start checking for errors.

Reviewed by: wulf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43102

(cherry picked from commit e452fa70d50761b5fe5f19c3c93c107be116728c)

6 months agofreebsd32: Report errors when copying out oldlenp in __sysctl
Mark Johnston [Tue, 26 Dec 2023 01:37:32 +0000 (20:37 -0500)]
freebsd32: Report errors when copying out oldlenp in __sysctl

This matches the native implementation's behaviour.

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43101

(cherry picked from commit 81eb7baa69e983fe159d254a4ed47d9c00396801)

6 months agoath: Handle errors from copyout() in ath_rate_fetch_node_stats()
Mark Johnston [Tue, 26 Dec 2023 01:35:43 +0000 (20:35 -0500)]
ath: Handle errors from copyout() in ath_rate_fetch_node_stats()

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43096

(cherry picked from commit 711880597c6c4ac971eb2aba6a2dadb5933d38dd)

6 months agoConvert fsidcmp(9) from macro to inline function
Konstantin Belousov [Tue, 26 Dec 2023 19:39:33 +0000 (21:39 +0200)]
Convert fsidcmp(9) from macro to inline function

(cherry picked from commit 3334a537ed385e487a47208dab8f36b25643bcdb)

6 months agoofed: use ANSI C functions definitions in opensm/sm.c
Konstantin Belousov [Tue, 26 Dec 2023 19:16:49 +0000 (21:16 +0200)]
ofed: use ANSI C functions definitions in opensm/sm.c

(cherry picked from commit bf7830d79dd02a84225c93130c2dce68e0a541d6)

6 months agoiommu_gas_remove(): consolidate places where decision is made to keep the entry
Konstantin Belousov [Fri, 22 Dec 2023 22:41:19 +0000 (00:41 +0200)]
iommu_gas_remove(): consolidate places where decision is made to keep the entry

(cherry picked from commit c0047e7c356953d138194ff71cc510ffe85425f0)

6 months agoiommu_gas: make placeholder entry at the start of the GAS zero size
Konstantin Belousov [Fri, 22 Dec 2023 22:19:05 +0000 (00:19 +0200)]
iommu_gas: make placeholder entry at the start of the GAS zero size

(cherry picked from commit f59128775636846574e092c68e849a56f74577e6)

6 months agoiommu: add iommu_gas_remove_locked()
Konstantin Belousov [Thu, 14 Dec 2023 02:41:31 +0000 (04:41 +0200)]
iommu: add iommu_gas_remove_locked()

(cherry picked from commit 273b4de3462d7825ebe4ace7a1930f098311287f)

6 months agoIOMMU: add GAS map entry flag IOMMU_MAP_ENTRY_FAKE
Konstantin Belousov [Fri, 22 Dec 2023 22:39:27 +0000 (00:39 +0200)]
IOMMU: add GAS map entry flag IOMMU_MAP_ENTRY_FAKE

(cherry picked from commit a59c252903e81f46c74903ce5b1cf0960927dbcc)

6 months agoiommu_gas: zero fake on-stack map entry used in iommu_gas_remove_clip_left()
Konstantin Belousov [Sun, 24 Dec 2023 00:59:19 +0000 (02:59 +0200)]
iommu_gas: zero fake on-stack map entry used in iommu_gas_remove_clip_left()

(cherry picked from commit cb1d664b0073232173072231cb386f0216ee596b)

6 months agoiommu_gas: print entries flags and domains if an overlap detected
Konstantin Belousov [Sat, 23 Dec 2023 23:34:16 +0000 (01:34 +0200)]
iommu_gas: print entries flags and domains if an overlap detected

(cherry picked from commit 733da1eb947688210bc152656357ecafbd172bb7)

6 months agoDMAR: add knob to disable RMRR entries installation into domains
Konstantin Belousov [Sat, 23 Dec 2023 16:57:19 +0000 (18:57 +0200)]
DMAR: add knob to disable RMRR entries installation into domains

(cherry picked from commit 24e38af60a637073b5164837959098acaa3d8daa)

6 months agoiommu_gas: add ddb 'show iommu_domain' command
Konstantin Belousov [Sun, 24 Dec 2023 14:52:00 +0000 (16:52 +0200)]
iommu_gas: add ddb 'show iommu_domain' command

(cherry picked from commit 30ce85ca11433ba05cdbab8aedceaa15a93bd97a)

6 months agoiommu_gas_match_one(): check for underflow
Konstantin Belousov [Tue, 26 Dec 2023 00:57:00 +0000 (02:57 +0200)]
iommu_gas_match_one(): check for underflow

(cherry picked from commit a869643e184a73382ef7939b465fd42785e096d1)

6 months agodmar(9): style, fix indent
Konstantin Belousov [Fri, 15 Dec 2023 11:24:44 +0000 (13:24 +0200)]
dmar(9): style, fix indent

(cherry picked from commit 7153d5e4bc67732f8258d50ffffa42a09a19b427)

6 months agoiommu: remove leftover sys/cdefs.h includes
Konstantin Belousov [Sun, 24 Dec 2023 14:24:05 +0000 (16:24 +0200)]
iommu: remove leftover sys/cdefs.h includes

(cherry picked from commit 6afa2333d2e42e1df67a0fab20f0ede76dff516d)

6 months agoMerge commit c97a7675eea4 from llvm git (by Qiu Chaofan):
Dimitry Andric [Fri, 29 Dec 2023 19:30:45 +0000 (20:30 +0100)]
Merge commit c97a7675eea4 from llvm git (by Qiu Chaofan):

  [PowerPC] Expand FSINCOS of fp128 (#76494)

This fixes "fatal error: error in backend: Cannot select: 0x6d420285c0:
f128,f128 = fsincos 0x6d4202b6f0" when compiling s_cpowl.c for
powerpc64le.

Upstream ticket: https://github.com/llvm/llvm-project/issues/76442

Reported by: pkubaj
MFC after: 3 days

(cherry picked from commit 79639686401bedbcbbf04eb71e0acb1cc7dcbbcb)

6 months agoMinimize libc++ errno-related header diffs with upstream
Dimitry Andric [Mon, 25 Dec 2023 17:18:31 +0000 (18:18 +0100)]
Minimize libc++ errno-related header diffs with upstream

In commit 88640c0e8b6f5 the new EINTEGRITY errno value was added, and
this caused us to carry a patch for upstream libc++ since that time.
Because it can cause merge conflicts when importing libc++ code from
upstream, I have submitted an upstream pull request to get most of that
patch integrated.

It turns out that we do not need the errno.h part of it at all, since
all supported FreeBSD versions define EOWNERDEAD and ENOTRECOVERABLE,
and therefore the block that juggles with ELAST values is never used in
FreeBSD. At the moment it only applies to older versions of Linux, or
possibly other platforms.

Therefore the only part that needs to stay is the definition of a enum
errc value for EINTEGRITY, and this is made optional upon EINTEGRITY
being defined, to make it suitable for upstreaming.

No functional change is intended.

MFC after: 1 week

(cherry picked from commit 1ff41cad716adeba0d408652c92c81e59e3ba316)

6 months agoReorganize libclang_rt Makefile and make more lib/arch combos available
Dimitry Andric [Thu, 28 Dec 2023 12:57:41 +0000 (13:57 +0100)]
Reorganize libclang_rt Makefile and make more lib/arch combos available

Upstream has made more clang runtime libraries available for more
architectures, so add them. To make this easier, split up subdir lists
into functional parts (asan, tsan, etc), and put each architecture into
its own .if block.

Effectively, this adds the following libraries for aarch64: asan, cfi,
fuzzer, msan, safestack, stats, tsan, ubsan, xray.

PR: 262706
MFC after: 3 days

(cherry picked from commit e77a1bb2757471ab3fed0750b76eeb15d0c7b10a)

6 months agoTeach if_smsc to get MAC from bootargs.
Ronald Klop [Sat, 4 Nov 2023 14:14:00 +0000 (15:14 +0100)]
Teach if_smsc to get MAC from bootargs.

Some Raspberry Pi pass smsc95xx.macaddr=XX:XX:XX:XX:XX:XX as bootargs.
Use this if no ethernet address is found in an EEPROM.
As last resort fall back to ether_gen_addr() instead of random MAC.

(cherry picked from commit 3878bbf1bb9e68f8579b57cde7d4e5c77de93320)

if_smsc: fix build on armv6 & armv7

compile error was:
/usr/src/sys/dev/usb/net/if_smsc.c:1597:40: error: format specifies type 'unsigned long' but the argument has type 'ssize_t' (aka 'int') [-Werror,-Wformat]
                                "failed alloc for bootargs (%lu)", len);
                                                            ~~~    ^~~
                                                            %zd

(cherry picked from commit 8a0ee306227a17a998bdc7af2275fd94b9164342)

PR: 274092
Reported by: Patrick M. Hausen (via ML)
Reviewed by: imp, karels, zlei
Tested by: Patrick M. Hausen
Approved by: karels
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D42463

6 months agofortune: update mailing list search url
Christos Margiolis [Wed, 27 Dec 2023 16:28:11 +0000 (18:28 +0200)]
fortune: update mailing list search url

Markmail no longer exists.

Reviewed by: markj
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D43209

(cherry picked from commit 2b1c477d88e579585c6b3ba5f6ded70b9a05e3c3)

6 months agovfs_domount_update(): correct fsidcmp() usage
Andrew Gierth [Sun, 24 Dec 2023 12:04:21 +0000 (14:04 +0200)]
vfs_domount_update(): correct fsidcmp() usage

(cherry picked from commit 2a1d50fc12f6e604da834fbaea961d412aae6e85)

6 months agofreebsd32: Fix error handling for suword32() calls
Mark Johnston [Thu, 21 Dec 2023 16:51:29 +0000 (11:51 -0500)]
freebsd32: Fix error handling for suword32() calls

suword32() returns -1 upon an error, not an errno value.

MFC after: 1 week

(cherry picked from commit bd1654ce92569bbfbe513749db08cdd781b3a036)

6 months agoufs: Update *eofflag upon a read of an unlinked directory
Mark Johnston [Thu, 21 Dec 2023 18:26:13 +0000 (13:26 -0500)]
ufs: Update *eofflag upon a read of an unlinked directory

If the directory is unlinked, no further entries will be returned, but
we return no error.  At least one caller (vn_dir_next_dirent()) asserts
that a VOP_READDIR call which returns no error and no entries will set
*eofflag != 0, so the current behaviour of UFS can trigger an assertion
failure.

Simply set *eofflag in this scenario.

Reviewed by: olce, kib
Reported by: syzkaller
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43089

(cherry picked from commit 3ff574c5e1d1d5d07763a14f22d6f9d7291550c6)

6 months agoieee80211: Check for copyout() errors in the SIOCG80211STATS handler
Mark Johnston [Tue, 19 Dec 2023 03:44:54 +0000 (22:44 -0500)]
ieee80211: Check for copyout() errors in the SIOCG80211STATS handler

In preparation for annotating copyin() and related functions with
__result_use_check.

Reviewed by: bz, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43095

(cherry picked from commit d760d74dbed81638979e662130e24111b3a5db0d)

6 months agokthread: Set *newtdp earlier in kthread_add1()
Mark Johnston [Sat, 9 Dec 2023 15:22:06 +0000 (10:22 -0500)]
kthread: Set *newtdp earlier in kthread_add1()

syzbot reported a single boot-time crash in g_event_procbody(), a page
fault when dereferencing g_event_td.  g_event_td is initialized by the
kproc_kthread_add() call which creates the GEOM event thread:

  kproc_kthread_add(g_event_procbody, NULL, &g_proc, &g_event_td,
      RFHIGHPID, 0, "geom", "g_event");

I believe that the caller of kproc_kthread_add() was preempted after
adding the new thread to the scheduler, and before setting *newtdp,
which is equal to g_event_td.  Thus, since the first action of the GEOM
event thread is to lock itself, it ended up dereferencing a NULL
pointer.

Fix the problem simply by initializing *newtdp earlier.  I see no harm
in that, and it matches kproc_create1().  The scheduler provides
sufficient synchronization to ensure that the store is visible to the
new thread, wherever it happens to run.

Reported by: syzbot+5397f4d39219b85a9409@syzkaller.appspotmail.com
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42986

(cherry picked from commit ae77041e0714627f9ec8045ca9ee2b6ea563138e)

6 months agonetlink: fix snl_writer and linear_buffer re-allocation logic
Igor Ostapenko [Tue, 12 Dec 2023 18:26:21 +0000 (19:26 +0100)]
netlink: fix snl_writer and linear_buffer re-allocation logic

- Use the correct base pointer after re-allocation to avoid buffer
  overflows.

- Maintain correct snl_writer.size, which avoids redundant memory
  allocation, e.g. a need for ~1k bytes may end up with ~32k
  linear_buffer actually allocated.

This fixes a pfctl regression at least for armv7 after the addrule logic
migration to netlink:
  ffbf25951e7b ("pf: convert rule addition to netlink")

The add rule command creates a bigger than default size netlink requests
which triggers the re-allocation logic.

Reviewed by: kp
MFC after: 2 weeks
Differnetial Revision: https://reviews.freebsd.org/D43003

(cherry picked from commit 0c511bafdd5b309505c13c8dc7c6816686d1e103)

6 months agoocs_fc: Use xpt_path_sbuf() to copy the path to sbuf.
Ram Kishore Vegesna [Wed, 13 Dec 2023 07:56:40 +0000 (13:26 +0530)]
ocs_fc: Use xpt_path_sbuf() to copy the path to sbuf.

 Reported by: imp
 MFC after: 1 week

(cherry picked from commit a9504d76ccdad240b7d5761f4208e252f57042dd)

6 months agoocs_fc: IO timeout handling and error reporting fix.
Ram Kishore Vegesna [Tue, 12 Dec 2023 15:22:58 +0000 (10:22 -0500)]
ocs_fc: IO timeout handling and error reporting fix.

Hardware timeout uses a 8-bit timeout value and expects the timeout to
be less than 255 seconds. Added software timer implemetation to timeout
and abort the IOs with timeout more than 255 seconds.

Fix the timeout problem by dividing CAM timeouts by 1000 as hardware
expects timeout value in seconds.  Before this change, CAM timeouts in
milliseconds were getting truncated to 8 bits and converted to seconds.
So the actual timeout used when going down to the card would depend on
the bottom 8 bits of the timeout used.

Add the mapping of ocs_fc error status to CAM status.

Reported by: ken
Reviewed by: ken
Tested by: ken, ram
Approved by: ken
MFC after: 1 week

(cherry picked from commit 70547544ce931357c980be47d937e5b57a2d7f49)

6 months agobhyve.8: add missed dot
Konstantin Belousov [Thu, 21 Dec 2023 23:54:39 +0000 (01:54 +0200)]
bhyve.8: add missed dot

(cherry picked from commit 59a35b7c6b1a955920eff8dcade2ceec4d5d5fd6)

6 months agovmm.h: remove dup declaration
Konstantin Belousov [Wed, 20 Dec 2023 23:40:00 +0000 (01:40 +0200)]
vmm.h: remove dup declaration

(cherry picked from commit 7c8f16318499d2b05e916abd66148e5409284a9d)

6 months agoFix snprintf truncation in telnet
Dimitry Andric [Thu, 21 Dec 2023 22:35:17 +0000 (23:35 +0100)]
Fix snprintf truncation in telnet

Building telnet with clang 18 results in the following warning:

  contrib/telnet/telnet/telnet.c:231:5: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 11 [-Werror,-Wformat-truncation]
    231 |     snprintf(temp2, sizeof(temp2), "%c%c%c%c....%c%c", IAC, SB, TELOPT_COMPORT,
|     ^

The temp2 buffer is 10 chars, while the format string also consists of
10 chars. Therefore, snprintf(3) will truncate the last character, 'SE'
(end sub negotation) in this case.

Bump the buffer to 11 chars to avoid truncation.

MFC after: 3 days

(cherry picked from commit c794d188222a4d3414233ff9630d47eedc090fbe)

6 months agoSilence VLA extension warnings in fusefs tests
Dimitry Andric [Thu, 21 Dec 2023 22:41:57 +0000 (23:41 +0100)]
Silence VLA extension warnings in fusefs tests

Building tests/sys/fs/fusefs with clang 18 results the following
warning:

  tests/sys/fs/fusefs/cache.cc:145:14: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
    145 |         uint8_t buf[bufsize];
        |                     ^~~~~~~

Because we do not particularly care that this is a clang extension,
suppress the warning.

MFC after: 3 days

(cherry picked from commit dc0b4094abf6784bf1a9492c2fea3fb91116b014)

6 months agoSilence snprintf truncation warnings in printf_test examples
Dimitry Andric [Thu, 21 Dec 2023 22:39:15 +0000 (23:39 +0100)]
Silence snprintf truncation warnings in printf_test examples

Building share/examples/tests with clang 18 results in a few warnings
like:

  share/examples/tests/tests/plain/printf_test.c:67:6: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 17 [-Werror,-Wformat-truncation]
     67 |         if (snprintf(buffer, sizeof(buffer), "0123456789abcdef") != 16)
        |             ^

Since these tests are meant as an example of testing snprintf overflow,
suppress the warnings.

MFC after: 3 days

(cherry picked from commit 69c8025a498450b6bc4cc9e97ba779ed1c2e7f4b)

6 months agoMerge commit 989879f8fded from llvm git (by Paul Walker):
Dimitry Andric [Mon, 4 Dec 2023 17:59:02 +0000 (18:59 +0100)]
Merge commit 989879f8fded from llvm git (by Paul Walker):

  [Clang] Allow C++11 style initialisation of SVE types.

  Fixes https://github.com/llvm/llvm-project/issues/63223

  Differential Revision: https://reviews.llvm.org/D153560

Requested by: andrew
MFC after: 3 days

(cherry picked from commit 641efdd10cc3ad05fb7eaeeae20b15c5ad4128c8)

6 months agocontrib/tzdata: import tzdata 2023d
Philip Paeps [Sat, 23 Dec 2023 01:51:01 +0000 (09:51 +0800)]
contrib/tzdata: import tzdata 2023d

Changes: https://github.com/eggert/tz/blob/2023d/NEWS

(cherry picked from commit eebb9c2caea1584773ae4cec311cee1eea5b1655)

6 months agortnetlink.4: Fix a typo in the manual pag
Gordon Bergling [Wed, 20 Dec 2023 09:06:08 +0000 (10:06 +0100)]
rtnetlink.4: Fix a typo in the manual pag

- s/constists/consists/

(cherry picked from commit fa826f64e1b7167dde2c3cb8cfc4df0d3e503542)

6 months agovtnet: don't leak pfil(9) data on detach
Gleb Smirnoff [Wed, 5 Jan 2022 02:41:05 +0000 (18:41 -0800)]
vtnet: don't leak pfil(9) data on detach

PR: 260667
Submitted by: <ghuckriede blackberry.com>

(cherry picked from commit 3f6ab5493f4b89e7625dd31f807065cfae6c503d)

6 months agolibc: correct some memory leaks in acl_to_text(3) and acl_to_text_np(3)
Peter Eriksson [Sun, 17 Dec 2023 22:03:13 +0000 (00:03 +0200)]
libc: correct some memory leaks in acl_to_text(3) and acl_to_text_np(3)

PR: 275232

(cherry picked from commit 7aa375dcc61e48cc56da45c9d5a11371693c8043)

6 months agoufs: do not leave around empty buffers shadowing disk content
Konstantin Belousov [Mon, 11 Dec 2023 22:57:28 +0000 (00:57 +0200)]
ufs: do not leave around empty buffers shadowing disk content

(cherry picked from commit ca39f23347e1416a28dde13279bfe5841ad9a746)

6 months agotcp_wrappers: recognize IPv6 addresses/prefixes
Gleb Smirnoff [Thu, 20 Jul 2023 21:56:20 +0000 (14:56 -0700)]
tcp_wrappers: recognize IPv6 addresses/prefixes

Intentionally or not, but the libwrap was written in such manner that
if your /etc/hosts.allow doesn't have any domain names, neither smart
keywords like LOCAL or KNOWN, then it will not try to resolve the
client address during the hosts check.  This was achieved with the
NOT_INADDR() check that matched IPv4 addresses/prefixes.  Extend this
to also skip resolve if client list token looks like IPv6.

Reviewed by: philip, emaste
PR: 269456
Differential revision: https://reviews.freebsd.org/D40070

(cherry picked from commit 1d9722de6f90c3edf286b077938bfa696e728d6c)

6 months agoEnsure 'struct thread' is aligned to a cache line
Olivier Certner [Fri, 13 Oct 2023 08:52:31 +0000 (10:52 +0200)]
Ensure 'struct thread' is aligned to a cache line

Using the new UMA_ALIGN_CACHE_AND_MASK() facility, which allows to
simultaneously guarantee a minimum of 32 bytes of alignment (the 5 lower
bits are always 0).

For the record, to this day, here's a (possibly non-exhaustive) list of
synchronization primitives using lower bits to store flags in pointers
to thread structures:
- lockmgr, rwlock and sx all use the 5 bits directly.
- rmlock indirectly relies on sx, so can use the 5 bits.
- mtx (non-spin) relies on the 3 lower bits.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42266

(cherry picked from commit 7d1469e555bdce32b3dfc898478ae5564d5072b1)

Approved by:    markj (mentor)

6 months agouma: Permit specifying max of cache line and some custom alignment
Olivier Certner [Fri, 13 Oct 2023 15:05:34 +0000 (17:05 +0200)]
uma: Permit specifying max of cache line and some custom alignment

To be used for structures for which we want to enforce that pointers to
them have some number of lower bits always set to 0, while still
ensuring we benefit from cache line alignment to avoid false sharing
between structures and fields within the structures (provided they are
properly ordered).

First candidate consumer that comes to mind is 'struct thread', see next
commit.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42265

(cherry picked from commit 733e0abd2897289e2acf70f7c72e31a5a560394a)

Approved by:    markj (mentor)

6 months agolinuxkpi: dma_get_cache_alignment(): Fix off-by-one result
Olivier Certner [Fri, 13 Oct 2023 15:13:28 +0000 (17:13 +0200)]
linuxkpi: dma_get_cache_alignment(): Fix off-by-one result

Substituting 'uma_align_cache' by the appropriately named accessor
uma_get_cache_align_mask() made apparent that dma_get_cache_alignment()
was off by one, since it was defined to be the mask derived from the
alignment value.

Reviewed by:            markj, bz
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42264

(cherry picked from commit 2c7dd66d09a1b92a4698232996cded6e5315b3bd)

Approved by:    markj (mentor)

6 months agouma: New check_align_mask(): Validate alignments (INVARIANTS)
Olivier Certner [Fri, 13 Oct 2023 14:09:51 +0000 (16:09 +0200)]
uma: New check_align_mask(): Validate alignments (INVARIANTS)

New function check_align_mask() asserts (under INVARIANTS) that the mask
fits in a (signed) integer (see the comment) and that the corresponding
alignment is a power of two.

Use check_align_mask() in uma_set_align_mask() and also in uma_zcreate()
to replace the KASSERT() there (that was checking only for a power of
2).

Reviewed by:            kib, markj
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42263

(cherry picked from commit 87090f5e5a7b927a2ab30878435f6dcba0705a1d)

Approved by:    markj (mentor)

6 months agoarm: Update declarations for arm_dcache_align{,_mask}
Mark Johnston [Thu, 2 Nov 2023 16:23:51 +0000 (12:23 -0400)]
arm: Update declarations for arm_dcache_align{,_mask}

Reported by: Jenkins
Fixes: 3d8f548b9e57 ("uma: Make the cache alignment mask unsigned")

(cherry picked from commit 185aa8c9c3d7a01d616cfaafd492f61b37ed2551)

Approved by:    markj (mentor)

6 months agouma: Make the cache alignment mask unsigned
Olivier Certner [Fri, 13 Oct 2023 12:49:11 +0000 (14:49 +0200)]
uma: Make the cache alignment mask unsigned

In uma_set_align_mask(), ensure that the passed value doesn't have its
highest bit set, which would lead to problems since keg/zone alignment
is internally stored as signed integers.  Such big values do not make
sense anyway and indicate some programming error.  A future commit will
introduce checks for this case and other ones.

Reviewed by:            kib, markj
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42262

(cherry picked from commit 3d8f548b9e5772ff6890bdc01f7ba7b76203857d)

Approved by:    markj (mentor)

6 months agoarm: Simplify get_cachetype_cp15()
Olivier Certner [Fri, 13 Oct 2023 12:22:14 +0000 (14:22 +0200)]
arm: Simplify get_cachetype_cp15()

There's no point in setting 'arm_dcache_align_mask' before the
function's end.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42261

(cherry picked from commit 1bce6f951a902f03bfb354f5b11473a0d12b3d7d)

Approved by:    markj (mentor)

6 months agouma: UMA_ALIGN_CACHE: Resolve the proper value at use point
Olivier Certner [Fri, 13 Oct 2023 12:13:30 +0000 (14:13 +0200)]
uma: UMA_ALIGN_CACHE: Resolve the proper value at use point

Having a special value of -1 that is resolved internally to
'uma_align_cache' provides no significant advantages and prevents
changing that variable to an unsigned type, which is natural for an
alignment mask.  So suppress it and replace its use with a call to
uma_get_align_mask().  The small overhead of the added function call is
irrelevant since UMA_ALIGN_CACHE is only used when creating new zones,
which is not performance critical.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42259

(cherry picked from commit e557eafe7233f8231c1f5f5b098e4bab8e818645)

Approved by:    markj (mentor)

6 months agouma: Hide 'uma_align_cache'; Create/rename accessors
Olivier Certner [Fri, 13 Oct 2023 09:52:28 +0000 (11:52 +0200)]
uma: Hide 'uma_align_cache'; Create/rename accessors

Create the uma_get_cache_align_mask() accessor and put it in a separate
private header so as to minimize namespace pollution in header/source
files that need only this function and not the whole 'uma.h' header.

Make sure the accessors have '_mask' as a suffix, so that callers are
aware that the real alignment is the power of two that is the mask plus
one.  Rename the stem to something more explicit.  Rename
uma_set_cache_align_mask()'s single parameter to 'mask'.

Hide 'uma_align_cache' to ensure that it cannot be set in any other way
then by a call to uma_set_cache_align_mask(), which will perform sanity
checks in a further commit.  While here, rename it to
'uma_cache_align_mask'.

This is also in preparation for some further changes, such as improving
the sanity checks, eliminating internal resolving of UMA_ALIGN_CACHE and
changing the type of the 'uma_cache_align_mask' variable.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42258

(cherry picked from commit dc8f7692fd1de628814f4eaf4a233dccf4c92199)

Approved by:    markj (mentor)

6 months agoEnsure "init" (PID 1) also executes userret() initially
Olivier Certner [Tue, 10 Oct 2023 17:36:20 +0000 (19:36 +0200)]
Ensure "init" (PID 1) also executes userret() initially

Calling userret() from fork_return() misses the first return to
userspace of the "init" (PID 1) process.  The latter is indeed created
by fork1() followed by a call to cpu_fork_kthread_handler() call that
replaces fork_return() by start_init() as the function to execute after
fork.

A new process' initial return to userspace in the end always happens
through returning from fork_exit(), so move userret() there instead to
fix the omission.

This problem was discovered as part of a revamp of scheduling priorities
that lead to experimenting with asserting and sometimes resetting
priorities in sched_userret(), in the course of which the author
stumbled on panics being triggered only in init() or only in other
processes, depending on the modifications to sched_userret().  This
change currently has no practical effect but will have some in the near
future.

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42257

(cherry picked from commit eac624207ccf3a16225368d226861b06e3631d0d)

Approved by:    markj (mentor)

6 months agopdinit(): Fix comment
Olivier Certner [Tue, 26 Sep 2023 10:26:46 +0000 (12:26 +0200)]
pdinit(): Fix comment

Reviewed by:            markj, kib
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42256

(cherry picked from commit 56bb3ce091371ffd95711c65e1eff306a19435e2)

Approved by:    markj (mentor)

6 months agosetusercontext(): Apply personal settings only on matching effective UID
Olivier Certner [Tue, 30 May 2023 16:35:08 +0000 (18:35 +0200)]
setusercontext(): Apply personal settings only on matching effective UID

Commit 35305a8dc114 (r211393) added a check on whether 'uid' was equal
to getuid() before calling setlogincontext().  Doing so still allows
a setuid program to apply resource limits and priorities specified in
a user-controlled configuration file ('~/.login_conf') where
a non-setuid program could not.  Plug the hole by checking instead that
the process' effective UID is the target one (which is likely what was
meant in the initial commit).

PR:                     271750
Reviewed by:            kib, des
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40351

(cherry picked from commit 892654fe9b5a9115815c30a423b8db47185aebbd)

Approved by:    markj (mentor)

6 months agologin_cap.c: Don't set errno to ERANGE on memory allocation failure
Olivier Certner [Thu, 25 May 2023 11:48:40 +0000 (13:48 +0200)]
login_cap.c: Don't set errno to ERANGE on memory allocation failure

Modified functions: login_getcaptime(), login_getcapnum(),
login_getcapsize().

They all call cgetstr(), which returns -2 on such conditions and already
sets errno to ENOMEM, arguably the appropriate value for these functions
as well.

No in-tree consumer currently checks for errno on error reported by
these functions, so this change has no other code impact.

Reviewed by:            kib
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40342

(cherry picked from commit b8c1aadef9d80786daf731300c33d3a001261422)

Approved by:    markj (mentor)

6 months agosetusercontext(): Fix gap when setting a realtime-class priority
Olivier Certner [Thu, 25 May 2023 07:10:27 +0000 (09:10 +0200)]
setusercontext(): Fix gap when setting a realtime-class priority

The login.conf's "priority" capability allows to set priorities in the
idle or realtime classes in addition to the classical nice values (-20
to 20), through a natural extension where values greater than 20 put the
processes in the idle class (with priority adjusted within RTP_PRIO_MIN
and RTP_PRIO_MAX, 21 being converted to 0, 22 to 1, etc.) and values
lower than -20 put the process in the realtime class (with priority
adjusted within RTP_PRIO_MIN and RTP_PRIO_MAX, -21 being converted to
RTP_PRIO_MAX (31), -22 to 30, etc.).

Before this fix, in the latter case (realtime class), -21 was converted
to 30, and RTP_PRIO_MAX (31) could never be specified.

While here, change the priority computation for the idle-class case to
be symmetrical and use RTP_PRIO_MIN (in practice, this changes nothing
at all, since RTP_PRIO_MIN is 0; but this is the correct theoretical
formula, which would work as well with other values of RTP_PRIO_MIN).

PR:                     271727
Reviewed by:            imp, kib
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40339

(cherry picked from commit bd572be78436473a2ad4c1b78728b739c74ef238)

Approved by:    markj (mentor)

6 months agosysctl(8): Mention more security.bsd knobs; Refer to security(7)
Olivier Certner [Thu, 17 Aug 2023 23:54:49 +0000 (01:54 +0200)]
sysctl(8): Mention more security.bsd knobs; Refer to security(7)

Reviewed by:            mhorne, pauamma_gundo.com, emaste
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41113

(cherry picked from commit 8d7a48d367ffde2a29419ef943c4099984e3af4d)

Approved by:    markj (mentor)

6 months agoptrace(2): Disabling: Describe influence of security.bsd.see_jail_proc
Olivier Certner [Thu, 17 Aug 2023 23:54:48 +0000 (01:54 +0200)]
ptrace(2): Disabling: Describe influence of security.bsd.see_jail_proc

Reviewed by:            mhorne, emaste, pauamma_gundo.com
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41109

(cherry picked from commit d952820105d6a2ad87ddf3bdc6c5fc5215d13b87)

Approved by:    markj (mentor)

6 months agosecurity(7): security.bsd.see*: Be more accurate
Olivier Certner [Thu, 17 Aug 2023 23:54:48 +0000 (01:54 +0200)]
security(7): security.bsd.see*: Be more accurate

Reviewed by:            mhorne, pauamma_gundo.com
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41108

(cherry picked from commit 61b6e00bee1d39e9c688e728fbf3a4efcdb61e66)

Approved by:    markj (mentor)

6 months agocr_canseeothergids(): Policy change's manual pages impact
Olivier Certner [Thu, 17 Aug 2023 23:54:46 +0000 (01:54 +0200)]
cr_canseeothergids(): Policy change's manual pages impact

See previous commit that made cr_canseeothergids() use the new
realgroupmember() function, taking into account real group IDs instead
of effective ones.

PR:                     272093
Reviewed by:            pauamma_gundo.com, mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40644

(cherry picked from commit 0452dd841336cea7cd979b13ef12b6ea5e992eff)

Approved by:    markj (mentor)

6 months agocr_canseeothergids(): Use real instead of effective group membership
Olivier Certner [Thu, 17 Aug 2023 23:54:45 +0000 (01:54 +0200)]
cr_canseeothergids(): Use real instead of effective group membership

Using the effective group and not the real one when testing membership
has the consequence that unprivileged processes cannot see setuid
commands they launch until these have relinquished their privileges.
This is also in contradiction with how the similar cr_canseeotheruids()
works, i.e., by taking into account real user IDs.

Fix this by substituting groupmember() with realgroupmember().  While
here, simplify the code.

PR:                     272093
Reviewed by:            mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40642

(cherry picked from commit 91658080f1a598ddda03943a783c9a941199f7d2)

Approved by:    markj (mentor)

6 months agorealgroupmember(9): Link to groupmember(9), document the function
Olivier Certner [Thu, 17 Aug 2023 23:54:46 +0000 (01:54 +0200)]
realgroupmember(9): Link to groupmember(9), document the function

Reviewed by:            bcr (older version), mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40643

(cherry picked from commit 5d9f38405a10fdcd9fc108c940dcf2642e9f1833)

Approved by:    markj (mentor)

6 months agoNew realgroupmember()
Olivier Certner [Thu, 17 Aug 2023 23:54:45 +0000 (01:54 +0200)]
New realgroupmember()

Like groupmember(), but taking into account the real group instead of
the effective group.  Leverages the new supplementary_group_member()
function.

Reviewed by:            mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40641

(cherry picked from commit 2a2bfa6ad92e9c82dcc55733ad2fd58fd2ea7559)

Approved by:    markj (mentor)

6 months agogroupmember(): Extract the supplementary group search in a separate function
Olivier Certner [Thu, 17 Aug 2023 23:54:44 +0000 (01:54 +0200)]
groupmember(): Extract the supplementary group search in a separate function

This is in preparation for the introduction of the new realgroupmember()
function, which does the same search into supplementary groups as
groupmember().

Reviewed by:            mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40640

(cherry picked from commit b725f232f3b09b4bcbc426854fe1545234c66965)

Approved by:    markj (mentor)

6 months agoprison_check(9): Bring up-to-date with hierarchical jails
Olivier Certner [Thu, 17 Aug 2023 23:54:44 +0000 (01:54 +0200)]
prison_check(9): Bring up-to-date with hierarchical jails

Reviewed by:            bcr, emaste, pauamma_gundo.com, mhorne
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40639

(cherry picked from commit e9fdd494537ca45b14e0917e8bb1595b6460f3a3)

Approved by:    markj (mentor)

6 months agop_candebug(9): cr_bsd_visible() impacts, misc fixes
Olivier Certner [Thu, 17 Aug 2023 23:54:43 +0000 (01:54 +0200)]
p_candebug(9): cr_bsd_visible() impacts, misc fixes

Mention cr_bsd_visible(9).  Remove references to cr_canseeothergids(9)
and cr_canseeotheruids(9), as well as indirect references not
immediately useful.

Fix description of credentials checks to match reality.

Re-order errors to match code's check order.

Reviewed by:            bcr, pauamma_gundo.com
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40638

(cherry picked from commit eb94f24fab4b44f13ca045370d9fcf12ca8835f2)

Approved by:    markj (mentor)

6 months agop_cansee(9): Bring up-to-date, misc fixes
Olivier Certner [Thu, 17 Aug 2023 23:54:43 +0000 (01:54 +0200)]
p_cansee(9): Bring up-to-date, misc fixes

Essentially defer to cr_cansee(9), except for the specifics.

Be more specific on the return codes.

Reviewed by:            bcr, pauamma_gundo.com
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40637

(cherry picked from commit 2ede38aff5d4c91a17ab6d093f2e8cce24b5418b)

Approved by:    markj (mentor)