Skip to contentSkip to conversation

Fixes the null pointer deferences in nsim_bpf

PATCH Superseded Dipendra Khadka 4 participants 5 messages Nov 10, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixes the null pointer deferences in nsim_bpf

Syzkaller found a null pointer dereference in nsim_bpf originating from the lack of a null check for state.

This patch fixes the issue by adding a check for state in two functions nsim_prog_set_loaded and nsim_setup_prog_hw_checks

---
 drivers/net/netdevsim/bpf.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/netdevsim/bpf.c +8 -5
index f60eb97e3a62..e407efb0e3de 100644
@@ -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;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · Dipendra Khadka

Syzkaller found a null pointer dereference in nsim_bpf originating from the lack of a null check for state.

This patch fixes the issue by adding a check for state in two functions nsim_prog_set_loaded and nsim_setup_prog_hw_checks

Please add a Fixes: tag, and remove this empty line, thanks.

Quoted 40 lines
---
 drivers/net/netdevsim/bpf.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/netdevsim/bpf.c +8 -6
index f60eb97e3a62..e407efb0e3de 100644
@@ -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

#2 lore raw

PATCH v2 1/1 Fixes the null pointer deferences in nsim_bpf

In reply to Dipendra Khadka

Syzkaller found a null pointer dereference in nsim_bpf originating from the lack of a null check for state.

This patch fixes the issue by adding a check for state
in two functions nsim_prog_set_loaded() and nsim_setup_prog_hw_checks()

Reported-by [email protected]
Fixes 31d3ad832948 ("netdevsim: add bpf offload support")
---
 drivers/net/netdevsim/bpf.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/netdevsim/bpf.c +7 -4
index f60eb97e3a62..5d755da3c736 100644
@@ -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,9 +318,11 @@ 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;
 }
Signature · 1 line
2.34.1
maintainer
#3 lore raw
Quoted 9 lines · On Fri, 10 Nov 2023 11:18:23 +0000 Dipendra Khadka wrote:

Syzkaller found a null pointer dereference in nsim_bpf originating from the lack of a null check for state.

This patch fixes the issue by adding a check for state
in two functions nsim_prog_set_loaded() and nsim_setup_prog_hw_checks()

Reported-by [email protected]
Fixes 31d3ad832948 ("netdevsim: add bpf offload support")

Don't think so. It's probably due to Stan's extensions / reuse of the offload infra.

Please put more effort into figuring out when and why this started happening. Describe your findings in the commit message.

Current patch looks too much like a bandaid.

Before you repost read:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html

Signature · 3 lines
pw-bot: cr
pv-bot: syz
pv-bot: 24h
#4 lore raw
Quoted 14 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 10 Nov 2023 11:18:23 +0000 Dipendra Khadka wrote:

Syzkaller found a null pointer dereference in nsim_bpf originating from the lack of a null check for state.

This patch fixes the issue by adding a check for state
in two functions nsim_prog_set_loaded() and nsim_setup_prog_hw_checks()

Reported-by [email protected]
Fixes 31d3ad832948 ("netdevsim: add bpf offload support")

Don't think so. It's probably due to Stan's extensions / reuse of the offload infra.

Quoted 7 lines

Please put more effort into figuring out when and why this started happening. Describe your findings in the commit message.

Current patch looks too much like a bandaid.

Before you repost read:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html

I agree, I have a similar suspicion for the same report on the bpf list [0].

0: https://lore.kernel.org/bpf/[email protected]/