diff options
| author | Josh Law <objecting@objecting.org> | 2026-03-19 08:43:06 +0900 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-03-25 11:06:10 +0100 |
| commit | 2cf5eff223fc9b720690c16ab763a00788e85c4b (patch) | |
| tree | f0abcb6be86d43c3f66ce300303318e93bb3c547 | |
| parent | c1bfc25d62d83160799bd731bcce5d6ab8dfd2a0 (diff) | |
tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
[ Upstream commit 3b2c2ab4ceb82af484310c3087541eab00ea288b ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rw-r--r-- | tools/bootconfig/main.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 8a48cc2536f5..32cf48f2da9a 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -157,8 +157,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); |
