From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Stringer Subject: [PATCH bpf-next] bpf: Fix dev pointer dereference from sk_skb Date: Fri, 12 Oct 2018 14:50:53 -0700 Message-ID: <20181012215053.17830-1-joe@wand.net.nz> Cc: netdev@vger.kernel.org, dan.carpenter@oracle.com, ast@kernel.org To: daniel@iogearbox.net Return-path: Received: from mail-qt1-f195.google.com ([209.85.160.195]:41724 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725765AbeJMFZ1 (ORCPT ); Sat, 13 Oct 2018 01:25:27 -0400 Received: by mail-qt1-f195.google.com with SMTP id l41-v6so15438339qtl.8 for ; Fri, 12 Oct 2018 14:51:00 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: Dan Carpenter reports: The patch 6acc9b432e67: "bpf: Add helper to retrieve socket in BPF" from Oct 2, 2018, leads to the following Smatch complaint: net/core/filter.c:4893 bpf_sk_lookup() error: we previously assumed 'skb->dev' could be null (see line 4885) Fix this issue by checking skb->dev before using it. Signed-off-by: Joe Stringer --- net/core/filter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 4bbc6567fcb8..b844761b5d4c 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4821,9 +4821,12 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = { static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple, struct sk_buff *skb, u8 family, u8 proto) { - int dif = skb->dev->ifindex; bool refcounted = false; struct sock *sk = NULL; + int dif = 0; + + if (skb->dev) + dif = skb->dev->ifindex; if (family == AF_INET) { __be32 src4 = tuple->ipv4.saddr; -- 2.17.1