From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>
Subject: [PATCH] udp: fix a race in encap_rcv handling
Date: Tue, 01 Nov 2011 23:56:59 +0100 [thread overview]
Message-ID: <1320188219.4728.7.camel@edumazet-laptop> (raw)
In-Reply-To: <CAKpUy7Z5KOfHbKfBp-qg+77cED=OxUAkm2P4pQacHaHKmKBQpw@mail.gmail.com>
udp_queue_rcv_skb() has a possible race in encap_rcv handling, since
this pointer can be changed anytime.
We should use ACCESS_ONCE() to close the race.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/ipv4/udp.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index ebaa96b..15b50df 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1397,6 +1397,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
nf_reset(skb);
if (up->encap_type) {
+ int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
+
/*
* This is an encapsulation socket so pass the skb to
* the socket's udp_encap_rcv() hook. Otherwise, just
@@ -1409,11 +1411,11 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
*/
/* if we're overly short, let UDP handle it */
- if (skb->len > sizeof(struct udphdr) &&
- up->encap_rcv != NULL) {
+ encap_rcv = ACCESS_ONCE(up->encap_rcv);
+ if (skb->len > sizeof(struct udphdr) && encap_rcv != NULL) {
int ret;
- ret = (*up->encap_rcv)(sk, skb);
+ ret = encap_rcv(sk, skb);
if (ret <= 0) {
UDP_INC_STATS_BH(sock_net(sk),
UDP_MIB_INDATAGRAMS,
next prev parent reply other threads:[~2011-11-01 22:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-01 22:00 PROBLEM: pppol2tp over pppoe NULL pointer dereference Misha Labjuk
2011-11-01 22:35 ` Eric Dumazet
2011-11-02 5:04 ` Misha Labjuk
2011-11-02 7:07 ` Eric Dumazet
2011-11-02 15:54 ` Jorge Boncompte [DTI2]
2011-11-02 22:35 ` Misha Labjuk
2011-11-02 22:53 ` [PATCH] l2tp: fix l2tp_recv_dequeue() Eric Dumazet
2011-11-03 6:50 ` Eric Dumazet
2011-11-03 8:47 ` PROBLEM: pppol2tp over pppoe NULL pointer dereference Eric Dumazet
2011-11-03 22:02 ` David Miller
2011-11-01 22:56 ` Eric Dumazet [this message]
2011-11-02 4:51 ` [PATCH] udp: fix a race in encap_rcv handling David Miller
2011-11-01 23:58 ` PROBLEM: pppol2tp over pppoe NULL pointer dereference Eric Dumazet
2011-11-05 2:28 ` David Miller
2011-11-05 7:40 ` Eric Dumazet
2011-11-08 19:00 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1320188219.4728.7.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox