Skip to content

Commit 67e89ac

Browse files
joestringerAlexei Starovoitov
authored andcommitted
bpf: Fix dev pointer dereference from sk_skb
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>
1 parent 1ae80cf commit 67e89ac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/core/filter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4821,9 +4821,12 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = {
48214821
static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
48224822
struct sk_buff *skb, u8 family, u8 proto)
48234823
{
4824-
int dif = skb->dev->ifindex;
48254824
bool refcounted = false;
48264825
struct sock *sk = NULL;
4826+
int dif = 0;
4827+
4828+
if (skb->dev)
4829+
dif = skb->dev->ifindex;
48274830

48284831
if (family == AF_INET) {
48294832
__be32 src4 = tuple->ipv4.saddr;

0 commit comments

Comments
 (0)