Skip to content

Commit e9c2b9f

Browse files
jmberg-intelgregkh
authored andcommitted
netlink: fix netlink_ack() extack race
[ Upstream commit 48044eb ] 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: 2d4bc93 ("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>
1 parent aa9ab97 commit e9c2b9f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/netlink/af_netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
22992299
size_t tlvlen = 0;
23002300
struct netlink_sock *nlk = nlk_sk(NETLINK_CB(in_skb).sk);
23012301
unsigned int flags = 0;
2302+
bool nlk_has_extack = nlk->flags & NETLINK_F_EXT_ACK;
23022303

23032304
/* Error messages get the original request appened, unless the user
23042305
* requests to cap the error message, and get extra error data if
@@ -2309,7 +2310,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
23092310
payload += nlmsg_len(nlh);
23102311
else
23112312
flags |= NLM_F_CAPPED;
2312-
if (nlk->flags & NETLINK_F_EXT_ACK && extack) {
2313+
if (nlk_has_extack && extack) {
23132314
if (extack->_msg)
23142315
tlvlen += nla_total_size(strlen(extack->_msg) + 1);
23152316
if (extack->bad_attr)
@@ -2318,8 +2319,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
23182319
} else {
23192320
flags |= NLM_F_CAPPED;
23202321

2321-
if (nlk->flags & NETLINK_F_EXT_ACK &&
2322-
extack && extack->cookie_len)
2322+
if (nlk_has_extack && extack && extack->cookie_len)
23232323
tlvlen += nla_total_size(extack->cookie_len);
23242324
}
23252325

@@ -2347,7 +2347,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
23472347
errmsg->error = err;
23482348
memcpy(&errmsg->msg, nlh, payload > sizeof(*errmsg) ? nlh->nlmsg_len : sizeof(*nlh));
23492349

2350-
if (nlk->flags & NETLINK_F_EXT_ACK && extack) {
2350+
if (nlk_has_extack && extack) {
23512351
if (err) {
23522352
if (extack->_msg)
23532353
WARN_ON(nla_put_string(skb, NLMSGERR_ATTR_MSG,

0 commit comments

Comments
 (0)