Thread (38 messages) 38 messages, 6 authors, 2017-04-25

Re: [PATCH v3 3/7] kprobes: validate the symbol name length

From: Naveen N. Rao <hidden>
Date: 2017-04-20 07:21:09
Also in: lkml

Excerpts from Michael Ellerman's message of April 20, 2017 11:38:
"Naveen N. Rao" [off-list ref] writes:
=20
quoted
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 6a128f3a7ed1..bb86681c8a10 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1382,6 +1382,28 @@ bool within_kprobe_blacklist(unsigned long addr)
 	return false;
 }
=20
+bool is_valid_kprobe_symbol_name(const char *name)
+{
+	size_t sym_len;
+	char *s;
+
+	s =3D strchr(name, ':');
+	if (s) {
+		sym_len =3D strnlen(s+1, KSYM_NAME_LEN);
+		if (sym_len <=3D 0 || sym_len >=3D KSYM_NAME_LEN)
+			return false;
+		sym_len =3D (size_t)(s - name);
+		if (sym_len <=3D 0 || sym_len >=3D MODULE_NAME_LEN)
+			return false;
+	} else {
+		sym_len =3D strnlen(name, MODULE_NAME_LEN);
+		if (sym_len <=3D 0 || sym_len >=3D MODULE_NAME_LEN)
+			return false;
+	}
=20
I think this is probably more elaborate than it needs to be.
=20
Why not just check the string is <=3D (MODULE_NAME_LEN + KSYM_NAME_LEN) ?
Yes, that would be sufficient for now.

It's probably just me being paranoid, but I felt it's good to have=20
stricter checks for user-provided strings, to guard against future=20
changes to how we process this.

- Naveen

=
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help