netlink: fix netlink_ack() extack race
authorJohannes Berg <johannes.berg@intel.com>
Mon, 16 Oct 2017 15:09:53 +0000 (17:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Nov 2017 10:30:36 +0000 (11:30 +0100)
commite9c2b9fd0a1efa1f14c0f5fc6fe656029a5fa3e5
treee008ddc13d9f60d051c89e8a442d399b7680936f
parentaa9ab97c4d79b29727344f9c77d673743bbe35cb
netlink: fix netlink_ack() extack race

[ Upstream commit 48044eb490be71c203e14dd89e8bae87209eab52 ]

It seems that it's possible to toggle NETLINK_F_EXT_ACK
through setsockopt() while another thread/CPU is building
a message inside netlink_ack(), which could then trigger
the WARN_ON()s I added since if it goes from being turned
off to being turned on between allocating and filling the
message, the skb could end up being too small.

Avoid this whole situation by storing the value of this
flag in a separate variable and using that throughout the
function instead.

Fixes: 2d4bc93368f5 ("netlink: extended ACK reporting")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netlink/af_netlink.c