freebsd-dev/sys
Jessica Clarke 29863d1eff xhci: Rework 64-byte context support to avoid pointer abuse
Currently, to support 64-byte contexts, xhci_ctx_[gs]et_le(32|64) take a
pointer to the field within a 32-byte context and, if 64-byte contexts
are in use, compute where the 64-byte context field is and use that
instead by deriving a pointer from the 32-byte field pointer. This is
done by exploiting a combination of 64-byte contexts being the same
layout as their 32-byte counterparts, just with 32 bytes of padding at
the end, and that all individual contexts are either in a device
context or an input context which itself is page-aligned. By masking out
the low 4 bits (which is the offset of the field within the 32-byte
contxt) of the offset within the page, the offset of the invididual
context within the containing device/input context can be determined,
which is itself 32 times the number of preceding contexts. Thus, adding
this value to the pointer again gets 64 times the number of preceding
contexts plus the field offset, which gives the offset of the 64-byte
context plus the field offset, which is the address of the field in the
64-byte context.

However, this involves a fair amount of lying to the compiler when
constructing these intermediate pointers, and is rather difficult to
reason about. In particular, this is problematic for CHERI, where we
compile the kernel with subobject bounds enabled; that is, unless
annotated to opt out (e.g. for C struct inheritance reasons where you
need to be able to downcast, or containerof idioms), a pointer to a
member of a struct is a capability whose bounds only cover that field,
and any attempt to dereference outside those bounds will fault,
protecting against intra-object buffer overflows. Thus the pointer given
to xhci_ctx_[gs]et_le(32|64) is a capability whose bounds only cover the
field in the 32-byte context, and computing the pointer to the 64-byte
context field takes the address out of bounds, resulting in a fault when
later dereferenced.

This can be cleaned up by using a different abstraction. Instead of
doing the 32-byte to 64-byte conversion on access to the field, we can
do the conversion when getting a pointer to the context itself, and
define proper 64-byte versions of contexts in order to let the compiler
do all the necessary arithmetic rather than do it manually ourselves.
This provides a cleaner implementation, works for CHERI and may even be
slightly more performant as it avoids the need to mess with masking
pointers (which cannot in the general case be optimised by compilers to
be reused across accesses to different fields within the same context,
since it does not know that the contexts are over-aligned compared with
the C ABI requirements).

Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D32554
2021-10-27 18:38:37 +01:00
..
amd64 linux: Improve debug for PTRACE_GETEVENTMSG 2021-10-23 19:53:12 +01:00
arm arm: Remove obsolete comments 2021-10-27 09:44:58 -06:00
arm64 linux: Constify bsd_to_linux_regset() 2021-10-23 08:33:58 +01:00
bsm
cam cam(4): Limit search for disks in SES enclosure by single bus 2021-10-05 15:01:16 -04:00
cddl Allow ddb and dtrace use the DMAP region on arm64 2021-10-01 11:27:33 +01:00
compat LinuxKPI: module.h add MODULE_SUPPORTED_DEVICE() 2021-10-25 20:26:01 +00:00
conf Retire obsolete iscsi_initiator(4) 2021-10-26 16:17:35 -04:00
contrib Revert "Handle partial reads in zfs_read" 2021-10-22 15:16:42 -04:00
crypto crypto: Support Chacha20-Poly1305 with a nonce size of 8 bytes. 2021-10-06 14:08:49 -07:00
ddb
dev xhci: Rework 64-byte context support to avoid pointer abuse 2021-10-27 18:38:37 +01:00
dts ipq4018: add a device tree file for the ASUS rt-ac58u router 2021-10-18 19:18:46 +00:00
fs nfscl: Add a missing delegation lock release 2021-10-25 19:11:45 -07:00
gdb
geom geom_label: Add more validation for NTFS volume tasting 2021-10-04 18:15:06 -04:00
gnu
i386 Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
isa
kern rmslock: Update td_locks during lock and unlock operations 2021-10-27 11:18:13 -04:00
kgssapi
libkern
mips Convert vm_page_alloc() callers to use vm_page_alloc_noobj(). 2021-10-19 21:22:56 -04:00
modules Retire obsolete iscsi_initiator(4) 2021-10-26 16:17:35 -04:00
net bpf: Fix the write filter for detached descriptors 2021-10-26 10:00:39 -04:00
net80211 net80211: correct input_sta length checks and control frame handling 2021-10-22 10:42:06 +00:00
netgraph Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
netinet rack: Update the fast send block on setsockopt(2) 2021-10-27 08:22:00 -07:00
netinet6 net: Allow binding of unspecified address without address existance 2021-10-20 19:25:51 -04:00
netipsec ipsec: fix typo part2 2021-09-27 07:46:56 +02:00
netpfil Use network epoch to protect local IPv4 addresses hash. 2021-10-22 14:40:53 -07:00
netsmb
nfs
nfsclient
nfsserver
nlm
ofed socket: De-duplicate SBLOCKWAIT() definitions 2021-09-14 09:01:32 -04:00
opencrypto ktls: Change struct ktls_session.cipher to an OCF-specific type. 2021-10-21 09:36:53 -07:00
powerpc Use the vm_radix_init() helper when initializing pmaps 2021-10-19 21:22:56 -04:00
riscv Convert consumers to vm_page_alloc_noobj_contig() 2021-10-19 21:22:56 -04:00
rpc rpc: Convert an SOLISTENING check to an assertion 2021-09-17 14:19:05 -04:00
security
sys Inline critical enter/exit for "tied" kernel modules 2021-10-25 20:07:06 +00:00
teken
tests
tools ipq4018: add TCSR definitions from Linux. 2021-10-18 19:18:01 +00:00
ufs ufs: remove write-only variables 2021-10-21 21:40:46 +03:00
vm sysctl vm.objects: yield if hog 2021-10-25 20:34:02 +03:00
x86 Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
xdr
xen
Makefile