]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
authorJosh Law <objecting@objecting.org>
Wed, 18 Mar 2026 23:43:06 +0000 (08:43 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 18 Mar 2026 23:43:06 +0000 (08:43 +0900)
If fstat() fails after open() succeeds, the function returns without
closing the file descriptor. Also preserve errno across close(), since
close() may overwrite it before the error is returned.

Link: https://lore.kernel.org/all/20260318155847.78065-3-objecting@objecting.org/
Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Signed-off-by: Josh Law <objecting@objecting.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
tools/bootconfig/main.c

index 55d59ed507d541e54cf2c481246326b959dd7208..643f707b8f1da1838fb828f8478c7db4800cc855 100644 (file)
@@ -162,8 +162,11 @@ static int load_xbc_file(const char *path, char **buf)
        if (fd < 0)
                return -errno;
        ret = fstat(fd, &stat);
-       if (ret < 0)
-               return -errno;
+       if (ret < 0) {
+               ret = -errno;
+               close(fd);
+               return ret;
+       }
 
        ret = load_xbc_fd(fd, buf, stat.st_size);