]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mips/vdso: Fix resource leaks in genvdso.c
authorPeng Fan <fanpeng@loongson.cn>
Tue, 14 Jul 2020 12:30:18 +0000 (20:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:26:45 +0000 (11:26 +0200)
[ Upstream commit a859647b4e6bfeb192284d27d24b6a0c914cae1d ]

Close "fd" before the return of map_vdso() and close "out_file"
in main().

Signed-off-by: Peng Fan <fanpeng@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/mips/vdso/genvdso.c

index b66b6b1c4aeb9298d8ee4d30b7db9433f7df5f29..8f581a2c8578b377a5776b10a72dd790e2da46eb 100644 (file)
@@ -122,6 +122,7 @@ static void *map_vdso(const char *path, size_t *_size)
        if (fstat(fd, &stat) != 0) {
                fprintf(stderr, "%s: Failed to stat '%s': %s\n", program_name,
                        path, strerror(errno));
+               close(fd);
                return NULL;
        }
 
@@ -130,6 +131,7 @@ static void *map_vdso(const char *path, size_t *_size)
        if (addr == MAP_FAILED) {
                fprintf(stderr, "%s: Failed to map '%s': %s\n", program_name,
                        path, strerror(errno));
+               close(fd);
                return NULL;
        }
 
@@ -139,6 +141,7 @@ static void *map_vdso(const char *path, size_t *_size)
        if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0) {
                fprintf(stderr, "%s: '%s' is not an ELF file\n", program_name,
                        path);
+               close(fd);
                return NULL;
        }
 
@@ -150,6 +153,7 @@ static void *map_vdso(const char *path, size_t *_size)
        default:
                fprintf(stderr, "%s: '%s' has invalid ELF class\n",
                        program_name, path);
+               close(fd);
                return NULL;
        }
 
@@ -161,6 +165,7 @@ static void *map_vdso(const char *path, size_t *_size)
        default:
                fprintf(stderr, "%s: '%s' has invalid ELF data order\n",
                        program_name, path);
+               close(fd);
                return NULL;
        }
 
@@ -168,15 +173,18 @@ static void *map_vdso(const char *path, size_t *_size)
                fprintf(stderr,
                        "%s: '%s' has invalid ELF machine (expected EM_MIPS)\n",
                        program_name, path);
+               close(fd);
                return NULL;
        } else if (swap_uint16(ehdr->e_type) != ET_DYN) {
                fprintf(stderr,
                        "%s: '%s' has invalid ELF type (expected ET_DYN)\n",
                        program_name, path);
+               close(fd);
                return NULL;
        }
 
        *_size = stat.st_size;
+       close(fd);
        return addr;
 }
 
@@ -280,10 +288,12 @@ int main(int argc, char **argv)
        /* Calculate and write symbol offsets to <output file> */
        if (!get_symbols(dbg_vdso_path, dbg_vdso)) {
                unlink(out_path);
+               fclose(out_file);
                return EXIT_FAILURE;
        }
 
        fprintf(out_file, "};\n");
+       fclose(out_file);
 
        return EXIT_SUCCESS;
 }