]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agolinux: make sure to zero the l_siginfo structure for ptrace(2)
Edward Tomasz Napierala [Tue, 8 Jun 2021 09:18:29 +0000 (10:18 +0100)]
linux: make sure to zero the l_siginfo structure for ptrace(2)

Reported By: dchagin
Sponsored By: EPSRC

(cherry picked from commit f102b61d0ecffc6d9cc322fa7a48e0927391421b)

2 years agonetinet: prevent NULL pointer dereference in in_aifaddr_ioctl()
Artem Khramov [Tue, 24 Aug 2021 14:26:35 +0000 (17:26 +0300)]
netinet: prevent NULL pointer dereference in in_aifaddr_ioctl()

It appears that maliciously crafted ifaliasreq can lead to NULL
pointer dereference in in_aifaddr_ioctl(). In order to replicate
that, one needs to

1. Ensure that carp(4) is not loaded

2. Issue SIOCAIFADDR call setting ifra_vhid field of the request
   to a negative value.

A repro code would look like this.

int main() {
    struct ifaliasreq req;
    struct sockaddr_in sin, mask;
    int fd, error;

    bzero(&sin, sizeof(struct sockaddr_in));
    bzero(&mask, sizeof(struct sockaddr_in));

    sin.sin_len = sizeof(struct sockaddr_in);
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = inet_addr("192.168.88.2");

    mask.sin_len = sizeof(struct sockaddr_in);
    mask.sin_family = AF_INET;
    mask.sin_addr.s_addr = inet_addr("255.255.255.0");

    fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (fd < 0)
        return (-1);

    memset(&req, 0, sizeof(struct ifaliasreq));
    strlcpy(req.ifra_name, "lo0", sizeof(req.ifra_name));
    memcpy(&req.ifra_addr, &sin, sin.sin_len);
    memcpy(&req.ifra_mask, &mask, mask.sin_len);
    req.ifra_vhid = -1;

    return ioctl(fd, SIOCAIFADDR, (char *)&req);
}

To fix, discard both positive and negative vhid values in
in_aifaddr_ioctl, if carp(4) is not loaded. This prevents NULL pointer
dereference and kernel panic.

Reviewed by: imp@
Pull Request: https://github.com/freebsd/freebsd-src/pull/530

(cherry picked from commit 620cf65c2bc4035a07e1152da419a4e60d36ff9b)

2 years agotop(1): indicate how to reset grep string
John Grafton [Tue, 7 Sep 2021 17:39:59 +0000 (13:39 -0400)]
top(1): indicate how to reset grep string

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/536/files

(cherry picked from commit 4ccbbe5f0689513de4399d6dad43e85d97ad9cde)

2 years agotop(1): support command name and argument grepping
John Grafton [Wed, 16 Jun 2021 19:40:21 +0000 (15:40 -0400)]
top(1): support command name and argument grepping

Obtained from:  OpenBSD
Reviewed by: imp@
Pull Request: https://github.com/freebsd/freebsd-src/pull/479

(cherry picked from commit a00d703f2f438b199d3933d19d535540586b7792)

2 years agoMissed line from 7af4475a6e31.
Alexander Motin [Fri, 3 Sep 2021 02:25:16 +0000 (22:25 -0400)]
Missed line from 7af4475a6e31.

MFC after: 2 weeks

(cherry picked from commit 5d9e5a7edfb5a2256be1c6433aaef32433cdd14e)

2 years agovmd(4): Major driver refactoring
Alexander Motin [Fri, 3 Sep 2021 00:58:02 +0000 (20:58 -0400)]
vmd(4): Major driver refactoring

 - Re-implement pcib interface to use standard pci bus driver on top of
vmd(4) instead of custom one.
 - Re-implement memory/bus resource allocation to properly handle even
complicated configurations.
 - Re-implement interrupt handling to evenly distribute children's MSI/
MSI-X interrupts between available vmd(4) MSI-X vectors and setup them
to be handled by standard OS mechanisms with minimal overhead, except
sharing when unavoidable.

Successfully tested on Dell XPS 13 laptop with Core i7-1185G7 CPU (VMD
device ID 0x9a0b) and single NVMe SSD, dual-booting with Windows 10.

Successfully tested on Supermicro X11DPI-NT motherboard with Xeon(R)
Gold 6242R CPUs (VMD device ID 0x201d), simultaneously handling NVMe
SSD on one PCIe port and PLX bridge with 3 NVMe and 1 AHCI SSDs on
another.  Handles SSD hot-plug (except Optane 905p for some reason,
which are not detected until manual bus rescan) and enabled IOMMU
(directly connected SSDs work, but ones connected to the PLX fail
without errors from IOMMU).

MFC after: 2 weeks
Sponsored by: iXsystems, Inc.
Differential revision: https://reviews.freebsd.org/D31762

(cherry picked from commit 7af4475a6e31202a865b1dd3727018659b44470f)

2 years agovmd_bus: Fix typo in comment
Neel Chauhan [Sat, 17 Jul 2021 21:31:57 +0000 (14:31 -0700)]
vmd_bus: Fix typo in comment

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

(cherry picked from commit 76fffd0a865374e1e09d8f61f36bfbda918da5c7)

2 years agovmd: Rename vmd_bus class to pci
Neel Chauhan [Fri, 16 Jul 2021 02:03:05 +0000 (19:03 -0700)]
vmd: Rename vmd_bus class to pci

This fixes a kernel panic when probing for vmd_bus on Intel TigerLake on
14-CURRENT. Apparently, vmd_bus is a type of PCI bus, but was registered
as a separate device class.

PR: 256915
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D31071

(cherry picked from commit ad1f608fb2f529baf028384bbe7e8fbbff5cbe23)

2 years agostand: Add MK_PIE=no to defs.mk
Warner Losh [Wed, 11 Aug 2021 16:59:28 +0000 (10:59 -0600)]
stand: Add MK_PIE=no to defs.mk

There's no need to build both pie and non-pie .o's for stand. There's
some other build thing with MK_BEAR_SSL=yes and/or MK_LOADER_VERIEXEC=yes
that causes the pie build to fail that the 'ar' stage now. Since we don't
need the PIE stuff and the non-PIE stuff, disable PIE for the boot loader.

Reviewed by: emaste
Sponsored by: Netflix

(cherry picked from commit 879675e9a0d84880cad9834e2ef98e8724c5532c)

2 years agortsx: Fix wakeup race similar to sdhci one fixed in 35547df5c786
Warner Losh [Tue, 10 Aug 2021 23:07:50 +0000 (17:07 -0600)]
rtsx: Fix wakeup race similar to sdhci one fixed in 35547df5c786

rtsx copied code from sdhci, and has the same wakeup race bug that was
fixed in 35547df5c786, so apply a similar fix here.

Sponsored by: Netflix

(cherry picked from commit 9339e7c0bd565506092bb0a2618ff32fb04bb2c4)

2 years agomk: WITH_FOO=no now generates a warning
Warner Losh [Thu, 10 Jun 2021 00:10:12 +0000 (18:10 -0600)]
mk: WITH_FOO=no now generates a warning

Many people are used to gnu configure's behavior of changing
--with-foo=no to --without-foo. At the same time, several folks have
WITH_FOO=no in their config files to enable this ironic form of the
option because of an old meme from IRC, a mailing list or the forums (I
forget which). Add a warning to allow to alert people w/o breaking POLA.

Reviewed by: allanjude, bdrewery, manu
MFC After: 2 weeks
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D30684

(cherry picked from commit f4d987cd137cb2d0d54a3e35d9258ca7c175d291)

2 years agoclock_gettime: Add Linux aliases for CLOCK_*
Warner Losh [Fri, 30 Jul 2021 23:11:43 +0000 (17:11 -0600)]
clock_gettime: Add Linux aliases for CLOCK_*

Linux standardized what we call CLOCK_{REALTIME,MONOTONIC}_FAST as
CLOCK_{REALTIME,MONOTONIC}_COARSE. In addition, Linux spells
CLOCK_UPTIME as CLOCK_BOOTTIME.

Add aliases to time.h and document these new aliases in
clock_gettime(2).

Reviewed by: vangyzen, kib (prior), dchagin (prior)
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D30988

(cherry picked from commit 155f15118a77d2aeab7b177ada78c848778d7d80)

