EEXIST is possible in a race condition.
Inspired by: ffc72591b1 (Don't worry if a module is already loaded ...)
Reviewed by: glebius
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44633
(cherry picked from commit f6f67f58c1)
(cherry picked from commit 2e8d60c685)
Both the mbuf length and the total packet length are signed.
While here, update a stall comment to reflect the current practice.
Reviewed by: kp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42390
(cherry picked from commit e7102929bf)
(cherry picked from commit 4d65728d55)
There is no sense to have separate implementations for FreeBSD and Linux. Make
Linux code shared as more functional and just register FreeBSD-specific prune
callback with arc_add_prune_callback() API.
Aside of code cleanup this fixes excessive pruning on FreeBSD.
[olce: This code comes from the OpenZFS pull request:
https://github.com/openzfs/zfs/pull/16083, vendor-merged into our tree. Its
commit message has been slightly adapted to the present context. The upstream
pull request has been reviewed and merged into 'zfs-2.1.16-staging' as
5b81b1bf5e6d6aeb8a87175dcb12b529185cac2f, which should come into our tree at the
next vendor import. This is the same code that was merged into stable/14 and
main as part of vendor merges, and released as an EN (FreeBSD-EN-23:18.openzfs)
over releng/14.0 by markj@.]
PR: 275594, 274698
Reported by: Seigo Tanimura <seigo.tanimura@gmail.com>, markj, and others
Tested by: olce
Approved by: emaste (mentor)
Obtained from: OpenZFS
Sponsored by: iXsystems, Inc.
Sponsored by: The FreeBSD Foundation
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
The variable fileid stores the result from kern_kldload() but never gets
used. Since the third parameter `*fileid` of kern_kldload() can be NULL,
this unused variable can be safely removed.
No functional change intended.
Reviewed by: emaste, bz, #linuxkpi
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44583
(cherry picked from commit 317cc829ee)
(cherry picked from commit d4d5aed66a)
The history section (added in CSRG) claimed both first appeared in v6.
Looking at the manuals in the TUHS archive, /dev/mem was in v1
and /dev/kmem was introduced in v5.
Reviewed by: imp
Obtained from: OpenBSD
Differential Revision: https://reviews.freebsd.org/D44486
(cherry picked from commit 8a56ef8d75)
fdisk and disklabel are legacy tools for legacy disk partitioning
schemes.
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D43564
(cherry picked from commit 8669e516f0)
(cherry picked from commit 7ced571062)
ccd(4) previoulsy had knowledge of BSD disklabels, and relied on their
use on the underlying disks, but this hasn't been the case since 2003
(commit 0f76d6d822).
Remove disklabel references from the man page.
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D43574
(cherry picked from commit a3ed434a69)
(cherry picked from commit b5ae8f2171)
Rather than reject new bridge members because they have the wrong MTU
change it to match the bridge. If that fails, reject the new interface.
PR: 264883
Different Revision: https://reviews.freebsd.org/D35597
(cherry picked from commit 1865ebfb12)
A nonzero `userrefs` of a linker file indicates that the file, either
loaded from kldload(2) or preloaded, can be unloaded via kldunload(2).
As for the kernel file, it can be unloaded by the loader but should not
be after initialization.
This change fixes regression from d9ce8a41ea which incidentally
increases `userrefs` of the kernel file.
Reviewed by: dfr, dab, jhb
Fixes: d9ce8a41ea kern_linker: Handle module-loading failures in preloaded .ko files
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D42530
(cherry picked from commit 39450eba8e)
(cherry picked from commit 7da45efb09)
Despite the name, linker_file_unload() will drop a reference and return
success when the module file has dependants, i.e. it has more than one
reference. When user request to unload such modules then the kernel
should reject unambiguously and immediately.
PR: 274986
Reviewed by: dfr, dab, jhb
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D42527
(cherry picked from commit f43ff3e15c)
(cherry picked from commit f1994d1eb2)
If a string is at or near the end of an input file and the amount of
remaining data in the file is smaller than the maximum string size,
the pread(2) system call would return a short read which is treated as
an error. Instead, add a new helper function for reading a string
which permits short reads so long as the data read from the file
contains a terminated string.
Reported by: jrtc27
Reviewed by: jrtc27
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D44419
(cherry picked from commit 785600d0fb)
These are bus addresses not CPU virtual addresses.
Reviewed by: andrew
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D44343
(cherry picked from commit 66658b0f27)
Reported by: Coverity Scan
CID: 1539214
Fixes: 7485926e09 nvme: Firmware revisions in the firmware slot info logpage are ASCII strings
(cherry picked from commit 1b38f851d8)
In particular, don't try to byteswap the values as 64-bit integers and
always print a non-empty version as a string.
Reviewed by: chuck, imp
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D44121
(cherry picked from commit 7485926e09)
When a packet matches an existing dynamic rule for a keep-state rule,
the matching engine advances the "instruction pointer" to the action
portion of the rule skipping over the match conditions. However, the
code was merely breaking out of the switch statement rather than doing
a continue, so the remainder of the loop body after the switch was
still executed. If the first action opcode contains an F_NOT but not
an F_OR (such as an "untag" action), then match is toggled to 0, and
the code exits the inner loop via a break which aborts processing of
the actions.
To fix, just use a continue instead of a break.
PR: 276732
Reviewed by: jhb, ae
MFC after: 2 weeks
(cherry picked from commit 62b1faa3b7)
The #ifdef DDB code in parse_metadata was dead code without opt_ddb.h.
While here, update the call to db_fetch_ksymtab for changes in commit
02bc014a20.
Reviewed by: mhorne
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D43919
(cherry picked from commit 962b0bcbd9)
This fixes a panic if a driver uses bus_set_resource to add a resource
that fails to reserve and then deletes the resource via
bus_delete_resource.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D43891
(cherry picked from commit e05436d577)
acpi_set_resource excludes certain types of resources for certain
devices. The intention of this is to avoid adding resource entries
for bogus resources enumerated via _CRS. However, this also prevents
drivers from adding those resources explicitly if needed. To fix
this, move the logic to exclude these resources into an ignore hook
used when parsing _CRS to create the initial set of resources for each
device.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D43892
(cherry picked from commit 055c1fe230)
This is very unlikely to fail (and if it does, CAM isn't going to work
regardless), but fail with an error rather than a gauranteed panic via
NULL pointer dereference.
PR: 276770
Reported by: Qiushi <w290680224@gmail.com>
(cherry picked from commit eb86c6c5b4)
No functional change, but it is cleaner to use the existing generic
wrappers rather than KOBJ methods directly.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D43686
(cherry picked from commit 1fb5445206)
These functions are not used by pcib subclasses so do not need to
be exposed in pcib_private.h.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D43688
(cherry picked from commit 03719c6514)
The usual use case in 2024 for newfs_msdosfs is creating filesystems on SD cards
for older hardware. In most tutorials, they call the cluster size "allocation
size". Therefore, add a small note next to cluster size that it is also called
allocation size, and add an example for how to do this.
Reviewed by: jhb
Pull Request: https://github.com/freebsd/freebsd-src/pull/1045
(cherry picked from commit c8bf9f09ee)
typeof() does not exist in -std=c99 mode and the relevant #define is
only for _KERNEL, so use __typeof here instead.
Reviewed by: jhb
MFC after: 2 weeks
Pull Request: https://github.com/freebsd/freebsd-src/pull/1070
(cherry picked from commit 4261507a5e)
In 2005, Gnu find deprecated '+' as the leading character for the -perm
argument, instead preferring '/' with the same meaning. Implement that
behavior here, and document it in the man page.
Reviewed by: imp, emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/1060
(cherry picked from commit 2a121b97e9)
_Alignof(expression) is a non-standard extension. This is not allowed
in gnu11 and gnu17 which follow the C11 standard _Alignof(type).
Reviewed by: arichardson, imp, jhb
Fixes: 4a9cd9fc22 amd64 db_trace: Reject unaligned frame pointers
Fixes: 7ccaf76a27 riscv db_trace: Ensure trapframe pointer is suitably aligned.
Fixes: 638c68897f arm64 db_trace: Ensure trapframe pointer is suitably aligned.
Differential Revision: https://reviews.freebsd.org/D43409
(cherry picked from commit 03d04bf494)
* Give link(1) its own usage message.
* Use getprogname(3) instead of rolling our own.
* Verify that the target file does not already exist.
* Add tests specific to link(1).
MFC after: 3 days
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44635
(cherry picked from commit bee7cf9e97)
* When copying a directory, if the destination exists and is not a
directory, we would previously emit an error message and exit. The
correct behavior according to POSIX is to emit an error message and
continue without descending further into the source directory.
* When copying a directory, if the destination does not exist and we
fail to create it, we would previously emit an error message and
exit. The correct behavior according to POSIX is to emit an error
message and continue. Whether to descend further into the source
directory is explicitly left unspecified; GNU cp does not, which
seems to me to be the safer and less surprising option, so let's not
either.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44577
(cherry picked from commit dd286b0dc1)
cp: Correct the list of non-portable flags.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44576
(cherry picked from commit aaa1806f68)
[DSE] Remove malloc from EarliestEscapeInfo before removing. (#84157)
Not removing the malloc from earliest escape info leaves stale entries
in the cache.
Fixes https://github.com/llvm/llvm-project/issues/84051.
PR: https://github.com/llvm/llvm-project/pull/84157
This fixes a crash in clang (usually a bus error, but can also be
another memory error) when compiling the science/siconos port.
PR: 278174
Reported by: yuri
MFC after: 3 days
(cherry picked from commit aaabed1dea)
This commit reverts 8db56defa7,
rolling back the vendor import of xz 5.6.0 and restoring the
package to version 5.4.5.
The revert was not directly due to the attack (CVE-2024-3094):
our import process have removed the test cases and build scripts
that would have enabled the attack. However, reverting would
help to reduce potential confusion and false positives from
security scanners that assess risk based solely on version
numbers.
Another commit will follow to restore binary compatibility with
the liblzma 5.6.0 library by making the previously private
symbol (lzma_mt_block_size) public.
PR: 278127
(cherry picked from commit 2f9cd13d6c)
* Properly parse (no) command-line options.
* Ensure that errors go to stderr and result in a non-zero exit.
* Drop the special-case code for a single argument, as it will produce
the wrong outcome if the file does not exist or is corrupted.
* Don't print anything until after we've collected all the data.
* Always create all temporary files before setting the trap. This
ensures that the trap can safely fire at any moment, regardless of any
previous definition of `T`.
* Use a temporary file rather than a pipe between `nm` and `sed` to
ensure proper termination if `nm` fails due to a missing or invalid
input.
* The check for self-referential entries was conditional on testing our
argument list against a regex looking for archives. This was a
needless and unreliable optimization; make the check unconditional.
* Document that lorder will not work properly if any of its inputs have
spaces in their name.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44133
(cherry picked from commit 5c7b986c21)
lorder: Add unit tests.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44134
(cherry picked from commit 96da41b6db)
lorder: Undeprecate.
While lorder is not required by our current toolchain (or any toolchain
we've used in the past decade or two), it still occasionally shows up
in build systems of third party software, including The Open Group's
UNIX conformance test suite, and the maintenance cost is negligible.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: imp, allanjude, emaste
Differential Revision: https://reviews.freebsd.org/D44135
(cherry picked from commit cf4d9bf8b3)
lorder: Don't rely on legacy syntax.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44155
(cherry picked from commit aedb37dc49)
lorder: Tweak invalid file test.
Different implementations of `nm` have different ways of telling you
that your file is not a valid object or library, but they all seem to
have “not recognized” as a common substring.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44154
(cherry picked from commit aa80cfadff)
usr.bin: Make lorder conditional on MK_TOOLCHAIN.
MFC after: 1 week
Reviewed by: allanjude, markj
Differential Revision: https://reviews.freebsd.org/D44558
(cherry picked from commit 125c4560bc)