Re: [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to module names
[email protected] Mon, 03 Aug 2026 03:37:11 +0000
| Newsgroups | org.kernel.vger.linux-modules |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(= s) to consider: - [Medium] normalize_modname() returns an interior pointer, causing the ori= ginal heap allocation base pointer to be lost in read_exports() and __find_= modname(). -- --- Patch [2]: [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to= module names --- commit 8f5aadae3b846aa3bb569cfc55ef783d4449690f Author: Joe Lawrence <[email protected]> objtool/klp: Normalize Module.symvers paths to module names This commit normalizes Module.symvers object paths to runtime module names for exported symbols to prevent a crash during livepatch loading. It extrac= ts the module name processing into a shared normalize_modname() helper. > diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c > index aeb99d572300c..15d37d955af0e 100644 > --- a/tools/objtool/klp-diff.c > +++ b/tools/objtool/klp-diff.c > @@ -83,6 +83,35 @@ static char *escape_str(const char *orig) [ ... ] > +static char *normalize_modname(char *name) > +{ > + char *slash =3D strrchr(name, '/'); > + > + if (slash) > + name =3D slash + 1; > + > + for (char *c =3D name; *c; c++) { > + if (*c =3D=3D '-') > + *c =3D '_'; > + else if (*c =3D=3D '.') { > + *c =3D '\0'; > + break; > + } > + } > + return name; > +} > + > static int read_exports(void) > { [ ... ] > @@ -150,6 +179,9 @@ static int read_exports(void) > return -1; > } > =20 > + if (strcmp(export->mod, "vmlinux")) > + export->mod =3D normalize_modname(export->mod); > + [Severity: Medium] Does this assignment leak the original pointer returned by strdup()? Looking at read_exports(), export->mod is allocated via strdup() right before this check: export->mod =3D strdup(mod); if (!export->mod) { ERROR_GLIBC("strdup"); return -1; } if (strcmp(export->mod, "vmlinux")) export->mod =3D normalize_modname(export->mod); When processing module paths with a slash, normalize_modname() returns an interior pointer (slash + 1). If this offset pointer overwrites export->mod, the original base address from strdup() is permanently lost.=20 While objtool often relies on process termination for cleanup, if these strings are ever freed later, passing an interior pointer to free() will cause an invalid free crash. Could this be avoided by shifting the string contents in-place with memmove() instead? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1785727106.gi= [email protected]?part=3D2