Commit graph

139333 commits

Author SHA1 Message Date
Michael Tuexen
db8fc0ef23 tcp, udp: improve input validation in handling bind()
Reported by:		syzbot+24fcfd8057e9bc339295@syzkaller.appspotmail.com
Reported by:		syzbot+6e90ceb5c89285b2655b@syzkaller.appspotmail.com
Reviewed by:		markj, rscheff
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D31422

(cherry picked from commit 3f1f6b6ef7)
2022-02-22 23:27:01 +01:00
Ed Maste
531b495885 newvers.sh: allow multiple -V args in one invocation
Reviewed by:	imp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34253

(cherry picked from commit acfb506b3d)
2022-02-22 14:53:01 -05:00
Warner Losh
ee30e4458c ed: Remove options
ed(4) was removed some time ago, but these options relevant to only it
weren't GC'd at the time. Remove them.

Sponsored by:		Netflix

(cherry picked from commit 21e22be91a)
2022-02-22 11:44:56 -07:00
Andrew Turner
598e53b3d3 Stop single stepping in signal handers on arm64
We should clear the single step flag when entering a signal hander and
set it when returning. This fixes the ptrace__PT_STEP_with_signal test.

While here add support for userspace to set the single step bit as on
x86. This can be used by userspace for self tracing.

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

(cherry picked from commit 31cf95cec7)
2022-02-22 16:23:07 +00:00
Andrew Turner
4b8f747b9d Fix the signal code on 32-bit breakpoints on arm64
When debugging 32-bit programs a debugger may insert a instruction that
will raise the undefined instruction trap. The kernel handles these
by raising a SIGTRAP, however the code was incorrect.

Fix this by using the expected TRAP_BRKPT signal code.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 67dc576bae)
2022-02-22 16:23:07 +00:00
Andrew Turner
de87d94008 Sort the names of the arm64 debug registers
While here clean up the names for the naming convention of the other
registers in this file.

Reviewed by:	kib, mhorne (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34060

(cherry picked from commit 664640ba6c)
2022-02-22 16:23:07 +00:00
Andrew Turner
1633d17f61 Add the Armv8.3-SPE registers
(cherry picked from commit 2ad1999722)
2022-02-22 16:23:07 +00:00
Andrew Turner
61a7ad35bb Teach DTrace about BTI on arm64
The Branch Target Identification (BTI) Armv8-A extension adds new
instructions that can be placed where we may indirrectly branch to,
e.g. at the start of a function called via a function pointer. We can't
emulate these in DTrace as the kernel will have raised a different
exception before the DTrace handler has run.

Skip over the BTI instruction if it's used as the first instruction in
a function.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b5876847ac)
2022-02-22 16:23:07 +00:00
Andrew Turner
efe35aecb8 Handle functions that use a nop in the arm64 fbt
To trace leaf asm functions we can insert a single nop instruction as
the first instruction in a function and trigger off this.

Reviewed by:	gnn
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D28132

(cherry picked from commit 28d945204e)
2022-02-22 16:23:07 +00:00
Andrew Turner
24a205e328 Fix undefined behaviour in the USB controllers
The USB controller drivers assume they can cast a NULL pointer to a
struct and find the address of a member. KUBSan complains about this so
replace with the __offsetof and __containerof macros that use either a
builtin function where available, or the same NULL pointer on older
compilers without the builtin.

Reviewers: hselasky

Subscribers: imp

Reviewed by:	hselasky
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33865

(cherry picked from commit a3cea15680)
2022-02-22 16:23:07 +00:00
Mark Johnston
b55a7f3422 Fix handling of errors from dmu_write_uio_dbuf() on FreeBSD
FreeBSD's implementation of zfs_uio_fault_move() returns EFAULT when a
page fault occurs while copying data in or out of user buffers.  The VFS
treats such errors specially and will retry the I/O operation (which may
have made some partial progress).

When the FreeBSD and Linux implementations of zfs_write() were merged,
the handling of errors from dmu_write_uio_dbuf() changed such that
EFAULT is not handled as a partial write.  For example, when appending
to a file, the z_size field of the znode is not updated after a partial
write resulting in EFAULT.

Restore the old handling of errors from dmu_write_uio_dbuf() to fix
this.  This should have no impact on Linux, which has special handling
for EFAULT already.

Reviewed-by: Andriy Gapon <avg@FreeBSD.org>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #12964
(cherry picked from commit 063daa8350)
2022-02-21 09:59:58 -05:00
Mark Johnston
005452c350 Avoid memory allocations in the ARC eviction thread
When the eviction thread goes to shrink an ARC state, it allocates a set
of marker buffers used to hold its place in the state's sublists.

This can be problematic in low memory conditions, since
1) the allocation can be substantial, as we allocate NCPU markers;
2) on at least FreeBSD, page reclamation can block in
   arc_wait_for_eviction()

In particular, in stress tests it's possible to hit a deadlock on
FreeBSD when the number of free pages is very low, wherein the system is
waiting for the page daemon to reclaim memory, the page daemon is
waiting for the ARC eviction thread to finish, and the ARC eviction
thread is blocked waiting for more memory.

Try to reduce the likelihood of such deadlocks by pre-allocating markers
for the eviction thread at ARC initialization time.  When evicting
buffers from an ARC state, check to see if the current thread is the ARC
eviction thread, and use the pre-allocated markers for that purpose
rather than dynamically allocating them.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: George Amanakis <gamanakis@gmail.com>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #12985
(cherry picked from commit 6e2a59181e)
2022-02-21 09:59:23 -05:00
Mark Johnston
f8fa2f0e75 msdosfs: Fix mounting when the device sector size is >512B
HugeSectors * BytesPerSec should be computed before converting
HugeSectors to a DEV_BSIZE-based count.

Fixes:	ba2c98389b ("msdosfs: sanity check sector count from BPB")
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c7cd607a4e)
2022-02-21 09:57:54 -05:00
Mark Johnston
dbba19453e sleepqueue: Annotate sleepq_max_depth as static
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 852ff943b9)
2022-02-21 09:57:46 -05:00
Mark Johnston
59e095633d tcp: Avoid conditionally defined fields in union lro_address
The layout of the structure ends up depending on whether the including
file includes opt_inet.h and opt_inet6.h, so different compilation units
can end up seeing different versions of the structure.  Fix this by
unconditionally defining the address fields.

As a side effect, this eliminates some duplication in the kernel's CTF
type graph.

Reviewed by:	rscheff, tuexen
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b4f60fab5d)
2022-02-21 09:57:04 -05:00
Edward Tomasz Napierala
d3f0d2c0ee linux: Add additional ptracestop only if the debugger is Linux
In 6e66030c4c, additional ptracestop was added in order
to implement PTRACE_EVENT_EXEC.  Make it only apply to cases
where the debugger is a Linux processes; native FreeBSD
debuggers can trace Linux processes too, but they don't
expect that additonal ptracestop.

Fixes:		6e66030c4c
Reported By:	kib
Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32726

(cherry picked from commit 8bbc0600cc)
2022-02-21 14:31:22 +00:00
Edward Tomasz Napierala
bb726462cb linux: Make PTRACE_GETREGSET return proper buffer size
This fixes Chrome warning:

[1022/152319.328632:ERROR:ptracer.cc(476)] Unexpected registers size 0 != 216, 68

Reviewed By:	emaste
Sponsored By:	EPSRC
Differential Revision: https://reviews.freebsd.org/D32616

(cherry picked from commit f939dccfd7)
2022-02-21 13:36:23 +00:00
Edward Tomasz Napierala
f89bad7c9c linux: Fix ptrace panic with ERESTART
Translate ERESTART into Linux "internal" errno ERESTARTSYS.
This fixes the erestartsys.gen.test from strace(1).

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32623

(cherry picked from commit 6547153e46)
2022-02-21 13:36:11 +00:00
Edward Tomasz Napierala
f4fd475d45 linux: Improve debug for PTRACE_GETEVENTMSG
No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit 2ec26ae402)
2022-02-21 13:36:01 +00:00
Edward Tomasz Napierala
fc36cd43fd linux: implement PTRACE_EVENT_EXEC
This fixes strace(1) from Ubuntu Focal.

