Skip to contentSkip to conversation

Fix null pointer deference in nest_epollfd

PATCH In review Gaurav Singh 2 participants 3 messages Jun 18, 2020 – Jun 19, 2020 1 message not in the archive perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix null pointer deference in nest_epollfd

Add a NULL check for worker before dereferencing.

---
 tools/perf/bench/epoll-wait.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/bench/epoll-wait.c +3 -0
index 75dca9773186..42983eb7f82e 100644
@@ -239,6 +239,9 @@ static void *workerfn(void *arg)
 
 static void nest_epollfd(struct worker *w)
 {
+	if (!w)
+		return;
+
 	unsigned int i;
 	struct epoll_event ev;
 	int efd = multiq ? w->epollfd : epollfd;
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hello,

Quoted 2 lines · Gaurav Singh

Add a NULL check for worker before dereferencing.

Did you actually see a segfault due to this? It seems it's called with NULL only if multiq is false so there should not be a NULL dereference.

Quoted 11 lines
---
 tools/perf/bench/epoll-wait.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/bench/epoll-wait.c +0 -0
index 75dca9773186..42983eb7f82e 100644

tools/perf/bench/epoll-wait.c static void *workerfn(void *arg) · line 247

Quoted 9 lines
tools/perf/bench/epoll-wait.c +3 -0
@@ -239,6 +239,9 @@ static void *workerfn(void *arg)
 
 static void nest_epollfd(struct worker *w)
 {
+       if (!w)
+               return;
+
        unsigned int i;
        struct epoll_event ev;
        int efd = multiq ? w->epollfd : epollfd;

Maybe it's more intuitive to check w instead of multiq here.

Thanks
Namhyung

Quoted 3 lines

--
2.17.1

A message that is not in the archive (sent off-list or not yet received): CAFAFadA3rRQxw9nyGnhn7kshRfQ_2AN+d-eCwHF-HJ_bYfYVog@mail.gmail.com

maintainer
#3 lore raw
Quoted 2 lines · gaurav singh

multiqu is a static bool which is never assigned and nested is a static int (=0)

It's set by command line option (-m).

Thanks
Namhyung

Quoted 6 lines

and only assigned in nest_epollfd(). Hence,

        if (nested)
            nest_epollfd(NULL);

probably never gets executed.