[DTrace-devel] [PATCH] Check pid==0 for uaddr2str
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Mar 16 16:28:31 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
If dtrace_uaddr2str() is given pid==0, it will try to look up the
pid, get a NULL pointer back, dereference it, and cause dtrace to
segfault.
Add a check for pid==0.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_subr.c | 2 +-
test/unittest/ustack/tst.uaddr-pid0.d | 17 +++++++++++++++++
test/unittest/ustack/tst.uaddr-pid0.r | 1 +
test/unittest/ustack/tst.ufunc-pid0.d | 17 +++++++++++++++++
test/unittest/ustack/tst.ufunc-pid0.r | 1 +
test/unittest/ustack/tst.usym-pid0.d | 17 +++++++++++++++++
test/unittest/ustack/tst.usym-pid0.r | 1 +
7 files changed, 55 insertions(+), 1 deletion(-)
create mode 100644 test/unittest/ustack/tst.uaddr-pid0.d
create mode 100644 test/unittest/ustack/tst.uaddr-pid0.r
create mode 100644 test/unittest/ustack/tst.ufunc-pid0.d
create mode 100644 test/unittest/ustack/tst.ufunc-pid0.r
create mode 100644 test/unittest/ustack/tst.usym-pid0.d
create mode 100644 test/unittest/ustack/tst.usym-pid0.r
diff --git a/libdtrace/dt_subr.c b/libdtrace/dt_subr.c
index 3a93eed7..bff0497a 100644
--- a/libdtrace/dt_subr.c
+++ b/libdtrace/dt_subr.c
@@ -888,7 +888,7 @@ dtrace_uaddr2str(dtrace_hdl_t *dtp, pid_t pid, uint64_t addr, char *str,
pid = dt_proc_grab_lock(dtp, pid, DTRACE_PROC_WAITING |
DTRACE_PROC_SHORTLIVED);
- if (pid < 0) {
+ if (pid <= 0) {
snprintf(c, sizeof(c), "0x%llx", (unsigned long long)addr);
return dt_string2str(c, str, nbytes);
}
diff --git a/test/unittest/ustack/tst.uaddr-pid0.d b/test/unittest/ustack/tst.uaddr-pid0.d
new file mode 100644
index 00000000..263a7ca9
--- /dev/null
+++ b/test/unittest/ustack/tst.uaddr-pid0.d
@@ -0,0 +1,17 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/* Without a trigger, pid will be 0, but we should not segfault. */
+
+#pragma D option quiet
+
+tick-1
+/pid == $target/
+{
+ uaddr(ucaller);
+ exit(0);
+}
diff --git a/test/unittest/ustack/tst.uaddr-pid0.r b/test/unittest/ustack/tst.uaddr-pid0.r
new file mode 100644
index 00000000..a8e68f4e
--- /dev/null
+++ b/test/unittest/ustack/tst.uaddr-pid0.r
@@ -0,0 +1 @@
+ {ptr}
diff --git a/test/unittest/ustack/tst.ufunc-pid0.d b/test/unittest/ustack/tst.ufunc-pid0.d
new file mode 100644
index 00000000..f076782a
--- /dev/null
+++ b/test/unittest/ustack/tst.ufunc-pid0.d
@@ -0,0 +1,17 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/* Without a trigger, pid will be 0, but we should not segfault. */
+
+#pragma D option quiet
+
+tick-1
+/pid == $target/
+{
+ ufunc(ucaller);
+ exit(0);
+}
diff --git a/test/unittest/ustack/tst.ufunc-pid0.r b/test/unittest/ustack/tst.ufunc-pid0.r
new file mode 100644
index 00000000..a8e68f4e
--- /dev/null
+++ b/test/unittest/ustack/tst.ufunc-pid0.r
@@ -0,0 +1 @@
+ {ptr}
diff --git a/test/unittest/ustack/tst.usym-pid0.d b/test/unittest/ustack/tst.usym-pid0.d
new file mode 100644
index 00000000..d2f5ec5d
--- /dev/null
+++ b/test/unittest/ustack/tst.usym-pid0.d
@@ -0,0 +1,17 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/* Without a trigger, pid will be 0, but we should not segfault. */
+
+#pragma D option quiet
+
+tick-1
+/pid == $target/
+{
+ usym(ucaller);
+ exit(0);
+}
diff --git a/test/unittest/ustack/tst.usym-pid0.r b/test/unittest/ustack/tst.usym-pid0.r
new file mode 100644
index 00000000..a8e68f4e
--- /dev/null
+++ b/test/unittest/ustack/tst.usym-pid0.r
@@ -0,0 +1 @@
+ {ptr}
--
2.18.4
More information about the DTrace-devel
mailing list