2 years agotime.h: reduce CLOCK_ namespace pollution, move to _clock_id.h
Warner Losh [Fri, 30 Jul 2021 23:10:56 +0000 (17:10 -0600)]
time.h: reduce CLOCK_ namespace pollution, move to _clock_id.h

Attempt to comply with the strict namespace pollution requirements of
_POSIX_C_SOURCE. Add guards to limit visitbility of CLOCK_ and TIMER_
defines as appropriate. Only define the CLOCK_ variables relevant to the
specific standards. Move all the sharing to sys/_clock_id.h and make
time.h and sys/time.h both include that rather than copy due to the
now large number of clocks and compat defines.

Please note: The old time.h previously used these newer dates:
CLOCK_REALTIME 199506
CLOCK_MONOTONIC 200112
CLOCK_THREAD_CPUTIME_ID 200112
CLOCK_PROCESS_CPUTIME_ID 200112

but glibc defines all of these for 199309. glibc uses this date for all
these values, however, only CLOCK_REALTIME was in IEEE 1003.1b. Add a
comment about this to document it. A large number of programs and
libraries assume that these will be defined for _POSIX_C_SOURCE =
199309.

In addition, leak CLOCK_UPTIME_FAST for the pocl package until it can be
updated to use a simple CLOCK_MONOTONIC.

Reviewed by: kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31056

(cherry picked from commit 7b797ba27a714594dac910035d857e653d566b19)

2 years agonanobsd: adopt dhcpd to latest conventions
Warner Losh [Fri, 30 Jul 2021 22:55:43 +0000 (16:55 -0600)]
nanobsd: adopt dhcpd to latest conventions

Adopt the dhcpd build to use nanobsd-build top level directory that
other nanobsd builds are using.

Sponsored by: Netflix

(cherry picked from commit 9ed1e98abfe470a958a55b4fc6d6391ca8e4478d)

2 years agocli.lua.8: make the command match the code
Warner Losh [Thu, 29 Jul 2021 02:53:18 +0000 (20:53 -0600)]
cli.lua.8: make the command match the code

It's disable-device, not device-disable

Spotted by: jrtc27
Sponsored by: Netflix

(cherry picked from commit 6b51baf6a8de7241a4e1b0c8436d70299cd55270)

2 years agolua loader: Add disable-device to disable a device.
Warner Losh [Wed, 28 Jul 2021 22:52:38 +0000 (16:52 -0600)]
lua loader: Add disable-device to disable a device.

disable-device fooX will set hint.foo.X.disabled=1 as a way to easily
disable a device attaching during boot.

Reviewed by: tsoome
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31297

(cherry picked from commit 07c4b78d0a1d26b6441cf3e52b917f20c932b9d0)

2 years agoloader: support.4th resets the read buffer incorrectly
John Hood [Wed, 28 Jul 2021 19:43:02 +0000 (13:43 -0600)]
loader: support.4th resets the read buffer incorrectly

Large nextboot.conf files (over 80 bytes) are not read correctly by the
Forth loader, causing file parsing to abort, and nextboot configuration
fails to apply.

Simple repro:

nextboot -e foo=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shutdown -r now

That will cause the bug to cause a parse failure but shouldn't otherwise
affect the boot.  Depending on your loader configuration, you may also
have to set beastie_disable and/or reduce the number of modules loaded
to see the error on a small console screen.  12.0 or CURRENT users will
also have to explicitly use the Forth loader instead of the Lua loader.
The error will look something like:

Warning: syntax error on file /boot/loader.conf.local
foo="xxxxxxxxxxxxxxnextboot_enable="YES"
                                    ^
/boot/support.4th has crude file I/O buffering, which uses a buffer
'read_buffer', defined to be 80 bytes by the 'read_buffer_size'
constant.  The loader first tastes nextboot.conf, reading and parsing
the first line in it for nextboot_enable="YES".  If this is true, then
it reopens the file and parses it like other loader .conf files.

Unfortunately, the file I/O buffering code does not fully reset the
buffer state in the reset_line_reading word.  If the last file was read
to the end, that doesn't matter; the file buffer is treated as empty
anyway.  But in the nextboot.conf case, the loader will not read to the
end of file if it is over 80 bytes, and the file buffer may be reused
when reading the next file.  When the file is reread, the corrupt text
may cause file parsing to abort on bad syntax (if the corrupt line has
<>2 quotes in it), the wrong variable to be set, no variable to be set
at all, or (if the splice happens to land at a line ending) something
approximating normal operation.

The bug is very old, dating back to at least 2000 if not before, and is
still present in 12.0 and CURRENT r345863 (though it is now hidden by
the Lua loader by default).

Suggested one-line attached.  This does change the behavior of the
reset_line_reading word, which is exported in the line-reading
dictionary (though the export is not documented in loader man pages).
But repo history shows it was probably exported for the PNP support
code, which was never included in the loader build, and was removed 5
months ago.

One thing that puzzles me: how has this bug gone unnoticed/unfixed for
nearly 2 decades?  I find it hard to believe that nobody's tried to do
something interesting with nextboot, like load a kernel and filesystem,
which is what I'm doing.

Tested by: Gary Jennejohn
PR: 239315
MFC After: 3 weeks
Reviewed by: imp (and correctly applied this time)
Differential Revision: https://reviews.freebsd.org/D31328

(cherry picked from commit dbdf2b52f59df7374eb1f799b4df1b54e4502e40)

2 years agogenoffset: simplify and rewrite in sh
Warner Losh [Wed, 28 Jul 2021 19:47:05 +0000 (13:47 -0600)]
genoffset: simplify and rewrite in sh

genoffset used the fully generic ASSYM macro to generate the offsets
needed for the thread_lite structure. However, since these are offsets
into a structure, they will always be necessarily small and positive. As
such, just create a simple character array of the right size and use a
naming convention such that we can recover the field name, structure
name and type. Use nm -t d and sort -n to sort these into order, then
loop over the resutls to generate the thread_lite structure.

MFC After: 2 weeks
Reviewed by: kib, markj (earlier versions)
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31203

(cherry picked from commit 824897a3aea5ca22db8cb7d5b404697a1de1210a)

2 years agogenassym.sh: Fix two minor issues found by shellcheck
Warner Losh [Wed, 28 Jul 2021 19:42:29 +0000 (13:42 -0600)]
genassym.sh: Fix two minor issues found by shellcheck

o Remove redunant $ in $(( )) expression.
o Quote arg passed to work so paths with spaces, etc will work.

MFC After: 2 weeks
Reviewed by: kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31335

(cherry picked from commit 46dd3ef0338ba2ad24d05bab2a614410cf17b017)

2 years agodevctl: don't publish the mount options
Warner Losh [Sat, 24 Jul 2021 15:03:53 +0000 (09:03 -0600)]
devctl: don't publish the mount options

Mount options aren't solely ASCII strings. In addition, experience to
date suggests that the mount options are much less useful than was
originally supposed and the mount flags suffice to make decisions. Drop
the reporting of options for the mount/remount/unmount events.

Reviewed by: markj
Reported by: KASAN
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31287

(cherry picked from commit 6475667f7b72f5eb8fcd045967c251e45e38e2a2)

2 years agogeom_disk: use a preallocated geom_event for disk destruction.
Warner Losh [Fri, 23 Jul 2021 21:21:02 +0000 (15:21 -0600)]
geom_disk: use a preallocated geom_event for disk destruction.

Preallocate a geom_event (using the new geom_alloc_event) when we create
a disk. When we create the disk, we're going to be in a sleepable
context, so we can always allocate this extra bit of memory. Then use
this preallocated memory to free the disk. CAM can try to free the disk
from an unsleepable context if there was I/O outstanding when the disk
was destroyted (say because the SIM said it had gone away). The I/O
context isn't sleepable. Rather than trying to invent a retry mechanism
and making sure all the other geom_disk consumers did it properly,
preallocating the event ensure that the geom_disk will be properly torn
down, even when there's memory pressure when the disk departs.

Reviewd by: jhb
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D30544

(cherry picked from commit 47aeda7b70555049eccd7f020365aec031f41c62)

2 years agogeom: create an API to allocate events, and use that storage to send them
Warner Losh [Fri, 23 Jul 2021 21:16:57 +0000 (15:16 -0600)]
geom: create an API to allocate events, and use that storage to send them

g_alloc_event will allocate storage for an opaque event. g_post_event_ep
can use memory returned by g_alloc_event to send an event from a context
that might not be able to allocate the event. Occasionally, we can
alloate memory when we create an object, but not while we're destroy
it. This allows one to allocate at creation time memory to use when
destorying the object.

Reviewed by: jhb
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D30544

(cherry picked from commit 380710a5c8c1fd638ec961351b75b667e91667c9)

2 years agokqueue: drain kqueue taskqueue if syscall tickled it
Konstantin Belousov [Mon, 6 Sep 2021 11:43:06 +0000 (14:43 +0300)]
kqueue: drain kqueue taskqueue if syscall tickled it

PR: 258310

(cherry picked from commit 98168a6e6c12dab8f608f6b5f5b0b175d2b87ef0)

2 years agolualoader: use more concise verbiage for autoboot
Kyle Evans [Wed, 8 Sep 2021 21:34:33 +0000 (16:34 -0500)]
lualoader: use more concise verbiage for autoboot

The behavior remains the same, but lualoader now uses the more concise
verbiage that forthloader used.  This is particularly important because
the previous line would exceed the right boundary of the menu and run
straight into space that would typically be allowed for the logo.

This makes it slightly easier to port logos from forthloader to
lualoader.

(cherry picked from commit ed107537b43cabf7a18e73a17856a9d9e170c6e9)

2 years agolualoader: allow brands to specify a shift
Kyle Evans [Wed, 8 Sep 2021 21:33:28 +0000 (16:33 -0500)]
lualoader: allow brands to specify a shift

Some brands will want to specify a shift to make sure they're properly
centered; let it happen.

(cherry picked from commit e19d9a9b6e44e15087a140a26ab3e24b07f6ba56)

2 years agolualoader: remove shadowed local from graphics:drawitem()
Kyle Evans [Wed, 8 Sep 2021 21:32:53 +0000 (16:32 -0500)]
lualoader: remove shadowed local from graphics:drawitem()

for loop vars are local already and distinct from this earlier
declaration; remove it.

(cherry picked from commit 763bcebe0b6d5e53e5c8940a677de662e5652b6d)

2 years agoAdd support for recording EC2 AMI Ids in SSM
Colin Percival [Fri, 27 Aug 2021 00:54:53 +0000 (17:54 -0700)]
Add support for recording EC2 AMI Ids in SSM

If SSMPREFIX is specified, AMI Ids will be recorded in the SSM
Parameter Store under the name
  ${SSMPREFIX}/${ARCH}/${FLAVOUR}/${ROOTFS}/${REVISION}/${BRANCH}
where ARCH is "amd64" or "arm64", FLAVOUR is "base" (but may have
other options in the future), ROOTFS is "ufs" (but may have other
options in the future), and REVISION and BRANCH have their normal
meanings.

FreeBSD will be using the public prefix "/aws/service/freebsd",
resulting in SSM Parameter names which look like
  /aws/service/freebsd/amd64/base/ufs/14.0/CURRENT

Relnotes: yes
Sponsored by: https://patreon.com/cperciva
MFC after: 2 weeks

(cherry picked from commit c5af0ac1a732491aab789dda0da368ff48497871)

2 years agoEC2: Tell gptboot to skip its 3 second wait
Colin Percival [Mon, 21 Jun 2021 22:35:16 +0000 (15:35 -0700)]
EC2: Tell gptboot to skip its 3 second wait

Nobody is going to hit a key to tell gptboot to select another disk,
so there's no point waiting.

(cherry picked from commit 524260db7683681c7deec9f1968c15a717317685)

2 years agopf: ensure states passed to pf_free_state() are always unlinked
Kristof Provost [Fri, 3 Sep 2021 07:36:19 +0000 (09:36 +0200)]
pf: ensure states passed to pf_free_state() are always unlinked

In pf_create_state() we can end up deleting the state immediately. This
can happen if we fail to map the relevant addresses or fail
normalization or fail to insert it into the state table.
If that happens we delete the state again with pf_free_state(). However,
this asserts that the state must be unlinked.

It's correct to simply set the state to PFTM_UNLINKED because we've not
yet linked it.

Submitted by: Mateusz Guzik <mjg@FreeBSD.org>
Reviewed by: scottl
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D31752

(cherry picked from commit a0c64a443e4cae67a5eea3a61a47d746866de3ee)

2 years agodtrace: fix ipfw_rule_info_t translator
Andrey V. Elsukov [Thu, 2 Sep 2021 13:35:01 +0000 (16:35 +0300)]
dtrace: fix ipfw_rule_info_t translator

322e5efda8578b has changed field names in the struct ip_fw.
Use correct names in ipfw_rule_info_t translator in the ipfw.d script.

Reported by: Keith White <kwhite uottawa at gmail>

(cherry picked from commit 5c8e8e82aeaf3aa788acdd6cfca30ef09094230d)

2 years agolibarchive: import bugfix from upstream
Martin Matuska [Fri, 27 Aug 2021 10:51:01 +0000 (12:51 +0200)]
libarchive: import bugfix from upstream

Reworked bugfix for upstream issue #1566:
  Do not follow symlinks when processing the fixup list

(cherry picked from commit c577bdfce6b4451ab897bfe5013543e78a7f9b62)

2 years agolibarchive: import changes from upstream
Martin Matuska [Mon, 23 Aug 2021 00:54:15 +0000 (02:54 +0200)]
libarchive: import changes from upstream

Libarchive 3.5.2

New features:
  PR #1502: Support for PWB and v7 binary cpio formats
  PR #1509: Support of deflate algorithm in symbolic link decompression
            for ZIP archives

Important bugfixes:
  IS #1044: fix extraction of hardlinks to symlinks
  PR #1480: Fix truncation of size values during 7zip archive
            extraction on 32bit architectures
  PR #1504: fix rar header skiming
  PR #1514: ZIP excessive disk read - fix location of central directory
  PR #1520: fix double-free in CAB reader
  PR #1521: Fixed leak of rar before ending with error
  PR #1530: Handle short writes from archive_write_callback
  PR #1532: 7zip: Use compression settings from file also for file header
  IS #1566: do not follow symlinks when processing the fixup list

Relnotes: yes

(cherry picked from commit ddce862ad8594542e1fa1af9ffae7264e12ffd27)

2 years agoloader.efi: fix console output after BS off
Toomas Soome [Thu, 2 Sep 2021 21:17:32 +0000 (00:17 +0300)]
loader.efi: fix console output after BS off

When Boot Services (BS) are switched off, we can not use BS
functions any more. Since drawn console does implement our own
Blt(), we can use it to draw the console.

However, SimpleTextOutput protocol based console output must be
blocked.

Tested by inserting printf() after ExitBootServices() call.

(cherry picked from commit 4c7a3a70e047fbba2a3ce4a0168eaf2baddca76b)

2 years agocluster_write(): do not access buffer after it is released
Konstantin Belousov [Thu, 2 Sep 2021 04:04:23 +0000 (07:04 +0300)]
cluster_write(): do not access buffer after it is released

(cherry picked from commit 5cc82c563eda97b70120f06e9635ab6c1c24fecd)

2 years agoopenssh: regenerate freebsd-namespace.h
Ed Maste [Thu, 2 Sep 2021 01:54:57 +0000 (21:54 -0400)]
openssh: regenerate freebsd-namespace.h

For some reason poly64 was omitted when this file was last generated
(perhaps it was inlined by the Clang version then in use).

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit c7b4c21ee4615e2e418ab520abf6c026d6dae398)

2 years agoopenssh: disable libwrap (TCP wrappers) at configure time
Ed Maste [Thu, 2 Sep 2021 00:30:05 +0000 (20:30 -0400)]
openssh: disable libwrap (TCP wrappers) at configure time

We define LIBWRAP at build time in secure/usr.sbin/sshd/Makefile if
WITH_TCPWRAPPERS is in effect, so it should not be set in config.h.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 36cd1e5e8c216e0f67832d59d629f2910a02d4fc)

2 years agoopenssh: clarify krb5 use in freebsd-configure
Ed Maste [Thu, 2 Sep 2021 00:23:40 +0000 (20:23 -0400)]
openssh: clarify krb5 use in freebsd-configure

freebsd-configure.sh runs configure twice, --with-kerberos5 and
--without-kerberos5, in order to build a config.h that defaults to
kerberos5 disabled, and a small config file that represents the
differences.

Rename config.h.orig to config.h.kerberos5 to clarify the intent of this
script.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 5e4dd21fd60958ceef4e4fd14b000844b957287e)

2 years agoopenssh: tag generated file with @generated
Ed Maste [Thu, 2 Sep 2021 01:49:44 +0000 (21:49 -0400)]
openssh: tag generated file with @generated

Tools like Phabricator use the @generated tag to identify files that
may be excluded from review by default.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit b3e858f7622e7fb058c05f81abd657fc47c6f717)

2 years agollvm: Revert "[HardwareLoops] Change order of SCEV expression construction for InitLo...
Alfredo Dal'Ava Junior [Thu, 2 Sep 2021 17:54:31 +0000 (14:54 -0300)]
llvm: Revert "[HardwareLoops] Change order of SCEV expression construction for InitLoopCount."

Reverts llvm commit 42eaf4fe0adef3344adfd9fbccd49f325cb549ef, pointed
from bisect as source of regression that causes liblzma to compress/
uncompress incorrectly. It's know to affect powerpc64 BE only.

The patch unbreaks FreeBSD powerpc64 installation media, since
bsdinstall can't uncompress the *.txz produced by FreeBSD CI. It's
probably miscompiling other software bas well.

Upstream PR: https://bugs.llvm.org/show_bug.cgi?id=51714

Reviewed by: dim
MFC after: 2 days
Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision: https://reviews.freebsd.org/D31804

(cherry picked from commit f21fcae487026987f44154de981c03b69efbc945)

2 years agosctp: Implement sctp_inpcb_bind_locked()
Mark Johnston [Wed, 1 Sep 2021 14:04:47 +0000 (10:04 -0400)]
sctp: Implement sctp_inpcb_bind_locked()

This will be used by sctp_listen() to avoid dropping locks when
performing an implicit bind.  No functional change intended.

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 457abbb85794ad8b28d11a7cd44260eabdf3114d)

2 years agosctp: Release the socket reference when detaching an association
Mark Johnston [Wed, 1 Sep 2021 14:27:31 +0000 (10:27 -0400)]
sctp: Release the socket reference when detaching an association

Later in sctp_free_assoc(), when we clean up chunk lists,
sctp_free_spbufspace() is used to reset the byte count in the socket
send buffer.  However, if the PCB is going away, the socket may already
have been detached from the PCB, in which case this becomes a use-after
free.  Clear the socket reference from the association before detaching
it from the PCB, if the PCB has already lost its socket reference.

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 65f30a39e11bbbab927dbd2ca8de5ec5fc6af7ca)

2 years agosctp: Hold association locks across socket wakeups when freeing
Mark Johnston [Wed, 1 Sep 2021 14:27:51 +0000 (10:27 -0400)]
sctp: Hold association locks across socket wakeups when freeing

At this point we do not hold the inpcb lock, so the only thing holding
the socket reference live is the TCB lock, which needs to be acquired by
sctp_inpcb_free() in order to destroy associations.  Defer the unlock to
until after we dereference the socket reference.

Reported by: syzbot+1d0f2c4675de76a4cf1e@syzkaller.appspotmail.com
Reported by: syzbot+fabee77954fe69d3a5ad@syzkaller.appspotmail.com
Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit d35be50f57797a400ff68a37777405029bf9730a)

2 years agosctp: Add macros to assert on inp info lock state
Mark Johnston [Wed, 1 Sep 2021 14:06:02 +0000 (10:06 -0400)]
sctp: Add macros to assert on inp info lock state

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit be8ee77e9edcb0bc8f94cb8695fc7fb49cc0a282)

2 years agokevent: Fix races between timer detach and kqtimer_proc_continue()
Mark Johnston [Wed, 1 Sep 2021 18:18:58 +0000 (14:18 -0400)]
kevent: Fix races between timer detach and kqtimer_proc_continue()

- When detaching a knote, we need to double check the enqueued flag
  after acquiring the process lock, as kqtimer_proc_continue() may have
  toggled it.
- kqtimer_proc_continue() could in principle reschedule a stopped
  callout after filt_timerdetach() drains the callout.  So, we need to
  re-check.

Reported by: syzbot+4a4cebb3ec07892cb040@syzkaller.appspotmail.com
Reported by: syzbot+a9c04bc76078a3b7dd8d@syzkaller.appspotmail.com
Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit c511383de7a0325a80b9c5d2b8678b438db146dc)

2 years agopfctl: print counters in decimal
Kristof Provost [Sat, 4 Sep 2021 14:07:59 +0000 (16:07 +0200)]
pfctl: print counters in decimal

795d78a46713 pfctl: Don't use PRIu64 mistakenly changed these to be
printed as hexadecimal numbers.

Reported by: Florian Smeets
MFC after: 4 days
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 846a6e8f9ab25df4e06d28c05fb66060d803c9ba)

2 years agopfctl: Don't use PRIu64
Kristof Provost [Wed, 1 Sep 2021 16:18:26 +0000 (18:18 +0200)]
pfctl: Don't use PRIu64

Rather than PRIu64 we can just treat the data as uintmax_t, and use %jx
instead.

MFC after: 1 week
Suggested by: kib
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 795d78a46713fc16153966e77f20da2f40aac2a3)

2 years agopf: import pf_set_protostate() from OpenBSD
Kristof Provost [Tue, 20 Jul 2021 16:38:16 +0000 (18:38 +0200)]
pf: import pf_set_protostate() from OpenBSD

to change a state's state (that term is overloaded in pf, protocol state
like ESTABLISHED for tcp here), don't do it directly, but go through a newly
introduced pf_set_protostate()

Reviewed by: kbowling
Obtainted from: OpenBSD
MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31729

(cherry picked from commit ce3ea45047c7321bcfcf0cd31272f0e4359640f2)

2 years agopf: Add counters for syncookies
Kristof Provost [Sun, 29 Aug 2021 13:54:50 +0000 (15:54 +0200)]
pf: Add counters for syncookies

Count when we send a syncookie, receive a valid syncookie or detect a
synflood.

Reviewed by: kbowling
MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31713

(cherry picked from commit 4cab80a8dfecdf16333a1113513e046b9f4dd7f6)

2 years agowsp(4): Add evdev support.
Vladimir Kondratyev [Tue, 24 Aug 2021 23:01:42 +0000 (02:01 +0300)]
wsp(4): Add evdev support.

Reviewed by: hselasky
Tested by: Greg V, Constantin Furst<constantin_AT_fuersten_DOT_info>
PR: 252236
Differential revision: https://reviews.freebsd.org/D31653

(cherry picked from commit 8d73071c47ff1f911bdaec6356f37feb4e3b7cb5)

2 years agowsp(4): Compact parameter structure.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:59:48 +0000 (01:59 +0300)]
wsp(4): Compact parameter structure.

(cherry picked from commit 250ab004074df27372b9afb18003c1e39d79aff5)

2 years agoatp(4), wsp(4): Return correct priority from probe() method;
Vladimir Kondratyev [Tue, 24 Aug 2021 22:59:17 +0000 (01:59 +0300)]
atp(4), wsp(4): Return correct priority from probe() method;

(cherry picked from commit 9fa1201d60dc7004f11d950f0fbd277bdcdcaf2d)

2 years agoevdev: Add support for automatic MT protocol type A to type B conversion.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:53:56 +0000 (01:53 +0300)]
evdev: Add support for automatic MT protocol type A to type B conversion.

(cherry picked from commit d056693d7bc6c1b5f2c1612e5b34807f173e21c7)

2 years agoevdev: Add implicit mode for touch tracking.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:52:37 +0000 (01:52 +0300)]
evdev: Add implicit mode for touch tracking.

In implicit mode assignment of slot number and tracking id is performed
automatically on each synchronization requested by device driver.

This is done with creation of intermediate buffer for multitouch events.
This buffer holds untracked events until synchronization is requested by
device driver. It is needed as touch assigment requires
knowledges of all touch positions pushed in current and previous reports.

(cherry picked from commit f76051c7dabe952b75127a8031d87d78b603be20)

