Skip to content

Commit

Permalink
ipv6: use READ_ONCE() for inet->hdrincl as in ipv4
Browse files Browse the repository at this point in the history
commit 59e3e4b upstream.

As it was done in commit 8f659a0 ("net: ipv4: fix for a race
condition in raw_sendmsg") and commit 20b50d7 ("net: ipv4: emulate
READ_ONCE() on ->hdrincl bit-field in raw_sendmsg()") for ipv4, copy the
value of inet->hdrincl in a local variable, to avoid introducing a race
condition in the next commit.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Olivier Matz authored and Greg Kroah-Hartman committed May 5, 2020
1 parent d44ee54 commit 9e68a66
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
int hlimit = -1;
int tclass = -1;
int dontfrag = -1;
int hdrincl;
u16 proto;
int err;

Expand All @@ -770,6 +771,13 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (msg->msg_flags & MSG_OOB)
return -EOPNOTSUPP;

/* hdrincl should be READ_ONCE(inet->hdrincl)
* but READ_ONCE() doesn't work with bit fields.
* Doing this indirectly yields the same result.
*/
hdrincl = inet->hdrincl;
hdrincl = READ_ONCE(hdrincl);

/*
* Get and verify the address.
*/
Expand Down Expand Up @@ -878,7 +886,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
fl6.flowi6_oif = np->ucast_oif;
security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));

if (inet->hdrincl)
if (hdrincl)
fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;

dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
Expand All @@ -899,7 +907,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
goto do_confirm;

back_from_confirm:
if (inet->hdrincl)
if (hdrincl)
err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags);
else {
lock_sock(sk);
Expand Down

0 comments on commit 9e68a66

Please sign in to comment.