Reviewed By:	jhb
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32367

(cherry picked from commit 6e66030c4c)
2022-02-21 13:35:51 +00:00
Edward Tomasz Napierala
3b7841de78 linux: Make PTRACE_GET_SYSCALL_INFO handle EJUSTRETURN
This fixes panic when trying to run strace(8) from Focal.

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32355

(cherry picked from commit 2558bb8e91)
2022-02-21 13:35:30 +00:00
Edward Tomasz Napierala
046274e798 linux: Improve debug for PTRACE_GETREGSET
No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit e3a83df119)
2022-02-21 13:35:20 +00:00
Edward Tomasz Napierala
98e26c32bb linux: Improve debugging for PTRACE_GETREGSET
It's triggered by gdb(1).

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32456

(cherry picked from commit a03d4d73e4)
2022-02-21 13:35:10 +00:00
Edward Tomasz Napierala
d33684f371 linux: Implement some bits of PTRACE_PEEKUSER
This makes Linux gdb from Bionic a little less broken.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32455

(cherry picked from commit f9246e1484)
2022-02-21 13:34:56 +00:00
Edward Tomasz Napierala
36ff5ce03c linux: Adjust PTRACE_GET_SYSCALL_INFO buffer size semantics
The tests/ptrace_syscall_info test from strace(1) complained
about this.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32368

(cherry picked from commit 75a9d95b4d)
2022-02-21 13:34:44 +00:00
Konstantin Belousov
4cae9d803a Remove PT_GET_SC_ARGS_ALL
Reimplement bdf0f24bb1 by checking for the caller' ABI in
the implementation of PT_GET_SC_ARGS, and copying out everything if
it is Linuxolator.

Also fix a minor information leak: if PT_GET_SC_ARGS_ALL is done on the
thread reused after other process, it allows to read some number of that
thread last syscall arguments. Clear td_sa.args in thread_alloc().

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D31968

(cherry picked from commit f575573ca5)
2022-02-21 13:34:16 +00:00
Edward Tomasz Napierala
8371bf67d6 linux: implement PTRACE_GET_SYSCALL_INFO
This is one of the pieces required to make modern (ie Focal)
strace(1) work.

Reviewed By:	jhb (earlier version)
Sponsored by:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D28212

(cherry picked from commit bdf0f24bb1)
2022-02-21 13:23:50 +00:00
Edward Tomasz Napierala
0737ef6fbc linux: make ptrace(2) return EIO when trying to peek invalid address
Previously we've returned the error from native ptrace(2), ENOMEM.
This confused Linux strace(2).

Reviewed By:	emaste
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29925

(cherry picked from commit 77651151f3)
2022-02-21 13:19:30 +00:00
Edward Tomasz Napierala
7256167dfd linux: refactor bsd_to_linux_regset() out of linux_ptrace.c
This will be used for Linux coredump support.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30365

(cherry picked from commit 95c19e1d65)
2022-02-21 12:46:06 +00:00
Edward Tomasz Napierala
26105b4c13 linux(4): make arch_prctl(2) support GET_CET_STATUS, report unknown codes
This is largely a no-op, to make future debugging slightly easier.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30035

(cherry picked from commit 916f3dba45)
2022-02-21 12:44:26 +00:00
Edward Tomasz Napierala
1f948bb41f linux(4): fix ptrace(2) to properly handle orig_rax
This fixes strace(1) erroneously reporting return values
as "Function not implemented", combined with reporting the binary
ABI as X32.

Very similar code in linux_ptrace_getregs() is left as it is - it's
probably wrong too, but I don't have a way to test it.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29927

(cherry picked from commit 023bff7990)
2022-02-21 12:43:37 +00:00
Franco Fichtner
1c8d9e1b05 pf: fix set_prio after nv conversion
Reviewed by:	kp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D34266

