linux/net
Johannes Berg d4e46a3d98 [MAC80211]: fix race conditions with keys
During receive processing, we select the key long before using it and
because there's no locking it is possible that we kfree() the key
after having selected it but before using it for crypto operations.
Obviously, this is bad.

Secondly, during transmit processing, there are two possible races: We
have a similar race between select_key() and using it for encryption,
but we also have a race here between select_key() and hardware
encryption (both when a key is removed.)

This patch solves these issues by using RCU: when a key is to be freed,
we first remove the pointer from the appropriate places (sdata->keys,
sdata->default_key, sta->key) using rcu_assign_pointer() and then
synchronize_rcu(). Then, we can safely kfree() the key and remove it
from the hardware. There's a window here where the hardware may still
be using it for decryption, but we can't work around that without having
two hardware callbacks, one to disable the key for RX and one to disable
it for TX; but the worst thing that will happen is that we receive a
packet decrypted that we don't find a key for any more and then drop it.

When we add a key, we first need to upload it to the hardware and then,
using rcu_assign_pointer() again, link it into our structures.

In the code using keys (TX/RX paths) we use rcu_dereference() to get the
key and enclose the whole tx/rx section in a rcu_read_lock() ...
rcu_read_unlock() block. Because we've uploaded the key to hardware
before linking it into internal structures, we can guarantee that it is
valid once get to into tx().

One possible race condition remains, however: when we have hardware
acceleration enabled and the driver shuts down the queues, we end up
queueing the frame. If now somebody removes the key, the key will be
removed from hwaccel and then then driver will be asked to encrypt the
frame with a key index that has been removed. Hence, drivers will need
to be aware that the hw_key_index they are passed might not be under
all circumstances. Most drivers will, however, simply ignore that
condition and encrypt the frame with the selected key anyway, this
only results in a frame being encrypted with a wrong key or dropped
(rightfully) because the key was not valid. There isn't much we can
do about it unless we want to walk the pending frame queue every time
a key is removed and remove all frames that used it.

This race condition, however, will most likely be solved once we add
multiqueue support to mac80211 because then frames will be queued
further up the stack instead of after being processed.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Michael Wu <flamingice@sourmilk.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-10 16:49:26 -07:00
..
9p 9p: fix bad error path in conversion routines 2007-08-23 10:25:05 -05:00
802 [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
8021q [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
appletalk [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
atm [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
ax25 [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
bluetooth [NET]: Make socket creation namespace safe. 2007-10-10 16:49:07 -07:00
bridge [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
core [NET]: Fix race when opening a proc file while a network namespace is exiting. 2007-10-10 16:49:22 -07:00
dccp [NET]: Make /proc/net per network namespace 2007-10-10 16:49:06 -07:00
decnet [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
econet [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
ethernet [NET] ethernet: optimize memcpy and memset 2007-10-10 16:48:26 -07:00
ieee80211 [NET]: Make /proc/net per network namespace 2007-10-10 16:49:06 -07:00
ipv4 [IPV4]: Convert rt_check_expire() from softirq processing to workqueue. 2007-10-10 16:49:25 -07:00
ipv6 [NETLINK]: Introduce nested and byteorder flag to netlink attribute 2007-10-10 16:49:16 -07:00
ipx [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
irda [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
iucv [NET]: Make socket creation namespace safe. 2007-10-10 16:49:07 -07:00
key [NET]: Make socket creation namespace safe. 2007-10-10 16:49:07 -07:00
lapb [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
llc [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
mac80211 [MAC80211]: fix race conditions with keys 2007-10-10 16:49:26 -07:00
netfilter [NET]: Disable netfilter sockopts when not in the initial network namespace 2007-10-10 16:49:13 -07:00
netlabel [NETLINK]: Introduce nested and byteorder flag to netlink attribute 2007-10-10 16:49:16 -07:00
netlink [NET]: Fix race when opening a proc file while a network namespace is exiting. 2007-10-10 16:49:22 -07:00
netrom [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
packet [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
rfkill [RFKILL]: Add support for ultrawideband 2007-10-10 16:49:23 -07:00
rose [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
rxrpc [NET]: Make socket creation namespace safe. 2007-10-10 16:49:07 -07:00
sched [NET_SCHED]: Cleanup L2T macros and handle oversized packets 2007-10-10 16:49:20 -07:00
sctp [SCTP] net/sctp/socket.c: make 3 variables static 2007-10-10 16:49:19 -07:00
sunrpc [NET]: Make /proc/net per network namespace 2007-10-10 16:49:06 -07:00
tipc [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
unix [NET]: Make socket creation namespace safe. 2007-10-10 16:49:07 -07:00
wanrouter [NET]: Make /proc/net per network namespace 2007-10-10 16:49:06 -07:00
wireless [NET]: Fix race when opening a proc file while a network namespace is exiting. 2007-10-10 16:49:22 -07:00
x25 [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
xfrm [NET]: Support multiple network namespaces with netlink 2007-10-10 16:49:09 -07:00
Kconfig 9p: Reorganization of 9p file system code 2007-07-14 15:13:40 -05:00
Makefile 9p: Reorganization of 9p file system code 2007-07-14 15:13:40 -05:00
TUNABLE
compat.c O_CLOEXEC for SCM_RIGHTS 2007-07-16 09:05:45 -07:00
nonet.c [PATCH] Make most file operations structs in fs/ const 2006-03-28 09:16:06 -08:00
socket.c [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
sysctl_net.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00