linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scripts/sorttable: Handle mmap() failure gracefully
@ 2025-06-12 16:55 Michal Luczaj
  0 siblings, 0 replies; only message in thread
From: Michal Luczaj @ 2025-06-12 16:55 UTC (permalink / raw)
  To: Steven Rostedt, Peter Zijlstra (Intel), Ingo Molnar
  Cc: linux-kernel, Michal Luczaj

When mmap() fails, don't propagate MAP_FAILED as a return value. Caller
expects NULL on error.

Fixes: 3c47b787b651 ("scripts/sortextable: Rewrite error/success handling")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
...
  LD      vmlinux
  BTFIDS  vmlinux
  NM      System.map
  SORTTAB vmlinux
Could not mmap file: vmlinux
scripts/link-vmlinux.sh: line 200:  2688 Segmentation fault      (core dumped) ${objtree}/scripts/sorttable ${1}
Failed to sort kernel tables
---
Changes in v2:
- Rebase, resend
- Link to v1: https://lore.kernel.org/r/20240726-sorttable-fix-v1-1-8b5ba4c4471f@rbox.co
---
 scripts/sorttable.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index deed676bfe384deb0333b6dde78c60bc3c6622da..2fe0974b53719b5660e1053af438ad098cdcaf28 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -334,6 +334,7 @@ static void *mmap_file(char const *fname, size_t *size)
 	addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
 	if (addr == MAP_FAILED) {
 		fprintf(stderr, "Could not mmap file: %s\n", fname);
+		addr = NULL;
 		goto out;
 	}
 

---
base-commit: 9cc7d5904bab74f54aad4948a04535c1f07c74d8
change-id: 20240723-sorttable-fix-08b9ce81db32

Best regards,
-- 
Michal Luczaj <mhal@rbox.co>


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-06-12 16:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 16:55 [PATCH v2] scripts/sorttable: Handle mmap() failure gracefully Michal Luczaj

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).