netlink: Make room for the unfinished message when growing the buffer
When a message outgrows the writer's buffer, _nlmsg_refill_buffer()
allocates a larger one and moves the unfinished message there. The new
buffer was sized for the data about to be added alone, so with enough of
the message already written the caller wrote past its end and left it
with datalen > buflen. A 20-byte message plus an attribute of 8176
bytes got a buffer of 8192 bytes for 8200 bytes of data, and reading it
panicked an INVARIANTS kernel in nl_soreceive().
Size the new buffer for both, and add a ktest for it.
Reviewed by: glebius
Fixes: 7e5bf68495cc ("netlink: add netlink support")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60541
net80211: add DRIVER_REGISTRATION to README.md ; fix links
* add the driver registration doc to README.md
* fix the links to resolve correctly with current doxygen
(1.18.0) with the current file path -> sanity conversion ->
html path rules.
Differential Revision: https://reviews.freebsd.org/D60504
Reviewed by: ziaee
net80211: add driver registration documentation
This is a brief introduction into the top-level newbus
driver methods and net80211 driver registration.
Differential Revision: https://reviews.freebsd.org/D60503
Reviewed by: ziaee, zi
safe_eval.sh: safe_set_var use [:space:] if possible
Also use $ssv_extra$ssv_only as the default for $ssv_only has '-'
which must be last in the character class.
sctp: hold tcp lock when calling sctp_calc_rwnd()
This was done in all code paths except one. Fix this to avoid
race conditions.
Reported by: syzbot+2e2dc35c0e24a74663a7 at syzkaller.appspotmail.com
Reviewed by: tuexen
MFC after: 1 week
MFC to: stable/14
MFC to: stable/15
safe_eval.sh: safe_set_var avoid positional args
Use options to set ssv_{allow,only,extra}
Improve the documentation.
Add a test harness for safe_set_var.
pfctl: remove the prototype of pfr_ina_define()
The function went when DIOCRINADEFINE was converted to netlink; pfctl
calls pfctl_ina_define() from libpfctl instead. Name that one in the
error message that pfctl_load_tables() prints when it fails.
Fixes: 219ce3063840 ("pf: convert DIOCRINADEFINE to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
libpfctl: Fix the counts returned by pfctl_ina_define()
The counts of a table definition were stored only if the caller's
variables already held a non-zero value, and read uninitialised ones
otherwise. pfctl_ina_define() passes the address of two uninitialised
locals and sums them up.
Reviewed by: kp
Fixes: 219ce3063840 ("pf: convert DIOCRINADEFINE to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60614
LinuxKPI: pci: first round of file cleanup
While the multiple sections of the file are mostly clearly separated
some bits were spread around.
Get the device methods array to the end of the file saving us a lot
of forward function delcarations and making it easier to rename them
to a common lkpi_ prefix instead of linux_ showing that they are file
local internal functions not part of any official LinuxKPI KPI.
Sort the various lkpi_pci_* bus attachment functions together,
followed by the lkpi_pci_iov_ ones. Then add the
pci_[un]register_driver* driver bits. This keeps the group
logically together.
For the PCI functions then group the pdev allocations and free/release
functions--for the two paths--together, giving them more homogeneous
names and add comments to some of them so it is more clear which
ones are shared ("common") and which ones belong to which code path.
[17 lines not shown]
LinuxKPI: pci: make internal variables file local
The only reason the internal lists and lock are shared seems to be
because the SYSINIT code was in linux_compat.c.
Migrate the three variables (pci_drivers, pci_devices, and pci_lock)
to linux_pci.c and make them file local.
While doing so adjust a few things:
(a) mark the various sections of the linux_pci.c file as we add new
SYSINIT code to the middle of the file. The file currently really
contains three parts.
(b) rename the variables by adding a lkpi_ prefix indicating that they
are part of our internal code and not part of the public KPI, and
to clearly distinguish them from any native PCI code upon which
we call as well.
(c) factor the locking code out into macros as we have often done in
various parts of the kernel to make the lock itself more opaque.
[6 lines not shown]
LinuxKPI: pci: cleanup lkpinew_pci_dev_release()
Factor out some cleanup routines from the device detach path so
we can re-use them here too.
Also clarifying that lkpinew_pci_dev_release() should only run
from the (*release) callback function means that we adjust our
other calls to what we had already envisioned in comments, to
go through the official pci_dev_put() path.
Compared to the device detach path, we have little chance to know
if we held the last reference and if the device is really gone or
not but in this case a later release would be fine (if it happens).
In contrast to the device detach path we cannot do the hack of
setting the .release callback to NULL and check upon return from
pci_dev_put() as in this case the pdev is freed.
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: dumbbell (before rebase for ac9c07a3e908 instead of D57430)
Differential Revision: https://reviews.freebsd.org/D57431
if_gre: Use OID_AUTO for the net.link.gre sysctl node
if_gre(4) registers net.link.gre with the static OID number IFT_TUNNEL.
That number is an interface type that several tunnel drivers share, not
one that belongs to gre(4). if_me(4) used it too, which made loading
both modules panic until 21f2245de219. Nothing addresses the node by
number, so use OID_AUTO as if_me(4) now does.
Suggested by: markj
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")
safe_eval.sh fix description of safe_set_var returns.
The description was out of sync wrt return values.
1. invalid var
2. invalid val
3. var not in allowed list
safe_eval.sh: add safe_set_var
Get the log message right!
Fix default allowed chars (untabify clobbered TAB)
Add a couple more : messages to help debugging.
safe_eval.sh add safe_var_set
safe_var_set can be used to safely handle var=val args from command line.
eg.
while :
do
case "$1" in
*=*) # eval "$1" can be very dangerous
# safe_var_set will only eval if
# both var and value are sane.
if ! safe_var_set "$1"; then
case "$?" in
1) echo invalid variable name;;
2) echo invalide value;;
3) echo variabel not allowed;;
esac
fi
shift
[5 lines not shown]
nfs_nfsdstate.c: Add an extra safety belt check for the backchannel
I do not think that xp_p2 can be NULL at this point,
but add an extra safety belt, just in case.
(cherry picked from commit a52c50b4b7c2652954ef1bd34710a4b1fc8ef391)
clnt_vc.c: Fix handling of broken TCP connections
After more than, I don't know, maybe 10k operations: mount, copy,
remove, verify and unmount cycles, one cp command hung in
close() / ncl_flush and never recovered. The machine and the mount
continued to work normally through a new connection, but the writes
using the old connection stayed frozen.
I did not understand exactly what happened. I traced what appears to
be the issue in the code. My current understanding is that
clnt_vc_soupcall() saw the EOF and woke the caller waiting for RPC
replies, but one caller remained blocked in sosend().
That thread continued holding a reference to the old client, preventing
it from being completely cleaned up.
The attached patch calls socantsendmore() when EOF is received, which
should wake the blocked sender and let the normal reconnect code replace
the connection.
(cherry picked from commit 49bec8c3dc58cf8e944f9bbbbea07e7e856ad897)
clnt_vc.c: Fix handling of backchannel xprt
When clnt_vc_destroy() is called, it might not be the
current connection. Without this patch, if it is not
the current connection, xp_p2 is set NULL and xprt is released
when it should not be released.
This patch adds a check for "current connection" to fix
the problem. Found during testing to the client RDMA code,
but could happen for TCP as well.
(cherry picked from commit 81a6514689cefdaa5c92b5539ae885ec8c6b3336)