Skip to content
/ linux Public

Commit ef6e648

Browse files
techyguyperplexablegregkh
authored andcommitted
tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
[ Upstream commit 3b2c2ab ] 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: 950313e ("tools: bootconfig: Add bootconfig command") Signed-off-by: Josh Law <objecting@objecting.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d03e8c2 commit ef6e648

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/bootconfig/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ static int load_xbc_file(const char *path, char **buf)
162162
if (fd < 0)
163163
return -errno;
164164
ret = fstat(fd, &stat);
165-
if (ret < 0)
166-
return -errno;
165+
if (ret < 0) {
166+
ret = -errno;
167+
close(fd);
168+
return ret;
169+
}
167170

168171
ret = load_xbc_fd(fd, buf, stat.st_size);
169172

0 commit comments

Comments
 (0)