Re: [syzbot] [PATCH] net: Fix the null pointer deference in nsim_setup_prog_hw_checks

From: syzbot
Date: Fri Nov 10 2023 - 12:44:23 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.

***

Subject: [PATCH] net: Fix the null pointer deference in nsim_setup_prog_hw_checks
Author: kdipendra88@xxxxxxxxx

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

Signed-off-by: Dipendra Khadka <kdipendra88@xxxxxxxxx>
---
drivers/net/netdevsim/bpf.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index f60eb97e3a62..e407efb0e3de 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -97,7 +97,8 @@ static void nsim_prog_set_loaded(struct bpf_prog *prog, bool loaded)
return;

state = prog->aux->offload->dev_priv;
- state->is_loaded = loaded;
+ if (state)
+ state->is_loaded = loaded;
}

static int
@@ -317,10 +318,12 @@ nsim_setup_prog_hw_checks(struct netdevsim *ns, struct netdev_bpf *bpf)
}

state = bpf->prog->aux->offload->dev_priv;
- if (WARN_ON(strcmp(state->state, "xlated"))) {
- NSIM_EA(bpf->extack, "offloading program in bad state");
- return -EINVAL;
- }
+ if (state) {
+ if (WARN_ON(strcmp(state->state, "xlated"))) {
+ NSIM_EA(bpf->extack, "offloading program in bad state");
+ return -EINVAL;
+ }
+ }
return 0;
}

--
2.34.1