diff options
author | Nicolai Stange <nstange@suse.de> | 2018-01-08 09:54:44 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-09 11:59:16 -0500 |
commit | 20b50d79974ea3192e8c3ab7faf4e536e5f14d8f (patch) | |
tree | c25a3de78f24e225e238e1ffe3eebb193f5da3f0 | |
parent | 3dc2fa47549aca71773afdd12a78d31802bb22b4 (diff) |
net: ipv4: emulate READ_ONCE() on ->hdrincl bit-field in raw_sendmsg()
Commit 8f659a03a0ba ("net: ipv4: fix for a race condition in
raw_sendmsg") fixed the issue of possibly inconsistent ->hdrincl handling
due to concurrent updates by reading this bit-field member into a local
variable and using the thus stabilized value in subsequent tests.
However, aforementioned commit also adds the (correct) comment that
/* hdrincl should be READ_ONCE(inet->hdrincl)
* but READ_ONCE() doesn't work with bit fields
*/
because as it stands, the compiler is free to shortcut or even eliminate
the local variable at its will.
Note that I have not seen anything like this happening in reality and thus,
the concern is a theoretical one.
However, in order to be on the safe side, emulate a READ_ONCE() on the
bit-field by doing it on the local 'hdrincl' variable itself:
int hdrincl = inet->hdrincl;
hdrincl = READ_ONCE(hdrincl);
This breaks the chain in the sense that the compiler is not allowed
to replace subsequent reads from hdrincl with reloads from inet->hdrincl.
Fixes: 8f659a03a0ba ("net: ipv4: fix for a race condition in raw_sendmsg")
Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/raw.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 125c1eab3eaa..5e570aa9e43b 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -520,9 +520,11 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
520 | goto out; | 520 | goto out; |
521 | 521 | ||
522 | /* hdrincl should be READ_ONCE(inet->hdrincl) | 522 | /* hdrincl should be READ_ONCE(inet->hdrincl) |
523 | * but READ_ONCE() doesn't work with bit fields | 523 | * but READ_ONCE() doesn't work with bit fields. |
524 | * Doing this indirectly yields the same result. | ||
524 | */ | 525 | */ |
525 | hdrincl = inet->hdrincl; | 526 | hdrincl = inet->hdrincl; |
527 | hdrincl = READ_ONCE(hdrincl); | ||
526 | /* | 528 | /* |
527 | * Check the flags. | 529 | * Check the flags. |
528 | */ | 530 | */ |