public inbox for live-patching@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, Song Liu <song@kernel.org>,
	Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
	Petr Mladek <pmladek@suse.com>
Subject: [PATCH v4 02/12] objtool/klp: fix mkstemp() failure with long paths
Date: Tue, 10 Mar 2026 16:37:41 -0400	[thread overview]
Message-ID: <20260310203751.1479229-3-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260310203751.1479229-1-joe.lawrence@redhat.com>

The elf_create_file() function fails with EINVAL when the build directory
path is long enough to truncate the "XXXXXX" suffix in the 256-byte
tmp_name buffer.

Simplify the code to remove the unnecessary dirname()/basename() split
and concatenation.  Instead, allocate the exact number of bytes needed for
the path.

Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
 tools/objtool/elf.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 3da90686350d..2ffe3ebfbe37 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -16,7 +16,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <libgen.h>
 #include <ctype.h>
 #include <linux/align.h>
 #include <linux/kernel.h>
@@ -1189,7 +1188,7 @@ struct elf *elf_open_read(const char *name, int flags)
 struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name)
 {
 	struct section *null, *symtab, *strtab, *shstrtab;
-	char *dir, *base, *tmp_name;
+	char *tmp_name;
 	struct symbol *sym;
 	struct elf *elf;
 
@@ -1203,29 +1202,13 @@ struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name)
 
 	INIT_LIST_HEAD(&elf->sections);
 
-	dir = strdup(name);
-	if (!dir) {
-		ERROR_GLIBC("strdup");
-		return NULL;
-	}
-
-	dir = dirname(dir);
-
-	base = strdup(name);
-	if (!base) {
-		ERROR_GLIBC("strdup");
-		return NULL;
-	}
-
-	base = basename(base);
-
-	tmp_name = malloc(256);
+	tmp_name = malloc(strlen(name) + 8);
 	if (!tmp_name) {
 		ERROR_GLIBC("malloc");
 		return NULL;
 	}
 
-	snprintf(tmp_name, 256, "%s/%s.XXXXXX", dir, base);
+	sprintf(tmp_name, "%s.XXXXXX", name);
 
 	elf->fd = mkstemp(tmp_name);
 	if (elf->fd == -1) {
-- 
2.53.0


  parent reply	other threads:[~2026-03-10 20:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 20:37 [PATCH v4 00/12] livepatch-klp-build: small fixups and enhancements Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 01/12] objtool/klp: fix data alignment in __clone_symbol() Joe Lawrence
2026-03-10 20:37 ` Joe Lawrence [this message]
2026-03-10 20:37 ` [PATCH v4 03/12] livepatch/klp-build: support patches that add/remove files Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 04/12] livepatch/klp-build: switch to GNU patch and recountdiff Joe Lawrence
2026-03-11 22:20   ` Song Liu
2026-03-10 20:37 ` [PATCH v4 05/12] livepatch/klp-build: add grep-override function Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 06/12] livepatch/klp-build: add Makefile with check target Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 07/12] livepatch/klp-build: fix shellcheck complaints Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 08/12] livepatch/klp-build: improve short-circuit validation Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 09/12] livepatch/klp-build: Fix inconsistent kernel version Joe Lawrence
2026-03-11 22:23   ` Song Liu
2026-03-10 20:37 ` [PATCH v4 10/12] livepatch/klp-build: provide friendlier error messages Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 11/12] livepatch/klp-build: add terminal color output Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 12/12] livepatch/klp-build: report patch validation fuzz Joe Lawrence
2026-03-11 22:22   ` Song Liu
2026-03-16 22:23 ` [PATCH v4 00/12] livepatch-klp-build: small fixups and enhancements Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260310203751.1479229-3-joe.lawrence@redhat.com \
    --to=joe.lawrence@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox