Skip to content

Commit

Permalink
bpf: Fix dev pointer dereference from sk_skb
Browse files Browse the repository at this point in the history
Dan Carpenter reports:

The patch 6acc9b4: "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 <joe@wand.net.nz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Joe Stringer authored and Alexei Starovoitov committed Oct 14, 2018
1 parent 1ae80cf commit 67e89ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 67e89ac

Please sign in to comment.