(cherry picked from commit 0143a6bb7f)
2022-02-21 10:18:24 +01:00
Bjoern A. Zeeb
c39ff2415c Bump __FreeBSD_version to 1300526 for LinuxKPI changes.
This successfully builds against drm-fbsd13-kmod-5.4.144.g20220128
so no conflicting changes on the MFC.  Given there are overlaps, bump
__FreeBSD_version so they can be detected and removed as pleases.
2022-02-20 18:15:16 +00:00
Bjoern A. Zeeb
999377a66d LinuxKPI: 802.11 simplify beacon checks in rx path
In linuxkpi_ieee80211_rx() check if the frame is a beacon once upfront
and use the result for enhanced debugging and further checks.
This was done intially for rx_status->device_timestamp debugging.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c0cadd99d1)
2022-02-20 16:26:06 +00:00
Bjoern A. Zeeb
ddcb65c526 LinuxKPI: implement dma_sync_single_for_*, apply to (un)map single/sg
Implement dma_sync_single_for_{cpu,device} translating the Linux
DMA_ flags to BUS_DMASYNC_ combinations.  Make map_single/unmap_single*
functions call the respective sync function.   Apply the same logic to
the scatter-gather list map/unmap functions.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D32255

(cherry picked from commit 95edb10b47)
2022-02-20 16:26:01 +00:00
Bjoern A. Zeeb
d21079b4b8 LinuxKPI: 802.11: disable ic_headroom for the moment
There is a problem with some drivers, such as rtw88, asking for more
headroom than we currently can handle throughout the stack (we have
other legacy wireless driver in the tree with similar problems).
This may trigger an assertion in the TCP syncache where we are checking
for a reply to fit in MHLEN.
While for the moment we still copy data from mbufs to skbs,
we can simply disable the extra headroom request in ic_headroom and
deal with it ourselves (which we already did anyway).
Leave a link to the thread on freebsd-transport detailing more of the
problem so we can find it again and solve it here or there.

(cherry picked from commit 3d09d310d9)
2022-02-20 16:25:55 +00:00
Bjoern A. Zeeb
266cae8062 LinuxKPI: 802.11 advertise full offload scanning based on hw_scan only
We disabled hw_scan for drivers not advertising SINGLE_SCAN_ON_ALL_BANDS.
Do not depend on this hw flag to set IEEE80211_FEXT_SCAN_OFFLOAD for
net80211 as otherwise scanning will never work.
Long-term we probably want to re-think how we do/integrate hw_scan
better in net80211.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit cc4e78d513)
2022-02-20 16:25:49 +00:00
Bjoern A. Zeeb
6ddbe66d02 LinuxKPI: 802.11 header updates and add/adjust source dependencies.
This update is for more/newer versions of drivers:
- add and properly place more structs, enums, defines needed by drivers.
- correct types of struct fields.
- make various function arguments const.
- move REG_RULE() macro to its own file regulatory.h and
  use macros for calculations.
- add linuxkpi_ieee80211_get_channel() implementation.
- change linuxkpi_ieee80211_ifattach() to return int for error checking.

No intended functional changes for iwlwifi.

Sponsored by:	The FreeBSD Foundation (partially)

(cherry picked from commit 2e183d999c)
2022-02-20 16:25:43 +00:00
Bjoern A. Zeeb
5221620a8b LinuxKPI: skbuff updates
Various updates to skbuff for new/updated drivers and some housekeeping:
- update types and struct members, add new (stub) functions
- improve freeing of frags.
- fix an issue with sleeping during alloc for dev_alloc_skb().
- Adjust a KASSERT for skb_reserve() which apparently can be called
  multiple times if no data was put into the skb yet.
- move the sysctl from linux_8022.c (which may be in a different module)
  to linux_skbuff.c so in case we turn debugging on we do not run into
  unresolved symbols.  Rename the sysctl variable to be less conflicting
  and update debugging macros along with that; also add IMPROVE().
- add DDB support to show an skbuff.
- adjust comments/whitespace.

No functional changes intended for iwlwifi.

Sponsored by:	The FreeBSD Foundation (partially)

(cherry picked from commit 6baea3312d)
2022-02-20 16:25:37 +00:00
Bjoern A. Zeeb
1656816506 LinuxKPI: 802.11: defer workq allocation until we have a name
Turned out all the workq's taskqueues were named "wlanNA" if you had
more then one card in a machine as by the time we called wiphy_name()
the device name was not set yet and we returned the fallback.

