freebsd-dev/sys
Stephen Hurd b89827a052 iflib: fix invalid free during queue allocation failure
In r301567, code was added to cleanup to prevent memory leaks for the
Tx and Rx ring structs. This code carefully tracked txq and rxq, and
made sure to free them properly during cleanup.

Because we assigned the txq and rxq pointers into the ctx->ifc_txqs and
ctx->ifc_rxqs, we carefully reset these pointers to NULL, so that
cleanup code would not accidentally free the memory twice.

This was changed by r304021 ("Update iflib to support more NIC designs"),
which removed this resetting of the pointers to NULL, because it re-used
the txq and rxq pointers as an index into the queue set array.

Unfortunately, the cleanup code was left alone. Thus, if we fail to
allocate DMA or fail to configure the queues using the drivers ifdi
methods, we will attempt to free txq and rxq. These variables would now
incorrectly point to the wrong location, resulting in a page fault.

There are a number of methods to correct this, but ultimately the root
cause was that we reuse the txq and rxq pointers for two different
purposes.

Instead, when allocating, store the returned pointer directly into
ctx->ifc_txqs and ctx->ifc_rxqs. Then, assign this to txq and rxq as
index pointers before starting the loop to allocate each queue.
Drop the cleanup code for txq and rxq, and only use ctx->ifc_txqs and
ctx->ifc_rxqs.

Thus, we no longer need to free txq or rxq under any error flow, and
intsead rely solely on the pointers stored in ctx->ifc_txqs and
ctx->ifc_rxqs. This prevents the invalid free(), and ensures that we
still properly cleanup after ourselves as before when failing to
allocate.

Submitted by:	Jacob Keller
Reviewed by:	gallatin, sbruno
Sponsored by:	Intel Corporation
Differential Revision:	https://reviews.freebsd.org/D15285
2018-05-04 15:20:34 +00:00
..
amd64 amd64: get rid of the pessimized bcopy in syscall arg copy 2018-05-04 04:05:07 +00:00
arm Add Marvell ArmadaXP and Armada38X to GENERIC config 2018-05-03 01:23:42 +00:00
arm64 Print the dump progress indicator after calling dump_start(). 2018-05-01 17:32:43 +00:00
bsm
cam Refactor dadone(). There was no useful code sharing in it; it was just 2018-05-01 21:42:27 +00:00
cddl opensolaris system_taskq does not need to run at maximum priority 2018-05-04 07:28:01 +00:00
compat Define USEC_PER_MSEC and USEC_PER_SEC in the LinuxKPI. 2018-04-30 09:31:09 +00:00
conf Retire ixgb(4) 2018-05-02 15:59:15 +00:00
contrib MFV: r333077 2018-05-01 19:17:38 +00:00
crypto opencrypto: Integrate Chacha20 algorithm into OCF 2018-03-29 04:02:50 +00:00
ddb Restore db_radix on parse error, otherwise we'll silently change it to 2018-04-17 15:44:05 +00:00
dev Allow PCI VGA devices to be detached. 2018-05-03 22:51:44 +00:00
dts arm: overlays: Update to new path-based sugar format 2018-05-04 14:38:48 +00:00
fs msdosfs: long names of files are created incorrectly. 2018-05-04 03:44:12 +00:00
gdb amd64: Protect the kernel text, data, and BSS by setting the RW/NX bits 2018-03-06 14:28:37 +00:00
geom gpart: add fat32lba MBR partition type 2018-05-04 00:34:27 +00:00
gnu gnu/dts: Update our copy of arm dts from Linux 4.16 2018-04-20 19:37:08 +00:00
i386 Implement support for ifuncs in the kernel linker. 2018-05-03 21:37:46 +00:00
isa Revert r330780, it was improperly tested and results in taking a spin 2018-03-11 20:13:15 +00:00
kern dup1_processes -t 96 -s 5 on a dual 8160 2018-05-04 06:51:01 +00:00
kgssapi kgssapi: Remove trivial deadcode 2018-02-14 00:12:03 +00:00
libkern iconv uses strlen directly on user supplied memory 2018-02-26 18:23:36 +00:00
mips Print the dump progress indicator after calling dump_start(). 2018-05-01 17:32:43 +00:00
modules dtb/allwinner: Add a83t-sid overlay 2018-05-03 19:45:48 +00:00
net iflib: fix invalid free during queue allocation failure 2018-05-04 15:20:34 +00:00
net80211 Use an accessor function to access ifr_data. 2018-03-30 18:50:13 +00:00
netgraph Correct pseudo misspelling in sys/ comments 2018-02-23 18:15:50 +00:00
netinet Immediately propagate EACCES error code to application from tcp_output. 2018-05-04 09:28:12 +00:00
netinet6 Send an ICMPv6 PacketTooBig message in case of forwading a packet which 2018-05-02 22:11:16 +00:00
netipsec Merge r1.22-1.23 from NetBSD: 2018-04-26 12:23:31 +00:00
netpfil Retire ixgb(4) 2018-05-02 15:59:15 +00:00
netsmb Unsign some values related to allocation. 2018-01-22 02:08:10 +00:00
nfs Remove support for FDDI networks. 2018-04-11 17:28:24 +00:00
nfsclient style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nfsserver
nlm Use syscall_helper_register() to register syscalls and initialize though 2018-02-10 01:09:22 +00:00
ofed Improve copy-and-pasted versions of SIOCGIFADDR. 2018-03-27 20:51:49 +00:00
opencrypto cryptosoft: Do not exceed crd_len around *crypt_multi 2018-04-19 15:24:21 +00:00
powerpc Allow __builtin_memmove instead of bcopy for small buffers of known size 2018-05-04 04:00:48 +00:00
riscv Remove the unused fuwintr() and suiwintr() functions. 2018-04-17 18:04:28 +00:00
rpc Do pass removing some write-only variables from the kernel. 2017-12-25 04:48:39 +00:00
security Use an accessor function to access ifr_data. 2018-03-30 18:50:13 +00:00
sparc64 Retire ixgb(4) 2018-05-02 15:59:15 +00:00
sys Allow __builtin_memmove instead of bcopy for small buffers of known size 2018-05-04 04:00:48 +00:00
teken Pedantic polishing of code to please FlexeLint. 2018-04-08 19:23:50 +00:00
tests
tools Add dtb overlays support 2018-03-24 21:30:24 +00:00
ufs Renumber soft-update types starting at 1 instead of 0 to avoid confusion 2018-04-05 00:32:01 +00:00
vm Eliminate some vm object relocks in vm fault. 2018-04-29 12:43:08 +00:00
x86 Add helper macros to hide some boring repeatable ceremonies to define 2018-05-03 21:45:59 +00:00
xdr
xen xen: fix gntdev 2018-05-02 10:19:17 +00:00
Makefile