Skip to content

Commit ebf6449

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 21156d0 commit ebf6449

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tools/bootconfig/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ static int load_xbc_file(const char *path, char **buf)
157157
if (fd < 0)
158158
return -errno;
159159
ret = fstat(fd, &stat);
160-
if (ret < 0)
161-
return -errno;
160+
if (ret < 0) {
161+
ret = -errno;
162+
close(fd);
163+
return ret;
164+
}
162165

163166
ret = load_xbc_fd(fd, buf, stat.st_size);
164167

0 commit comments

Comments
 (0)