2 years agoevdev: Import support for touch-tracking.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:50:53 +0000 (01:50 +0300)]
evdev: Import support for touch-tracking.

Touch tracking is a process of assignment of unique trackingID to each
initiated contact on the surface.  Keeping the trackingIDs persistent
across multitouch reports requires solving of so called Euclidian
Bipartite Matching problem.

This commit imports EBM-solver implementation based on Dinitz-Kronrod
algorithm to find minimum cost matching between contacts listed in two
consecutive reports.

Obtained from: OpenBSD

(cherry picked from commit 4c0a134e32a7f4dec556fea15c8de22f69864492)

2 years agoevdev: Make MT tracking IDs monotonically increasing sequence.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:48:33 +0000 (01:48 +0300)]
evdev: Make MT tracking IDs monotonically increasing sequence.

(cherry picked from commit 66bd52f5e241bd2548015f847f12cdff69176c40)

2 years agoevdev: Give short aliases to items of evdev_mt_slot array
Vladimir Kondratyev [Tue, 24 Aug 2021 22:47:34 +0000 (01:47 +0300)]
evdev: Give short aliases to items of evdev_mt_slot array

with using of unioned anonymous structure.

Access to the same data by using different members of union generally
works despite it is not supported by C specs.

Also add helper function to report entire slot state.

(cherry picked from commit 059360287e3344f48f5a7839e2d6d54016b18b19)

2 years agoevdev: Normalize width and pressure of single touch compat events
Vladimir Kondratyev [Tue, 24 Aug 2021 22:46:49 +0000 (01:46 +0300)]
evdev: Normalize width and pressure of single touch compat events

to match Synaptics touchpad reporting range.

(cherry picked from commit 127e54deb6d8899e1dc1bc6251d512e19f21b0f1)

2 years agoevdev: force no fuzz for autogenerated single touch compat events.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:45:50 +0000 (01:45 +0300)]
evdev: force no fuzz for autogenerated single touch compat events.

As fuzz has already been applied on multitouch event processing.
This allows to remove existing workaround for double fuzz procesing.

(cherry picked from commit 314913ed7c6e6e1b7c80a1063620f478961419b7)

2 years agoevdev: Send first active rather than 0-th slot state as ST report
Vladimir Kondratyev [Tue, 24 Aug 2021 22:45:16 +0000 (01:45 +0300)]
evdev: Send first active rather than 0-th slot state as ST report

(cherry picked from commit fbe17f9017e785dd564ce7fc5553a9136d3a0b03)

2 years agoevdev: Use bitsets to track active touches and slots changed in current report
Vladimir Kondratyev [Tue, 24 Aug 2021 22:44:36 +0000 (01:44 +0300)]
evdev: Use bitsets to track active touches and slots changed in current report

Obtained from: OpenBSD

(cherry picked from commit 2dc7188e532f0147b36a44ce5c033d9f59cbd9f4)

2 years agoevdev: Multitouch code style changes.
Vladimir Kondratyev [Tue, 24 Aug 2021 22:43:41 +0000 (01:43 +0300)]
evdev: Multitouch code style changes.

1. Move touch count reporting helpers to utils. They are not multitouch.
2. Use evdev_mt prefix for private multitouch support routines.
3. Use int instead of int32_t where fixed size is not required.
4. Export some internal functions.

This change should be no-op.

(cherry picked from commit 98a7606b85e05132f328a2498dccab78df31cb7e)

2 years agorouting: Bring back the ability to specify transmit interface via its name.
Alexander V. Chernikov [Sun, 29 Aug 2021 19:51:28 +0000 (19:51 +0000)]
routing: Bring back the ability to specify transmit interface via its name.

Some software references outgoing interfaces by specifying name instead of
 index.

Use rti_ifp from rt_addrinfo if provided instead of always using
 address interface when constructing nexthop.

PR:  255678
Reported by: martin.larsson2 at gmail.com

(cherry picked from commit d98954e229812eee2fa6bf97714fecbbdcc56e4c)

2 years agorouting: Allow using IPv6 next-hops for IPv4 routes (RFC 5549).
Zhenlei Huang [Sun, 22 Aug 2021 22:28:47 +0000 (22:28 +0000)]
routing: Allow using IPv6 next-hops for IPv4 routes (RFC 5549).

Implement kernel support for RFC 5549/8950.

* Relax control plane restrictions and allow specifying IPv6 gateways
 for IPv4 routes. This behavior is controlled by the
 net.route.rib_route_ipv6_nexthop sysctl (on by default).

* Always pass final destination in ro->ro_dst in ip_forward().

* Use ro->ro_dst to exract packet family inside if_output() routines.
 Consistently use RO_GET_FAMILY() macro to handle ro=NULL case.

* Pass extracted family to nd6_resolve() to get the LLE with proper encap.
 It leverages recent lltable changes committed in c541bd368f86.

Presence of the functionality can be checked using ipv4_rfc5549_support feature(3).
Example usage:
  route add -net 192.0.0.0/24 -inet6 fe80::5054:ff:fe14:e319%vtnet0

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

(cherry picked from commit 62e1a437f3285e785d9b35a476d36a469a90028d)

2 years agorouting: Disallow zero nexthop weights in nexthop groups.
Alexander V. Chernikov [Mon, 30 Aug 2021 21:49:00 +0000 (21:49 +0000)]
routing: Disallow zero nexthop weights in nexthop groups.

Adding such nexthops breaks calc_min_mpath_slots() assumptions,
 thus resulting in the incorrect nexthop group creation and
 eventually leading to panic.
Reported by: avg

(cherry picked from commit 0a3a377aee9bb28546fd2d1e45baa3fcad02439b)

2 years agorouting: simplify malloc flags in alloc_nhgrp().
Alexander V. Chernikov [Tue, 31 Aug 2021 08:12:54 +0000 (08:12 +0000)]
routing: simplify malloc flags in alloc_nhgrp().

(cherry picked from commit 639d7abec6cd31db9d240d6439fe6098b19eb3d8)

2 years agorouting: Fix newly-added rt_get_inet[6]_parent() api.
Alexander V. Chernikov [Mon, 30 Aug 2021 21:10:37 +0000 (21:10 +0000)]
routing: Fix newly-added rt_get_inet[6]_parent() api.

Correctly handle the case when no default route is present.

Reported by: Konrad <konrad.kreciwilk at korbank.pl>

(cherry picked from commit f84c30106e8b725774b4e9a32c8dd11c90da8c25)

2 years agolltable: fix crash introduced in c541bd368f86.
Alexander V. Chernikov [Sun, 22 Aug 2021 08:47:49 +0000 (08:47 +0000)]
lltable: fix crash introduced in c541bd368f86.

Reported by: cy

(cherry picked from commit f8c1b1a9296696f70ac209612a00ae0722d07ed9)

2 years agolltable: Add support for "child" LLEs holding encap for IPv4oIPv6 entries.
Alexander V. Chernikov [Sat, 21 Aug 2021 14:13:32 +0000 (14:13 +0000)]
lltable: Add support for "child" LLEs holding encap for IPv4oIPv6 entries.

Currently we use pre-calculated headers inside LLE entries as prepend data
 for `if_output` functions. Using these headers allows saving some
 CPU cycles/memory accesses on the fast path.

However, this approach makes adding L2 header for IPv4 traffic with IPv6
 nexthops more complex, as it is not possible to store multiple
 pre-calculated headers inside lle. Additionally, the solution space is
 limited by the fact that PCB caching saves LLEs in addition to the nexthop.

Thus, add support for creating special "child" LLEs for the purpose of holding
 custom family encaps and store mbufs pending resolution. To simplify handling
 of those LLEs, store them in a linked-list inside a "parent" (e.g. normal) LLE.
 Such LLEs are not visible when iterating LLE table. Their lifecycle is bound
 to the "parent" LLE - it is not possible to delete "child" when parent is alive.
 Furthermore, "child" LLEs are static (RTF_STATIC), avoding complex state
 machine used by the standard LLEs.

nd6_lookup() and nd6_resolve() now accepts an additional argument, family,
 allowing to return such child LLEs. This change uses `LLE_SF()` macro which
 packs family and flags in a single int field. This is done to simplify merging
 back to stable/. Once this code lands, most of the cases will be converted to
 use a dedicated `family` parameter.

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

