mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-22 23:04:43 +00:00
modpost: fix potential mmap'ed file overrun in get_src_version()
I do not know how reliably this function works, but it looks dangerous to me. strchr(sources, '\n'); ... continues searching until it finds '\n' or it reaches the '\0' terminator. In other words, 'sources' should be a null-terminated string. However, grab_file() just mmaps a file, so 'sources' is not terminated with null byte. If the file does not contain '\n' at all, strchr() will go beyond the mmap'ed memory. Use read_text_file(), which loads the file content into a malloc'ed buffer, appending null byte. Here we are interested only in the first line of *.mod files. Use get_line() helper to get the first line. This also makes missing *.mod file a fatal error. Commit4be40e2223
("kbuild: do not emit src version warning for non-modules") ignored missing *.mod files. I do not fully understand what that commit addressed, but commit91341d4b2c
("kbuild: introduce new option to enhance section mismatch analysis") introduced partial section checks by using modpost. built-in.o was parsed by modpost. Even modules had a problem because *.mod files were created after the modpost check. Commitb7dca6dd1e
("kbuild: create *.mod with full directory path and remove MODVERDIR") stopped doing that. Now that modpost is only invoked after the directory descend, *.mod files should always exist at the modpost stage. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
parent
ac5100f543
commit
f531c1b5de
1 changed files with 11 additions and 17 deletions
|
@ -392,40 +392,34 @@ out:
|
||||||
/* Calc and record src checksum. */
|
/* Calc and record src checksum. */
|
||||||
void get_src_version(const char *modname, char sum[], unsigned sumlen)
|
void get_src_version(const char *modname, char sum[], unsigned sumlen)
|
||||||
{
|
{
|
||||||
void *file;
|
char *buf, *pos, *firstline;
|
||||||
unsigned long len;
|
|
||||||
struct md4_ctx md;
|
struct md4_ctx md;
|
||||||
char *sources, *end, *fname;
|
char *fname;
|
||||||
char filelist[PATH_MAX + 1];
|
char filelist[PATH_MAX + 1];
|
||||||
|
|
||||||
/* objects for a module are listed in the first line of *.mod file. */
|
/* objects for a module are listed in the first line of *.mod file. */
|
||||||
snprintf(filelist, sizeof(filelist), "%.*smod",
|
snprintf(filelist, sizeof(filelist), "%.*smod",
|
||||||
(int)strlen(modname) - 1, modname);
|
(int)strlen(modname) - 1, modname);
|
||||||
|
|
||||||
file = grab_file(filelist, &len);
|
buf = read_text_file(filelist);
|
||||||
if (!file)
|
|
||||||
/* not a module or .mod file missing - ignore */
|
|
||||||
return;
|
|
||||||
|
|
||||||
sources = file;
|
pos = buf;
|
||||||
|
firstline = get_line(&pos);
|
||||||
end = strchr(sources, '\n');
|
if (!firstline) {
|
||||||
if (!end) {
|
|
||||||
warn("bad ending versions file for %s\n", modname);
|
warn("bad ending versions file for %s\n", modname);
|
||||||
goto release;
|
goto free;
|
||||||
}
|
}
|
||||||
*end = '\0';
|
|
||||||
|
|
||||||
md4_init(&md);
|
md4_init(&md);
|
||||||
while ((fname = strsep(&sources, " ")) != NULL) {
|
while ((fname = strsep(&firstline, " "))) {
|
||||||
if (!*fname)
|
if (!*fname)
|
||||||
continue;
|
continue;
|
||||||
if (!(is_static_library(fname)) &&
|
if (!(is_static_library(fname)) &&
|
||||||
!parse_source_files(fname, &md))
|
!parse_source_files(fname, &md))
|
||||||
goto release;
|
goto free;
|
||||||
}
|
}
|
||||||
|
|
||||||
md4_final_ascii(&md, sum, sumlen);
|
md4_final_ascii(&md, sum, sumlen);
|
||||||
release:
|
free:
|
||||||
release_file(file, len);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue