sock: fix possible NULL sk dereference in __skb_tstamp_tx
authorWillem de Bruijn <willemb@google.com>
Wed, 11 Mar 2015 19:43:55 +0000 (15:43 -0400)
committerDavid S. Miller <davem@davemloft.net>
Thu, 12 Mar 2015 04:09:55 +0000 (00:09 -0400)
Test that sk != NULL before reading sk->sk_tsflags.

Fixes: 49ca0d8bfaf3 ("net-timestamp: no-payload option")
Reported-by: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/skbuff.c

index 434e78e5254d093be35c60487df8bc25b043b9cb..8e4ac97c84775f15c786020ff87a2ef22a8dbac8 100644 (file)
@@ -3733,9 +3733,13 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
                     struct sock *sk, int tstype)
 {
        struct sk_buff *skb;
-       bool tsonly = sk->sk_tsflags & SOF_TIMESTAMPING_OPT_TSONLY;
+       bool tsonly;
 
-       if (!sk || !skb_may_tx_timestamp(sk, tsonly))
+       if (!sk)
+               return;
+
+       tsonly = sk->sk_tsflags & SOF_TIMESTAMPING_OPT_TSONLY;
+       if (!skb_may_tx_timestamp(sk, tsonly))
                return;
 
        if (tsonly)