Move the alloc_ordered_workqueue() from linuxkpi_ieee80211_alloc_hw()
to linuxkpi_ieee80211_ifattach() at which time the device name has
to be set to give us a unique name.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 652e22d395)
2022-02-20 16:25:30 +00:00
Bjoern A. Zeeb
8bc13d98db LinuxKPI: 802.11 assign an(y) early chandef
The Realtek driver assumes an early chandef to be set.  At the time
of linuxkpi_ieee80211_ifattach() we do not really know one yet so
try to find the first one which is available and set that.
This prevents a NULL-deref panic.

(cherry picked from commit c5b96b3eae)
2022-02-20 16:25:25 +00:00
Bjoern A. Zeeb
ada6a7cd68 LinuxKPI: 802.11 scan update
Realtek's rtw88 is returning a hard-coded 1 in case they cannot
hw_scan (fw not advertising it).  In that case if we want any scan
to run we need to fall-back to sw scan.  Start dealing with this.
Long-term we probably need to keep internal state.

(cherry picked from commit d3ef7fb459)
2022-02-20 16:25:19 +00:00
Bjoern A. Zeeb
0422c15541 LinuxKPI: pci.h add more defines
Add and sort in more defines needed by newer drivers.

Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D34293

(cherry picked from commit c4f52f71de)
2022-02-20 16:25:13 +00:00
Bjoern A. Zeeb
fb8b8b6a1d LinuxKPI: 802.11 enahnce linuxkpi_ieee80211_iterate_interfaces()
Add support for IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER in
linuxkpi_ieee80211_iterate_interfaces() needed by a driver.

(cherry picked from commit 61a68e50d4)
2022-02-20 16:25:08 +00:00
Bjoern A. Zeeb
a108252a71 LinuxKPI: lockdep add lockdep_assert_not_held()
Add lockdep_assert_not_held() asserting LA_UNLOCKED as needed by a
driver.

Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D34232

(cherry picked from commit 064c110f4b)
2022-02-20 16:25:03 +00:00
Bjoern A. Zeeb
e709b7d778 net80211: enhance (disabled) debugging
Add maxchans to the disabled debugging in addchan() and copychan_prev()
to aid debugging possible errors rreturned due to reaching maxchans
limits.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 32cf376a01)
2022-02-20 16:24:57 +00:00
Bjoern A. Zeeb
c3ffeddb47 LinuxKPI: add kstrtoint_from_user() and DECLARE_FLEX_ARRAY()
Add an implementation of kstrtoint_from_user() based on the other
implementations and an attempt at DECLARE_FLEX_ARRAY() which works
for the driver needing it.

Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D34231

(cherry picked from commit c840d5cec2)
2022-02-20 16:24:51 +00:00
Bjoern A. Zeeb
715d53ecb9 LinuxKPI: add UUID_STRING_LEN and GUID_INIT to uuid.h
Add a definition for UUID_STRING_LEN to uuid.h as needed by a driver.
Also add GUID_INIT for drm-kmod [1].

Submitted by:	wulf [1]
Reviewed by:	hselasky (earlier), wulf
Differential Revision: https://reviews.freebsd.org/D34235

(cherry picked from commit 97009980c4)
2022-02-20 16:24:38 +00:00
Bjoern A. Zeeb
f2a66c84c9 LinuxKPI: 802.11: get rid of lkpi_ic_getradiocaps warnings
Users are seeing warnings about 2 channels (1 per band)
triggered by an ioctl from wpa_supplicant usually:
	lkpi_ic_getradiocaps: Adding chan ... returned error 55
This was an early FAQ.

Check the current number of channels against maxchans and the return
code from net80211. In case net80211 reports that we reached the limit
do not print the warning and do not try to add further channels.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit cee56e77d7)
2022-02-20 16:24:32 +00:00
Bjoern A. Zeeb
3dff0341d9 LinuxKPI: add get_unaligned_le16()
Add get_unaligned_le16() to asm/unaligned.h needed by a driver.

Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D34224

(cherry picked from commit 2e818fbcfc)
2022-02-20 16:24:28 +00:00