(cherry picked from commit c541bd368f863bbf5c08dd5c1ecce0166ad47389)

2 years agorouting: Fix crashes with dpdk_lpm[46] algo.
Alexander V. Chernikov [Sun, 15 Aug 2021 22:25:21 +0000 (22:25 +0000)]
routing: Fix crashes with dpdk_lpm[46] algo.

When a prefix gets deleted from the RIB, dpdk_lpm algo needs to know
 the nexthop of the "parent" prefix to update its internal state.
The glue code, which utilises RIB as a backing route store, uses
 fib[46]_lookup_rt() for the prefix destination after its deletion
 to fetch the desired nexthop.
This approach does not work when deleting less-specific prefixes
 with most-specific ones are still present. For example, if
 10.0.0.0/24, 10.0.0.0/23 and 10.0.0.0/22 exist in RIB, deleting
 10.0.0.0/23 would result in 10.0.0.0/24 being returned as a search
 result instead of 10.0.0.0/22. This, in turn, results in the failed
 datastructure update: part of the deleted /23 prefix will still
 contain the reference to an old nexthop. This leads to the
 use-after-free behaviour, ending with the eventual crashes.

Fix the logic flaw by properly fetching the prefix "parent" via
 newly-created rt_get_inet[6]_parent() helpers.

Differential Revision: https://reviews.freebsd.org/D31546
PR: 256882,256833

(cherry picked from commit 36e15b717eec80047fe7442898b5752101f2fbca)

2 years agorouting: add IPv6 fib validation procedure.
Alexander V. Chernikov [Mon, 16 Aug 2021 23:02:29 +0000 (23:02 +0000)]
routing: add IPv6 fib validation procedure.

Allow consistency validation of the inet6 fib based on rib data.
Validation can be kicked off by loading test_lookup module and
 running sysctl net.route.test.run_inet6_scan=1

(cherry picked from commit cbfba56c45ab77303a3e25a82cf750043849760b)

2 years agorouting: Use process fib instead of fib 0 when conducting tests.
Alexander V. Chernikov [Sun, 15 Aug 2021 22:05:41 +0000 (22:05 +0000)]
routing: Use process fib instead of fib 0 when conducting tests.

* Allow to do validation/performance tests by using process
 fib instead of default fib 0.
* Print all validation errors instead of just the first one.

(cherry picked from commit 4a77a9b6491093b9a8bb786a861ed74ddf156e8e)

2 years agoSimplify nhop operations in ip_output().
Alexander V. Chernikov [Sat, 7 Aug 2021 11:18:02 +0000 (11:18 +0000)]
Simplify nhop operations in ip_output().

Consistently use `nh` instead of always dereferencing
 ro->ro_nh inside the if block.
Always use nexthop mtu, as it provides guarantee that mtu is accurate.
Pass `nh` pointer to rt_update_ro_flags() to allow upcoming uses
 of updating ro flags based on different nexthop.

Differential Revision: https://reviews.freebsd.org/D31451
Reviewed by: kp

(cherry picked from commit 9748eb742791dcfbb6496dc5c7c72c9283759baf)

2 years ago[lltable] Restructure nd6 code.
Alexander V. Chernikov [Fri, 6 Aug 2021 08:27:22 +0000 (08:27 +0000)]
[lltable] Restructure nd6 code.

Factor out lltable locking logic from lltable_try_set_entry_addr()
 into a separate lltable_acquire_wlock(), so the latter can be used
 in other parts of the code w/o duplication.

Create nd6_try_set_entry_addr() to avoid code duplication in nd6.c
 and nd6_nbr.c.

Move lle creation logic from nd6_resolve_slow() into a separate
 nd6_get_llentry() to simplify the former.

These changes serve as a pre-requisite for implementing
 RFC8950 (IPv4 prefixes with IPv6 nexthops).

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

(cherry picked from commit 0b79b007ebfc250a8a7b928df268ada6f1c988c4)

2 years agoUse lltable calculated header when sending lle holdchain after successful lle resolution.
Alexander V. Chernikov [Mon, 2 Aug 2021 23:16:48 +0000 (23:16 +0000)]
Use lltable calculated header when sending lle holdchain after successful lle resolution.

Subscribers: imp, ae, bz

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

(cherry picked from commit 8482aa77481a1576df7a19dbeaccb91243fbb2a3)

2 years ago[lltable] Unify datapath feedback mechamism.
Alexander V. Chernikov [Mon, 2 Aug 2021 22:39:00 +0000 (22:39 +0000)]
[lltable] Unify datapath feedback mechamism.

Use newly-create llentry_request_feedback(),
 llentry_mark_used() and llentry_get_hittime() to
 request datapatch usage check and fetch the results
 in the same fashion both in IPv4 and IPv6.

While here, simplify llentry_provide_feedback() wrapper
 by eliminating 1 condition check.

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

(cherry picked from commit f3a3b061216936b6233d1624dfdba03240d7c045)

2 years agoFix typo in rib_unsibscribe<_locked>().
Alexander V. Chernikov [Sun, 1 Aug 2021 13:28:41 +0000 (13:28 +0000)]
Fix typo in rib_unsibscribe<_locked>().

Submitted by: Zhenlei Huang<zlei.huang at gmail.com>
Differential Revision: https://reviews.freebsd.org/D31356

(cherry picked from commit 5b42b494d54365254176dd0ef688cd96edabe657)

2 years ago[netflow] fix gateway reporting in ng_netflow
Alexander V. Chernikov [Sun, 30 May 2021 10:11:08 +0000 (10:11 +0000)]
[netflow] fix gateway reporting in ng_netflow

Reported by: Guy Yur <guyyur at gmail.com>

(cherry picked from commit 8e55a80e0cc53002979f04a2504d2167267db3c2)

2 years agoEnforce check for using the return result for ifa?_try_ref().
Alexander V. Chernikov [Tue, 30 Mar 2021 14:03:28 +0000 (15:03 +0100)]
Enforce check for using the return result for ifa?_try_ref().

Suggested by: hps
Differential Revision: https://reviews.freebsd.org/D29504

(cherry picked from commit 9e5243d7b65939c3d3dbf844616084e9580876dd)

2 years agoRename variables inside nexhtop group consider_resize() code.
Alexander V. Chernikov [Mon, 29 Mar 2021 23:06:13 +0000 (23:06 +0000)]
Rename variables inside nexhtop group consider_resize() code.

No functional changes.

(cherry picked from commit 0f30a36dedef43781f5003bdfcb4254d310f02e4)

2 years agoSimplify ifa/ifp refcounting in the routing stack.
Alexander V. Chernikov [Mon, 22 Feb 2021 21:42:27 +0000 (21:42 +0000)]
Simplify ifa/ifp refcounting in the routing stack.

The routing stack control depends on quite a tree of functions to
 determine the proper attributes of a route such as a source address (ifa)
 or transmit ifp of a route.

When actually inserting a route, the stack needs to ensure that ifa and ifp
 points to the entities that are still valid.
Validity means slightly more than just pointer validity - stack need guarantee
 that the provided objects are not scheduled for deletion.

Currently, callers either ignore it (most ifp parts, historically) or try to
 use refcounting (ifa parts). Even in case of ifa refcounting it's not always
 implemented in fully-safe manner. For example, some codepaths inside
 rt_getifa_fib() are referencing ifa while not holding any locks, resulting in
 possibility of referencing scheduled-for-deletion ifa.

Instead of trying to fix all of the callers by enforcing proper refcounting,
 switch to a different model.
As the rib_action() already requires epoch, do not require any stability guarantees
 other than the epoch-provided one.
Use newly-added conditional versions of the refcounting functions
 (ifa_try_ref(), if_try_ref()) and fail if any of these fails.

Reviewed by: donner
Differential Revision: https://reviews.freebsd.org/D28837

(cherry picked from commit 596417283722ee62ed17aed1c875ad90c01cbb0e)

2 years agoAdd if_try_ref() to simplify refcount handling inside epoch.
Alexander V. Chernikov [Mon, 22 Feb 2021 21:37:55 +0000 (21:37 +0000)]
Add if_try_ref() to simplify refcount handling inside epoch.

When we have an ifp pointer and the code is running inside epoch,
 epoch guarantees the pointer will not be freed.
