Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Apr 2026 12:45:40 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 294780] fexecve(2) only works for scripts if /dev/fd is mounted with the non-default nodup option.
Message-ID:  <bug-294780-227@https.bugs.freebsd.org/bugzilla/>

index | next in thread | raw e-mail

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294780

            Bug ID: 294780
           Summary: fexecve(2) only works for scripts if /dev/fd is
                    mounted with the non-default nodup option.
           Product: Base System
           Version: 15.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: crest@bultmann.eu

I'm trying to use fexecve(2) to run a script, but open(path, O_RDONLY | O_EXEC)
results in a file descriptor that's only opened for execution, but not for
reading. This means that while the kernel can fexecve() it any interpreter
specified on the shebang line (e.g. /bin/sh) can't use the file descriptor e.g.
/dev/fd/6 to read the script source because by default it has dup-like instead
of open-like semantics.

This means that as far as I can tell fexecve(2) is unusable for scripts unless
root has mounted /dev/fd with the non-default nodup option.

Is there a reason why the kernel clears the O_RDONLY (FREAD) when opening with
O_EXEC? Would it be possible to allow the combination of O_RDONLY | O_EXEC
(FREAD | FEXEC) to allow both direct execution and interpreters to work with
dup semantics?

-- 
You are receiving this mail because:
You are the assignee for the bug.

home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-294780-227>