The branch releng/15.2 has been updated by cperciva:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d5fc0696570e73ba07418694c61557ed009ee77d

commit d5fc0696570e73ba07418694c61557ed009ee77d
Author:     David E. O'Brien <[email protected]>
AuthorDate: 2026-11-21 04:53:30 +0000
Commit:     Colin Percival <[email protected]>
CommitDate: 2026-12-04 07:13:32 +0000

    imgact_elf: accept PT_INTERP segments up to 4096 bytes
    
    The Yocto/Poky relocatable SDK NUL-pads the interpreter path in
    PT_INTERP out to 4096 bytes (within Linux's POSIX PATH_MAX) so that
    'relocate_sdk.py' can rewrite the path in place.  The kernel rejected
    any PT_INTERP with p_filesz > BSD's MAXPATHLEN (1024) with
    "Invalid PT_INTERP" and ENOEXEC, so none of the SDK's binaries could
    be run under the Linuxulator.
    
    - The PT_INTERP segment may now be up to 'PT_INTERP_SEG_MAXSZ'
      bytes, which may be greater than 'MAXPATHLEN'.
    - The interpreter path within the segment must still be shorter
      than 'MAXPATHLEN' -- when violated results in 'ENAMETOOLONG'
      when the interpreter is looked up.
    
    Approved by:    re (cperciva)
    Reviewed by:    kib
    Differential Revision: https://reviews.freebsd.org/D62075
    (cherry picked from commit 7ee8d41ebb2ffb13e50ea59fd5bc43155123f323)
    (cherry picked from commit cada5351b20f3dd1e146d558d0f44a8f9a1f9b52)
---
 sys/kern/imgact_elf.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 0d681e8ff14b..b839da0fc7b4 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -2,7 +2,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  *
  * Copyright (c) 2017 Dell EMC
- * Copyright (c) 2000-2001, 2003 David O'Brien
+ * Copyright (c) 2000-2001, 2003, 2026 David O'Brien
  * Copyright (c) 1995-1996 Søren Schmidt
  * Copyright (c) 1996 Peter Wemm
  * All rights reserved.
@@ -1020,6 +1020,14 @@ __elfN(enforce_limits)(struct image_params *imgp, const 
Elf_Ehdr *hdr,
        return (0);
 }
 
+/*
+ * Maximum size of the PT_INTERP segment.  Linux accepts up to its POSIX
+ * PATH_MAX (4096) bytes, and some toolchains (e.g. the Yocto/Poky relocatable
+ * SDK) NUL-pad the interpreter path out to that size so that it can be
+ * rewritten in place.  The path itself must still fit in MAXPATHLEN.
+ */
+#define        PT_INTERP_SEG_MAXSZ     MAX(MAXPATHLEN, 4096)
+
 static int
 __elfN(get_interp)(struct image_params *imgp, const Elf_Phdr *phdr,
     char **interpp, bool *free_interpp)
@@ -1032,7 +1040,7 @@ __elfN(get_interp)(struct image_params *imgp, const 
Elf_Phdr *phdr,
        ASSERT_VOP_LOCKED(imgp->vp, __func__);
 
        /* Path to interpreter */
-       if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) {
+       if (phdr->p_filesz < 2 || phdr->p_filesz > PT_INTERP_SEG_MAXSZ) {
                uprintf("Invalid PT_INTERP\n");
                return (ENOEXEC);
        }

Reply via email to