However, the following case can still happen:

* in thread 1 we drop to refcount=0 for ifp and schedule its deletion.
* in thread 2 we use this ifp and reference it
* destroy callout kicks in
* unhappy user reports a bug

This can happen with the current implementation of ifnet_byindex_ref(),
 as we're not holding any locks preventing ifnet deletion by a parallel thread.

To address it, add if_try_ref(), allowing to return failure when
 referencing ifp with refcount=0.
Additionally, enforce existing if_ref() is with KASSERT to provide a
 cleaner error in such scenarios.

Finally, fix ifnet_byindex_ref() by using if_try_ref() and returning NULL
 if the latter fails.

MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28836

(cherry picked from commit 7563019bc69301a382abefbac3b0fea1d876410e)

2 years agosctp: Fix racy UNBOUND flag check in sctp_inpcb_bind()
Mark Johnston [Tue, 31 Aug 2021 11:43:47 +0000 (07:43 -0400)]
sctp: Fix racy UNBOUND flag check in sctp_inpcb_bind()

SCTP needs to avoid binding a given socket twice.  The check used to
avoid this is racy since neither the inpcb lock nor the global info lock
is held.  Fix it by synchronizing using the global info lock.  In
particular, sctp_inpcb_bind() may drop the inpcb lock in some cases, but
the info lock is sufficient to prevent double insertion into PCB hash
tables.

Reported by: syzbot+548a8560d959669d0e12@syzkaller.appspotmail.com
Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 4a36122b1db1b255cf21d926b997d524e6782429)

2 years agoitimer: Serialize access to the p_itimers array
Mark Johnston [Tue, 31 Aug 2021 20:38:05 +0000 (16:38 -0400)]
itimer: Serialize access to the p_itimers array

Fix the following race between itimer_proc_continue() and process exit.

itimer_proc_continue() may be called via realitexpire(), the real
interval timer.  Note that exit1() drains this timer _after_ draining
and freeing itimers.  Moreover, itimers_exit() is called without the
process lock held; it only acquires the proc lock when deleting
individual itimers, so once they are drained we free p->p_itimers
without any synchronization.  Thus, itimer_proc_continue() may load a
non-NULL p->p_itimers array and iterate over it after it has been freed.

Fix the problem by using the process lock when clearing p->p_itimers, to
synchronize with itimer_proc_continue().  Formally, accesses to this
field should be protected by the process lock anyway, and since the
array is allocated lazily this will not incur any overhead in the common
case.

Reported by: syzbot+c40aa8bf54fe333fc50b@syzkaller.appspotmail.com
Reported by: syzbot+929be2f32503bbc3844f@syzkaller.appspotmail.com
Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 3138392a46a4a8ecfb8e36e9970e88bbae9caed3)

2 years agomd: Clamp to a multiple of the sector size when resizing
Mark Johnston [Tue, 31 Aug 2021 19:35:08 +0000 (15:35 -0400)]
md: Clamp to a multiple of the sector size when resizing

We do this when creating md(4) devices, in kern_mdattach_locked(), but
not when resizing the provider.  Apply the same policy when resizing, as
many GEOM classes do not expect to deal with providers for which
pp->mediasize % pp->sectorsize != 0.

Reported by: syzkaller
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 47619b604402c9672a0f9bf62666f3bcba1dfb7e)

2 years agosctp: Simplify the free port search in sctp_inpcb_bind()
Mark Johnston [Tue, 31 Aug 2021 11:43:39 +0000 (07:43 -0400)]
sctp: Simplify the free port search in sctp_inpcb_bind()

Eliminate a flag variable and reduce indentation.  No functional change
intended.

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2496d812a9c781f8e4be1bfd22375c6e686665da)

2 years agosctp: Avoid unnecessary refcount bumps in sctp_inpcb_bind()
Mark Johnston [Tue, 31 Aug 2021 11:43:27 +0000 (07:43 -0400)]
sctp: Avoid unnecessary refcount bumps in sctp_inpcb_bind()

We only drop the inp lock when binding to a specific port.  So, only
acquire an extra reference when required.  This simplifies error
handling a bit.

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 93908fce7280b1146bbc5135b78829e8f8ff1b74)

2 years agograid: Avoid tasting devices with small sector sizes
Mark Johnston [Tue, 31 Aug 2021 21:09:52 +0000 (17:09 -0400)]
graid: Avoid tasting devices with small sector sizes

The RAID metadata parsers effectively assume a sector size of 512 bytes
or larger, but md(4) devices can be created with a sector size that's
any power of 2.  Add some seatbelts to graid tasting routines to ensure
that the requested sector(s) are large enough for the device to
plausibly contain RAID metadata.

Reported by: syzbot+f43583c9bf8357c8b56f@syzkaller.appspotmail.com
Reported by: syzbot+537dd9f22b91b698e161@syzkaller.appspotmail.com
Reported by: syzbot+51509dd48871c57c6e47@syzkaller.appspotmail.com
Reported by: syzbot+c882a31037ea2a54ff63@syzkaller.appspotmail.com
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 9e9ba9c73de9206d82b8390c47b07f71470d001a)

2 years agomdconfig: Add a regression test for mediasize rounding
Mark Johnston [Tue, 31 Aug 2021 19:50:09 +0000 (15:50 -0400)]
mdconfig: Add a regression test for mediasize rounding

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ed59446b47095fc20c1f77e832286f5b953cd289)

2 years agosctp: Remove always-false checks in sctp_inpcb_bind()
Mark Johnston [Tue, 31 Aug 2021 11:43:13 +0000 (07:43 -0400)]
sctp: Remove always-false checks in sctp_inpcb_bind()

No functional change intended.

Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 0d29e4bc011dd4557ff9bde373bd48c567c3a4bf)

2 years agoRELNOTES: Add entry for just-MFC'ed HiFive Unmatched support
Jessica Clarke [Tue, 7 Sep 2021 12:15:18 +0000 (13:15 +0100)]
RELNOTES: Add entry for just-MFC'ed HiFive Unmatched support

This is a direct commit.

2 years agomx25l: Add support for Integrated Silicon Solution is25wp256
Thomas Skibo [Mon, 30 Aug 2021 20:39:20 +0000 (21:39 +0100)]
mx25l: Add support for Integrated Silicon Solution is25wp256

This is used for the on-board flash on the HiFive Unmatched board.

Reviewed by: #riscv, jrtc27
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31562

(cherry picked from commit 416ac155bb750fa55917daf340abe4ef04e7d4e6)

2 years agosifive_spi: Add missing case for SPIBUS_MODE_NONE
Thomas Skibo [Mon, 30 Aug 2021 20:39:20 +0000 (21:39 +0100)]
sifive_spi: Add missing case for SPIBUS_MODE_NONE

Otherwise sckmode is left uninitialised, not zero. This mode is used for
the on-board flash on the HiFive Unmatched board. Whilst here, catch
unknown modes and return an error rather than silently continuing.

Reviewed by: #riscv, jrtc27
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31562

(cherry picked from commit f5d78bea1f699c05e1694505088e61d22b8fb1f5)

2 years agoRevert "Mark LLDB/CLANG_BOOTSTRAP/LLD_BOOTSTRAP as broken on non-FreeBSD for now"
Jessica Clarke [Tue, 24 Aug 2021 14:00:06 +0000 (15:00 +0100)]
Revert "Mark LLDB/CLANG_BOOTSTRAP/LLD_BOOTSTRAP as broken on non-FreeBSD for now"

The fixes for this have now been committed so we can re-enable these.

This reverts commit d9f25575a29ff7c83f226349a10a37b9aaf75ad5.

MFC after: 1 week

(cherry picked from commit 83ec48b79275b5211b06675dba04dab1f58c3a70)

2 years agoclang: Build with -fno-strict-aliasing when using GCC
Jessica Clarke [Tue, 24 Aug 2021 13:59:36 +0000 (14:59 +0100)]
clang: Build with -fno-strict-aliasing when using GCC

Somewhat ironically, there are strict aliasing violations in Clang,
which can result in the following assertion failure:

  Assertion `*(NamedDecl **)&Data == ND && "PointerUnion mangles the NamedDecl pointer!"' failed.

Upstream's clang/CMakeLists.txt specifically (not LLVM as a whole)
passes -fno-strict-aliasing if the compiler is not Clang, and this fixes
the above issue.

This was seen when cross-building from Linux using a bootstrap
compiler, but likely also affects worlds built with a new enough
external GCC toolchain.

MFC after: 1 week
Reviewed by: dim
Differential Revision: https://reviews.freebsd.org/D31533

(cherry picked from commit c1f7d8dd23db693106fcd66e0b1766a3f3194670)

2 years agoclang: Support building with GCC and DEBUG_FILES disabled
Jessica Clarke [Tue, 24 Aug 2021 13:59:18 +0000 (14:59 +0100)]
clang: Support building with GCC and DEBUG_FILES disabled

If MK_DEBUG_FILES=no then the Clang link rule has clang as .TARGET,
rather than clang.full, causing the implicit ${CFLAGS.${.TARGET:T}} to
be CFLAGS.clang, and thus pull in flags intended for when your compiler
is Clang, not when linking Clang itself. This doesn't matter if your
compiler is in fact Clang, but it breaks using GCC as, for example,
bsd.sys.mk adds -Qunused-arguments to CFLAGS.clang. This is seen when
trying to build a bootstrap toolchain on Linux where GCC is the system
compiler.

Thus, introduce a new internal NO_TARGET_FLAGS variable that is set by
Clang to disable the addition of these implicit flags. This is a bigger
hammer than necessary, as flags for .o files would be safe, but that is
not needed for Clang.

Note that the same problem does not arise for LDFLAGS when building LLD
with BFD, since our build produces a program called ld.lld, not plain
lld (unlike upstream, where ld.lld is a symlink to lld so they can
support multiple different flavours in one binary).

Suggested by: sjg
Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week
Reviewed by: dim, imp, emaste
Differential Revision: https://reviews.freebsd.org/D31532

(cherry picked from commit c8edd0542647f59ab07dd73e865edd34706397a5)

2 years agoFix bootstrapping to actually build lldb-tblgen for later use
Jessica Clarke [Tue, 24 Aug 2021 13:59:04 +0000 (14:59 +0100)]
Fix bootstrapping to actually build lldb-tblgen for later use

Because MK_LLDB=no is in BSARGS, the bootstrap-tools recursive make does
not add lldb-tblgen to _clang_tblgen, causing it to not be built. This
means that the build currently always uses the host's lldb-tblgen
(which, whilst currently it appears to work, could in future break if
TableGen backends are added or altered) and, if it doesn't exist (either
because the current FreeBSD system was built with it disabled, or you're
building on macOS/Linux), fails. Linux and macOS cross-builds used to
work simply because LLDB was previously in BROKEN_OPTIONS when building
on non-FreeBSD.

Instead, move MK_LLDB=no from BSARGS to XMAKE. This ensures that the
lib/clang build in cross-tools continues to not build LLDB parts for the
bootstrap toolchain (both to save time/space on FreeBSD, and because our
vendored LLDB does not include the macOS and Linux host files so those
would fail to build).

The DIRDEPS target is updated to move MK_LLDB=no from the BSARGS block
that mirrors Makefile.inc1 to the line that disables additional
toolchain components. The DIRDEPS build likely suffers from the same
issue currently, but having never used it and not being familiar with
how it works I am leaving that as-is. If it does suffer from the same
issue it should be easily reproducible by renaming /usr/bin/lldb-tblgen
or moving it to a directory not in PATH.

Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week
Reviewed by: dim, emaste, imp
Differential Revision: https://reviews.freebsd.org/D31531

(cherry picked from commit 1e4c802913af619ac15741bbd276e1141ca17dc9)

2 years agoMakefile.inc1: Make sure sub-makes see MK_CLANG_BOOTSTRAP=no when XCC is a path
Jessica Clarke [Tue, 24 Aug 2021 13:55:31 +0000 (14:55 +0100)]
Makefile.inc1: Make sure sub-makes see MK_CLANG_BOOTSTRAP=no when XCC is a path

Currently we override MK_CLANG_BOOTSTRAP to no so we don't build a
bootstrap compiler, but subdirectories don't see that and so the hack in
bsd.sys.mk to prefer our includes over Clang's resource dir for external
toolchains is not enabled unless you use -DWITHOUT_CLANG_BOOTSTRAP
explicitly on top of XCC (which tools/build/make.py does not do),
causing duplicate definition errors when building rtld-elf due to the
use of -ffreestanding (Clang's stdint.h will use the system one when
hosted, but its own when freestanding, and only has glibc's preprocessor
guards, not FreeBSD's).

This broke when dropping CLANG_BOOTSTRAP from BROKEN_OPTIONS.

Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week
Reviewed by: imp, arichardson
Differential Revision: https://reviews.freebsd.org/D31529

(cherry picked from commit ab3a18095faebe306989f25288c44968f4144063)

2 years agoclang: Fix inverted condition in llvm.build.mk
Jessica Clarke [Thu, 12 Aug 2021 22:53:30 +0000 (23:53 +0100)]
clang: Fix inverted condition in llvm.build.mk

Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week

(cherry picked from commit 5ff5d1177bc66f1c2a0a6ee4d0ffa128d32e1dad)

2 years agotools/build/cross-build: Fix building libllvmminimal on Linux
Jessica Clarke [Thu, 12 Aug 2021 22:50:48 +0000 (23:50 +0100)]
tools/build/cross-build: Fix building libllvmminimal on Linux

There is a __used member in glibc's posix_spawn_file_actions_t in
spawn.h, so we must temporarily undefine __used when including it,
otherwise Support/Unix/Program.inc fails to build. This is based on
similar handling for __unused in other headers.

Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week

(cherry picked from commit 8a1895a3fa6f634e9f459b6b62321a61c7941bdc)

2 years agoriscv: Fix pmap_alloc_l2 when it should allocate a new L1 entry
Jessica Clarke [Mon, 9 Aug 2021 19:28:37 +0000 (20:28 +0100)]
riscv: Fix pmap_alloc_l2 when it should allocate a new L1 entry

The current code checks the RWX bits are 0 but does not check the V bit
is non-zero, meaning not-yet-allocated L1 entries that are still zero
are regarded as being allocated. This is likely due to copying the arm64
code that checks ATTR_DESC_MASK is L1_TABLE, which emcompasses both the
type and the validity in a single field, and erroneously translating
that to a check of just PTE_RWX being 0 to indicate non-leaf, forgetting
about the V bit. This then results in the following panic:

    panic: Fatal page fault at 0xffffffc0005cf292: 0x00000000000050
    cpuid = 1
    time = 1628379581
    KDB: stack backtrace:
    db_trace_self() at db_trace_self
    db_trace_self_wrapper() at db_trace_self_wrapper+0x38
    kdb_backtrace() at kdb_backtrace+0x2c
    vpanic() at vpanic+0x148
    panic() at panic+0x2a
    page_fault_handler() at page_fault_handler+0x1ba
    do_trap_supervisor() at do_trap_supervisor+0x7a
    cpu_exception_handler_supervisor() at
    cpu_exception_handler_supervisor+0x70
    --- exception 13, tval = 0x50
    pmap_enter_l2() at pmap_enter_l2+0xb2
    pmap_enter_object() at pmap_enter_object+0x15e
    vm_map_pmap_enter() at vm_map_pmap_enter+0x228
    vm_map_insert() at vm_map_insert+0x4ec
    vm_map_find() at vm_map_find+0x474
    vm_map_find_min() at vm_map_find_min+0x52
    vm_mmap_object() at vm_mmap_object+0x1ba
    vn_mmap() at vn_mmap+0xf8
    kern_mmap() at kern_mmap+0x4c4
    sys_mmap() at sys_mmap+0x38
    do_trap_user() at do_trap_user+0x208
    cpu_exception_handler_user() at cpu_exception_handler_user+0x72
    --- exception 8, tval = 0x1dd

Instead, we should just check the V bit, as on amd64, and assert that
any valid L1 entries are not leaves, since an L1 leaf would render the
entire range allocated and thus we should not have attempted to map that
VA in the first place.

Reported by: David Gilbert <dgilbert@daveg.ca>
MFC after: 1 week
Reviewed by: markj, mhorne
Differential Revision: https://reviews.freebsd.org/D31460

(cherry picked from commit 98138bbde032e2040af3d158658c497fd3f63f2a)