Bug 297426 - linuxulator: linprocfs /proc/self/exe host path breaks execve under Linux ABI
Summary: linuxulator: linprocfs /proc/self/exe host path breaks execve under Linux ABI
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-08-10 23:32 UTC by Devin Teske
Modified: 2026-10-18 15:49 UTC (History)
7 users (show)

See Also:


Attachments
Rebuild linprocfs modules from /usr/src (204 bytes, application/x-sh)
2026-08-10 23:43 UTC, Devin Teske
no flags Details
Install rebuilt linprocfs module into the boot kernel dir and reload it (1.42 KB, application/x-sh)
2026-08-11 00:00 UTC, Devin Teske
no flags Details
/proc/self/exe litmus: readlink/stat/access/execve, under- and outside-emul, with per-case remedies (6.75 KB, text/plain)
2026-08-11 02:55 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-outside-no-native-proc.txt (669 bytes, text/plain)
2026-08-12 06:49 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-outside-with-proc-mounted.txt (210 bytes, text/plain)
2026-08-12 06:50 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-inside-no-native-proc-no-patch.txt (708 bytes, text/plain)
2026-08-12 06:51 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-inside-with-proc-mounted-no-patch.txt (1.11 KB, text/plain)
2026-08-12 06:51 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-inside-no-native-proc-with-patch.txt (198 bytes, text/plain)
2026-08-12 06:52 UTC, Devin Teske
no flags Details
proc-self-exe-litmus-inside-with-proc-mounted-with-patch.txt (198 bytes, text/plain)
2026-08-12 06:53 UTC, Devin Teske
no flags Details
linux-proc-self-exe-litmus2.c (5.43 KB, text/plain)
2026-08-15 06:53 UTC, Devin Teske
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Teske freebsd_committer freebsd_triage 2026-08-10 23:32:27 UTC
Observed behavior
-----------------

Linux programs that re-execute themselves via /proc/self/exe fail under
the Linuxulator even though the same binary runs when invoked by its
real path.

A minimal check (Linux python under linux_base-rl9):

  readlink(/proc/self/exe)  succeeds and returns a path
  stat(/proc/self/exe)      fails with ENOENT
  access(/proc/self/exe, X) fails
  execve(/proc/self/exe)    fails with ENOENT
  execve(<same binary by its normal path>) succeeds

Chromium-family browsers under the Linuxulator (for example
www/linux-brave) hit this immediately: helper processes are started with
execvp("/proc/self/exe"), which fails with:

  LaunchProcess: failed to execvp:
  /proc/self/exe

The GPU process then exits (status 32512), and the browser aborts
(SIGTRAP / "GPU process isn't usable").  Sites and DRM are beside the
point; the process cannot spawn helpers at all.  Native FreeBSD
www/chromium is not this bug.

Mechanism
---------

linprocfs exposes /proc/<pid>/exe as a symlink.  The fill routine uses
proc_get_binpath(), which returns a FreeBSD host path.  For a binary
installed under the emulator root that looks like:

  /compat/linux/usr/bin/python3.9

Linux ABI absolute lookups start at compat.linux.emul_path (default
/compat/linux).  Following the symlink therefore searches for:

  /compat/linux/compat/linux/usr/bin/python3.9

which does not exist -- hence ENOENT on stat/access/execve of
/proc/self/exe, while execve of the Linux-visible path
(/usr/bin/python3.9) works.

On Linux, /proc/self/exe readlink returns a path already meaningful
inside that namespace (e.g. /usr/bin/python3.9), so follow/exec succeed.

Proposed direction
------------------

Patch forthcoming on Phabricator: when filling the linprocfs exe
symlink, report a Linux-visible path (strip the emul_path prefix when
present) so readlink, namei follow, and execve of /proc/self/exe behave
as on Linux.  Native FreeBSD procfs should keep reporting the host path
for FreeBSD processes.
Comment 1 Devin Teske freebsd_committer freebsd_triage 2026-08-10 23:43:02 UTC
Created attachment 273605 [details]
Rebuild linprocfs modules from /usr/src
Comment 2 Devin Teske freebsd_committer freebsd_triage 2026-08-11 00:00:13 UTC
Created attachment 273606 [details]
Install rebuilt linprocfs module into the boot kernel dir and reload it
Comment 3 Alex S 2026-08-11 00:09:31 UTC
Let's actually try it:

% /compat/linux/bin/python3
Python 3.9.23 (main, Aug 19 2025, 00:00:00) 
[GCC 11.5.0 20240719 (Red Hat 11.5.0-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.readlink("/proc/self/exe")
'/compat/linux/usr/bin/python3.9'
>>> os.stat("/proc/self/exe")
os.stat_result(st_mode=33261, st_ino=1860340, st_dev=502192302, st_nlink=1, st_uid=0, st_gid=0, st_size=15448, st_atime=0, st_mtime=1761952505, st_ctime=1772769444)
>>> os.execv("/proc/self/exe", ["whatever"])
Python 3.9.23 (main, Aug 19 2025, 00:00:00) 
[GCC 11.5.0 20240719 (Red Hat 11.5.0-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.readlink("/proc/self/exe")
'/compat/linux/usr/bin/python3.9'
>>> os.stat("/proc/self/exe")
os.stat_result(st_mode=33261, st_ino=1860340, st_dev=502192302, st_nlink=1, st_uid=0, st_gid=0, st_size=15448, st_atime=0, st_mtime=1761952505, st_ctime=1772769444)

Do you have an working repro or you are just trying to waste everyone's time?
Comment 4 Devin Teske freebsd_committer freebsd_triage 2026-08-11 02:42:30 UTC
(In reply to Alex S from comment #3)

Thanks for taking the time to test.  The difference between our systems
will be what is mounted at the native /proc -- could you post your
`mount | grep proc`?

On a default Linuxulator setup -- linux_enable=YES, where rc.d/linux
mounts linprocfs at /compat/linux/proc and nothing is mounted at the
native /proc -- the same sequence fails:

$ mount | grep proc
linprocfs on /compat/linux/proc (linprocfs, local)

$ /compat/linux/usr/bin/python3.9 -c "
import os
print('readlink:', os.readlink('/proc/self/exe'))
try:
    print('stat:', os.stat('/proc/self/exe'))
except OSError as e:
    print('stat: FAIL --', e)
try:
    os.execv('/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
except OSError as e:
    print('execv: FAIL --', e)
"
readlink: /compat/linux/usr/bin/python3.9
stat: FAIL -- [Errno 2] No such file or directory: '/proc/self/exe'
execv: FAIL -- [Errno 2] No such file or directory

Mechanism: linprocfs fills the exe symlink with the host path
(/compat/linux/usr/bin/python3.9).  The Linux ABI resolves absolute
paths from compat.linux.emul_path, so following that target looks up
/compat/linux/compat/linux/usr/bin/python3.9 and gets ENOENT.  If
procfs(5) is mounted at the native /proc (it provides both "self" and
"exe" nodes), namei's restart into the native namespace resolves
/proc/self/exe there and stat/execve succeed -- which would explain
the results on your system.

Note that even in your successful run, readlink returned
'/compat/linux/usr/bin/python3.9'.  On Linux this returns the path in
the process's own namespace ('/usr/bin/python3.9'); the emulator
prefix is host configuration (a FreeBSD sysctl) that consumers
comparing or deriving paths from the result should never see.  The
proposed patch strips that prefix.

I'll attach a small litmus program that exercises
readlink/stat/access/execve for both cases: a binary under the
emulator root, and one outside it (e.g. Linux binaries that ports
install under ${PREFIX}, such as www/linux-brave, which is how this
was found).
Comment 5 Devin Teske freebsd_committer freebsd_triage 2026-08-11 02:55:57 UTC
Created attachment 273609 [details]
/proc/self/exe litmus: readlink/stat/access/execve, under- and outside-emul, with per-case remedies
Comment 6 Devin Teske freebsd_committer freebsd_triage 2026-08-11 03:12:48 UTC
https://reviews.freebsd.org/D58780
Comment 7 Alex S 2026-08-11 20:16:40 UTC
(In reply to Devin Teske from comment #4)

> Thanks for taking the time to test.  The difference between our systems
will be what is mounted at the native /proc -- could you post your
`mount | grep proc`?

I don't normally mount procfs at /proc, but there is no impact either way.

> Mechanism: linprocfs fills the exe symlink with the host path
(/compat/linux/usr/bin/python3.9).  The Linux ABI resolves absolute
paths from compat.linux.emul_path, so following that target looks up
/compat/linux/compat/linux/usr/bin/python3.9 and gets ENOENT.  If
procfs(5) is mounted at the native /proc (it provides both "self" and
"exe" nodes), namei's restart into the native namespace resolves
/proc/self/exe there and stat/execve succeed -- which would explain
the results on your system.

It might or might not be a good idea to get rid of the double lookup
(/compat/linux/compat/linux/usr/bin/python3, then /compat/linux/usr/bin/python3),
but that itself is not the cause of any of your problems.
Comment 8 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:47:41 UTC
(In reply to Alex S from comment #7)

> I don't normally mount procfs at /proc, but there is no impact either
> way.

I repeated the exact Python test from your comment 3 while changing only the
native procfs mount state. On this 16.0-CURRENT system, mount state
directly changes the result.

Test environment
----------------

  kern.osreldate:          1600019
  linux_base-rl9:          9.8
  compat.linux.emul_path:  /compat/linux

  unmodified source:       34718e01869b
  D58780 source:           bec989b72aae

The linprocfs module was rebuilt using the already-attached
linux_rebuild2.sh and installed/reloaded using linux_reload2.sh.

Exact Python reproduction
-------------------------

With no native procfs mounted:

  $ mount | grep proc
  linprocfs on /compat/linux/proc (linprocfs, local)

  $ /compat/linux/usr/bin/python3.9 -c "
  import os
  print('readlink:', os.readlink('/proc/self/exe'))
  try:
      print('stat:', os.stat('/proc/self/exe'))
  except OSError as e:
      print('stat: FAIL --', e)
  try:
      os.execv('/proc/self/exe',
          ['python3', '-c', 'print(\"execv OK\")'])
  except OSError as e:
      print('execv: FAIL --', e)
  "

  readlink: /compat/linux/usr/bin/python3.9
  stat: FAIL -- [Errno 2] No such file or directory: '/proc/self/exe'
  execv: FAIL -- [Errno 2] No such file or directory

After mounting native procfs, with no other change:

  $ sudo mount -t procfs proc /proc
  $ mount | grep proc
  linprocfs on /compat/linux/proc (linprocfs, local)
  procfs on /proc (procfs, local)

Running the same Python command then produces:

  readlink: /compat/linux/usr/bin/python3.9
  stat: OK
  execv OK

Thus native procfs mount state does affect the outcome: stat/execve
change from ENOENT to success. The successful case still exposes the
FreeBSD host path through readlink rather than the Linux-visible path.

C litmus
--------

The attached linux-proc-self-exe-litmus.c tests readlink, stat,
access(X_OK), and execve independently.

Install the Linux development tools and compile it as a Linux binary:

  $ sudo pkg install linux-rl9-devtools

  $ /compat/linux/usr/bin/gcc -O2 \
      -o ~/linux-proc-self-exe-litmus \
      ~/linux-proc-self-exe-litmus.c

Run it first with its executable text outside the emulator root:

  $ ~/linux-proc-self-exe-litmus

Create a Linux-side temporary directory under the emulator root. This
directory is not created by default:

  $ sudo mkdir -p /compat/linux/tmp
  $ sudo chmod 1777 /compat/linux/tmp

Copy the same binary beneath compat.linux.emul_path and run it using its
FreeBSD host path:

  $ cp ~/linux-proc-self-exe-litmus /compat/linux/tmp/

  $ /compat/linux/tmp/linux-proc-self-exe-litmus

The program exits nonzero on failure and prints the result of readlink,
stat, access(X_OK), and execve independently.

Complete result matrix
----------------------

The complete observed matrix is:

  executable    linprocfs    native /proc   readlink result       verdict
  ------------  -----------  -------------  --------------------  -------
  outside-emul  unmodified   absent         host path             FAIL
  outside-emul  unmodified   mounted        host path             PASS
  under-emul    unmodified   absent         /compat/linux/...     FAIL
  under-emul    unmodified   mounted        /compat/linux/...     FAIL (*)
  under-emul    D58780       absent         Linux-visible path    PASS
  under-emul    D58780       mounted        Linux-visible path    PASS

(*) With native procfs mounted, stat/access/execve succeed through
native-namespace fallback, but readlink still returns the host path
including /compat/linux. The litmus therefore correctly reports failure:
The Linuxulator should not expose FreeBSD host emulator configuration through /proc/self/exe. To emulate native Linux accurately, it should report the path in the process’s own namespace, improving compatibility with Linux binaries. Returning a host-only emulator prefix through an ABI-visible pathname is a Linuxulator implementation leak with no analogue in native Linux and is highly irregular for a Linux compatibility layer.

Representative output
---------------------

Unmodified linprocfs, executable outside emul_path, no native procfs:

  case: outside-emul
  readlink(/proc/self/exe) =
      /home/dteske/linux-proc-self-exe-litmus
  readlink: OK
  stat(/proc/self/exe): FAIL (No such file or directory)
  access(X_OK): FAIL (No such file or directory)
  execve(/proc/self/exe): FAIL
  VERDICT: FAIL (outside-emul)

Unmodified linprocfs, executable outside emul_path, native procfs
mounted:

  case: outside-emul
  readlink(/proc/self/exe) =
      /home/dteske/linux-proc-self-exe-litmus
  readlink: OK
  stat(/proc/self/exe): OK
  access(X_OK): OK
  execve(/proc/self/exe): OK
  VERDICT: PASS (outside-emul)

Unmodified linprocfs, executable under emul_path, no native procfs:

  case: under-emul
  readlink(/proc/self/exe) =
      /compat/linux/tmp/linux-proc-self-exe-litmus
  readlink: FAIL (host path; expected the Linux namespace path)
  stat(/proc/self/exe): FAIL (No such file or directory)
  access(X_OK): FAIL (No such file or directory)
  execve(/proc/self/exe): FAIL
  VERDICT: FAIL (under-emul)

Unmodified linprocfs, executable under emul_path, native procfs mounted:

  case: under-emul
  readlink(/proc/self/exe) =
      /compat/linux/tmp/linux-proc-self-exe-litmus
  readlink: FAIL (host path; expected the Linux namespace path)
  stat(/proc/self/exe): OK
  access(X_OK): OK
  execve(/proc/self/exe): OK
  VERDICT: FAIL (under-emul)

D58780, executable under emul_path, no native procfs:

  case: under-emul
  readlink(/proc/self/exe) =
      /tmp/linux-proc-self-exe-litmus
  readlink: OK
  stat(/proc/self/exe): OK
  access(X_OK): OK
  execve(/proc/self/exe): OK
  VERDICT: PASS (under-emul)

D58780, executable under emul_path, native procfs mounted:

  case: under-emul
  readlink(/proc/self/exe) =
      /tmp/linux-proc-self-exe-litmus
  readlink: OK
  stat(/proc/self/exe): OK
  access(X_OK): OK
  execve(/proc/self/exe): OK
  VERDICT: PASS (under-emul)

Concrete consumer
-----------------

This is not only a path-format discrepancy. www/linux-brave provides a
concrete consumer of the failing follow operation.

Brave is installed outside compat.linux.emul_path, under
/usr/local/share/brave. Chromium starts helper processes by executing
/proc/self/exe. Without procfs mounted at native /proc, that operation
fails with ENOENT:

  LaunchProcess: failed to execvp:
  /proc/self/exe

The GPU helper consequently exits and Brave cannot launch successfully.
D58784 makes this requirement explicit by refusing to start
www/linux-brave without native procfs and printing the required mount
instructions.

The two fixes address complementary cases:

  * Linux binaries outside compat.linux.emul_path, such as
    www/linux-brave, require procfs mounted at native /proc.

  * Linux binaries under compat.linux.emul_path should receive a
    Linux-visible /proc/self/exe target. D58780 supplies that behavior by
    stripping the emulator prefix.

D58780 therefore does not attempt to replace native procfs for
outside-emul binaries. It fixes the distinct under-emul case where
linprocfs itself emits a target that is not valid in the process's Linux
namespace.

Mechanism and scope
-------------------

proc_get_binpath() returns a FreeBSD host path. For executable text under
the emulator root, unmodified linprocfs therefore reports a target such as:

  /compat/linux/usr/bin/python3.9

The Linux ABI first resolves that absolute path relative to
compat.linux.emul_path, producing an initial lookup equivalent to:

  /compat/linux/compat/linux/usr/bin/python3.9

Without native procfs, following /proc/self/exe consequently fails with
ENOENT. Native procfs can mask the follow operation through
native-namespace fallback, but it cannot correct the readlink result.

D58780 strips compat.linux.emul_path when the executable is beneath that
root. The symlink then reports the Linux-visible path:

  /usr/bin/python3.9

That fixes readlink and makes stat/access/execve work regardless of
whether native procfs is mounted.

D58780 intentionally does not alter paths for executables outside the
emulator root. Those require procfs mounted at native /proc. Making
arbitrary FreeBSD host paths directly meaningful inside the Linux
namespace is a separate and substantially broader problem and is not
part of D58780.

I am attaching the complete six output files underlying this matrix. If
another system produces different results, please provide both
`mount | grep proc` and the complete litmus output so the differing
lookup path can be identified. Also, please provide for test env:

1. uname -K # for kernel version
2. pkg info linux_base-rl9 # for Linuxulator version
Comment 9 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:49:41 UTC
Created attachment 273670 [details]
proc-self-exe-litmus-outside-no-native-proc.txt
Comment 10 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:50:22 UTC
Created attachment 273671 [details]
proc-self-exe-litmus-outside-with-proc-mounted.txt
Comment 11 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:51:06 UTC
Created attachment 273672 [details]
proc-self-exe-litmus-inside-no-native-proc-no-patch.txt
Comment 12 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:51:58 UTC
Created attachment 273673 [details]
proc-self-exe-litmus-inside-with-proc-mounted-no-patch.txt
Comment 13 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:52:48 UTC
Created attachment 273674 [details]
proc-self-exe-litmus-inside-no-native-proc-with-patch.txt
Comment 14 Devin Teske freebsd_committer freebsd_triage 2026-08-12 06:53:34 UTC
Created attachment 273675 [details]
proc-self-exe-litmus-inside-with-proc-mounted-with-patch.txt
Comment 15 Gleb Popov freebsd_committer freebsd_triage 2026-08-12 07:32:24 UTC
It seems the whole fuss is around this statement

> The Linuxulator should not expose FreeBSD host emulator configuration through /proc/self/exe.

Which I don't quite get. All path lookups done by Linuxulator are first performed against / and then against emul_path. So everything works as it should to me.
Comment 16 Alex S 2026-08-12 07:51:32 UTC
(In reply to Gleb Popov from comment #15)

> Which I don't quite get. All path lookups done by Linuxulator are first performed against / and then against emul_path. So everything works as it should to me.

I don't pretend to know this code, but it's likely the other way around:

% ls -lh /compat/linux/etc/hosts
-rw-r--r--  1 root wheel  158B 23 июня   2020 /compat/linux/etc/hosts
% ls -lh /etc/hosts
-rw-r--r--  1 root wheel  2,3K  9 июля  13:28 /etc/hosts
% /compat/linux/bin/ls -lh /etc/hosts
-rw-r--r-- 1 root wheel 158 июн 23  2020 /etc/hosts

The main issue is that we might have a bug here, but the LLM dignosis
doesn't look correct to me. I have no opinion on the linprofs change.
However, we already past pretending it will help the browser in any
way (since it's not installed in /compat/linux) with the pivot point
somewhere in the middle of this thread. Now it's two separate issues
and both don't look correctly diagnosed to me.
Comment 17 Dan Kotowski 2026-08-12 07:54:25 UTC
FWIW I am NOT able to reproduce on CURRENT

$ /compat/linux/usr/bin/python3.9
Python 3.9.25 (main, Apr 17 2026, 00:00:00)
[GCC 11.5.0 20240719 (Red Hat 11.5.0-14)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print('readlink:', os.readlink('/proc/self/exe'))
readlink: /compat/linux/usr/bin/python3.9
>>> try:
...     print('stat:', os.stat('/proc/self/exe'))
... except OSError as e:
...     print('stat: FAIL --', e)
...
stat: os.stat_result(st_mode=33261, st_ino=1426886, st_dev=4259517978, st_nlink=1, st_uid=0, st_gid=0, st_size=15448, st_atime=0, st_mtime=1779238957, st_ctime=1785159540)
>>> try:
...     os.execv('/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
... except OSError as e:
...     print('execv: FAIL --', e)
...
execv OK

$ uname -v
FreeBSD 16.0-CURRENT main-n288168-71e72c9e91c4 GENERIC

$ mount | grep proc
procfs on /proc (procfs, local)
linprocfs on /compat/linux/proc (linprocfs, local)
Comment 18 Dan Kotowski 2026-08-12 08:00:03 UTC
Also works as expected even when using linprocfs under /compat/linux

$ /compat/linux/usr/bin/python3.9
Python 3.9.25 (main, Apr 17 2026, 00:00:00)
[GCC 11.5.0 20240719 (Red Hat 11.5.0-14)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print('readlink:', os.readlink('/proc/self/exe'))
readlink: /compat/linux/usr/bin/python3.9
>>> print('readlink:', os.readlink('/compat/linux/proc/self/exe'))
readlink: /compat/linux/usr/bin/python3.9
>>> try:
...     print('stat:', os.stat('/compat/linux/proc/self/exe'))
... except OSError as e:
...     print('stat: FAIL --', e)
...
stat: os.stat_result(st_mode=33261, st_ino=1426886, st_dev=4259517978, st_nlink=1, st_uid=0, st_gid=0, st_size=15448, st_atime=0, st_mtime=1779238957, st_ctime=1785159540)
>>> try:
...     os.execv('/compat/linux/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
... except OSError as e:
...     print('stat: FAIL --', e)
...
execv OK
Comment 19 Devin Teske freebsd_committer freebsd_triage 2026-08-12 10:41:47 UTC
(In reply to Dan Kotowski from comment #17)

You have procfs mounted on /proc

As I have repeatedly stated, that is wrong.

Unmount /proc and try again and you'll see your test fails.

Please re-read what I wrote.
Comment 20 Dan Kotowski 2026-08-12 10:46:29 UTC
(In reply to Devin Teske from comment #19)

In so much that we are inspecting a deprecated feature, yes. But man 4 procfs says clearly at the top that procfs should be mounted at /proc.

See src commit 8d8a74e and https://reviews.freebsd.org/D22275
Comment 21 Devin Teske freebsd_committer freebsd_triage 2026-08-12 10:51:40 UTC
(In reply to Dan Kotowski from comment #20)

procfs is insecure, it's why we have procstat. We should be endeavoring to not require procfs (/proc) mounted, but more importantly, if Linux programs were expected to require procfs, then linux_enable=YES in rc.conf (and subsequently service linux start) should be mounting it, but it does not.

So far, everyone that has said (in so many words) "works for me" and "cannot replicate" have had procfs mounted.

It's so much more than just "deprecated feature" it's a UX issue.

Like I did not spend 3 days trying to figure out why linux-brave would not launch on 16.0-CURRENT with linux_enable=YES only to find that mounting /proc solves the issue (not before devolving into potentially patching namei in the VFS layer to address the issue of compat lookups by Linux programs outside the emul path).

We should be working toward a future where linuxulator is highly polished and doesn't require insecure procfs.

Yes, procfs is not just an obsolete element, it was done-away-with because of security. I'm fine keeping linprocfs for Linux binaries and linux_enable=YES absolutely brings in linprocfs to satisfy the requirements of Linux binaries. However, it should not require a crutch of procfs to satisfy any Linux program looking at /proc/self/exe in linprocfs.
Comment 22 Gleb Popov freebsd_committer freebsd_triage 2026-08-12 10:57:36 UTC
As a seasoned porter I can state that deprecating procfs is simply unrealistic unless Linux deprecates it too. There are a lot of software that tries to access /proc in the wild and it is unrealistic that we patch all of them with an alternative libprocstat/libkvm code path. Not to mention that all upstreams wouldn't be happy to accept such patches.

What security issues lead to procfs deprecation exactly? Maybe we could solve them or strip some functionality.
Comment 23 Devin Teske freebsd_committer freebsd_triage 2026-08-12 11:19:42 UTC
(In reply to Gleb Popov from comment #22)

Your statement flies in the face of good people that have worked very hard to get rid of procfs in the base and we have operated without procfs for many releases without a problem.

I have not had to mount procfs in over 10 years. Not for Firefox, not for anything in base, not for any natively compiled program.

Then I attend one BSDCan and get the bug to start improving relations with the Framework folks and the Foundation -- working toward having Framework officially (on the record) state that they support FreeBSD as an OS and I go ahead and start polishing the OS to support all manner of use-cases for the laptop.

I start my own window manager. I implement touchscreen gestures. I develop handicapable interfaces for disabled people. I test the platform as a portable gaming rig. A pro audio station.

Then I get to the use case of using the laptop as a Set Top Box (STB) to replace my Apple TV and of course, I have to get things like Netflix going. I really didn't want to use native chromium because I don't trust Google (spent some time with tcpdump and I can verifiably prove that their mesh hardware doesn't play "nice" with things like PiHole; notably when DNS gets a response like 0.0.0.0 for a domain, their mesh routers will call home to the Google infra over DoH and resolve the domain on the auspice that the DNS gave a "bad" result, thus neutering the use of block lists). So, when it came to running Widevine to run sites like Netflix, I wanted to use a browser I could trust. I am aware that Brave is built atop chromium anyhow, but at least it's more trustworthy than Chromium in my opinion.

So I started playing with linux-brave (the only way I am aware of running brave on FreeBSD) and that's the first time in over a decade that I've had to load procfs.

So saying that it's unlikely we will ever get rid of procfs ignores the fact that I have been living procfs free for a decade plus and only when I had to load a single linux program did I have to bring it back onto my systems that have been happily procfs-free for a long time.
Comment 24 Gleb Popov freebsd_committer freebsd_triage 2026-08-12 11:34:09 UTC
(In reply to Devin Teske from comment #23)

I'm overrun by the amount of information and attachments in this PR. Could you please provide a simple way to reproduce the issue, so I can look into it?
Comment 25 Devin Teske freebsd_committer freebsd_triage 2026-08-12 12:03:35 UTC
(In reply to Gleb Popov from comment #24)

I very painstakingly generated those litmus outputs and documented the complete result matrix for the six conditions because trying to be brief was not working.

Let me boil it down to the simplest form that I am capable if:

Step 1. Unmount procfs
Step 2. Run this:

```
/compat/linux/usr/bin/python3.9 -c "
import os
print('readlink:', os.readlink('/proc/self/exe'))
try:
    print('stat:', os.stat('/proc/self/exe'))
except OSError as e:
    print('stat: FAIL --', e)
try:
    os.execv('/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
except OSError as e:
    print('execv: FAIL --', e)
"
```

Step 3. Get this error:

```
readlink: /compat/linux/usr/bin/python3.9
stat: FAIL -- [Errno 2] No such file or directory: '/proc/self/exe'
execv: FAIL -- [Errno 2] No such file or directory
```

Copied from my earlier comment 4.

Simplicity:

A Linux executable in /compat/linux such as python3.9 (feel free to substitute python3 if you don't have python3.9) should be capable of working with linprocfs alone and not require not-one but two proc filesystems. We should not need to have both linprocfs and procfs loaded concurrently. linprocfs should be sufficient to satisfy /proc needs of Linux programs that are part of linux rl9 family.
Comment 26 Ed Maste freebsd_committer freebsd_triage 2026-08-12 13:21:58 UTC
This is a consequence of fd745e1db6b5 / cea7c564c70a / 459ac3044b51.
Comment 27 Devin Teske freebsd_committer freebsd_triage 2026-08-12 13:33:34 UTC
(In reply to Gleb Popov from comment #22)

> As a seasoned porter I can state that deprecating procfs is simply unrealistic

current portmgr standard is that no ports are allowed to depend on native proc

> unless Linux deprecates it too

native proc != linprocfs

> What security issues lead to procfs deprecation exactly? Maybe we could solve them or strip some functionality.

TOCTOU for 1
Comment 28 Gleb Popov freebsd_committer freebsd_triage 2026-08-12 13:45:34 UTC
(In reply to Devin Teske from comment #27)
> current portmgr standard is that no ports are allowed to depend on native proc

Where does this information come from?

> native proc != linprocfs
> TOCTOU for 1

If you're being that extremely terse because you're tired of this conversation, it's understandable. I'm tired as well. But in the end I guess we both want to fix the real issues, not hide them behind workarounds. This requires understanding the problem, which is why I keep asking questions. Replying with a two or three words doesn't help.

I'll try out your reproduction case once I get done with $WORK.
Comment 29 Devin Teske freebsd_committer freebsd_triage 2026-08-12 16:40:54 UTC
(In reply to Gleb Popov from comment #28)

> Where does this information come from?

Phrased poorly. No written handbook rule. Purely a de facto operational constraint:

1. Poudriere: Jails do not provide native procfs. Ports requiring it for building, testing, or basic package staging fail on the cluster.
2. Runtime & Base System: Gutted skeleton in src. Tracing, memory-mapping, and debugging internals stripped years ago. Code skeleton kept solely to prevent runtime failures in legacy end-user scripts.

> If you're being that extremely terse because you're tired of this conversation, it's understandable. [...] Replying with a two or three words doesn't help.

I had prepared a much longer answer which was met with a mid-air (in-flight) collision with Ed's comment 26

I then shortened my re-response to minimal length as to not bury Ed's comment. So in that way, the terse responses are actually helping. Helping to keep Ed's very important pointers to commit hashes accessible.
Comment 30 Gleb Popov freebsd_committer freebsd_triage 2026-08-12 19:53:43 UTC
(In reply to Devin Teske from comment #25)
I can confirm this and thanks to Ed's references it is now clear that the bug is about resolving symlinks specifically, not arbitrary file paths.

I'm not knowledgeable enough to propose a fix, though.
Comment 31 Mark Millard 2026-08-12 21:26:44 UTC
(In reply to Devin Teske from comment #25)

I seem to have replicated the described behavior. I started in an
environment in which I did not have the linux service enabled and
did not a have any linux present, much less also having
linux-rl9-python39 present. So my sequencing was . . .
(Note: I abbreviate my long FreeBSD command prompts to # below.
I was logged in as root.

# mount | grep proc
# service linux onestart
# pkg install -rmain-amd64-default linux_base-rl9 # I do not show building it 1st
# service linux onestop
# service linux onestart
# mount | grep proc
linprocfs on /compat/linux/proc (linprocfs, local)
# pkg install -rmain-amd64-default linux-rl9-python39 # Again: build 1st not shown
# /compat/linux/usr/bin/python3.9 --version
Python 3.9.25
# /compat/linux/usr/bin/python3.9 -c "
import os
print('readlink:', os.readlink('/proc/self/exe'))
try:
    print('stat:', os.stat('/proc/self/exe'))
except OSError as e:
    print('stat: FAIL --', e)
try:
    os.execv('/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
except OSError as e:
    print('execv: FAIL --', e)
"
readlink: /compat/linux/usr/bin/python3.9
stat: FAIL -- [Errno 2] No such file or directory: '/proc/self/exe'
execv: FAIL -- [Errno 2] No such file or directory
# 


After the replication above I then also tried:

# chroot /compat/linux /bin/bash
bash-5.1# which python3.9
/bin/python3.9
bash-5.1# /bin/python3.9 -c "
import os
print('readlink:', os.readlink('/proc/self/exe'))
try:
    print('stat:', os.stat('/proc/self/exe'))
except OSError as e:
    print('stat: FAIL --', e)
try:
    os.execv('/proc/self/exe', ['python3', '-c', 'print(\"execv OK\")'])
except OSError as e:
    print('execv: FAIL --', e)
"
readlink: /usr/bin/python3.9
stat: os.stat_result(st_mode=33261, st_ino=234748, st_dev=2112205527, st_nlink=1, st_uid=0, st_gid=0, st_size=15448, st_atime=0, st_mtime=1779238957, st_ctime=1786567941)
execv OK
bash-5.1#
Comment 32 Alex S 2026-08-13 07:08:08 UTC
(In reply to Ed Maste from comment #26)

The only sensible thing to do here would be reverting 459ac3044b51
considering how much it breaks linux-* ports. Is there any intention
to do so?

To be clear, neither beahavior is entirely correct, but the issue that
commit was trying to fix (using debootstrapped installatons without
chrooting into them) is quite a bit more niche and more easily
workaroundable.
Comment 33 Ricardo Branco 2026-08-13 08:18:03 UTC
I'll take a look over the weekend.
Comment 34 Ricardo Branco 2026-08-14 08:50:33 UTC
(In reply to Alex S from comment #32)

> the issue that commit was trying to fix (using debootstrapped installatons without
chrooting into them) is quite a bit more niche

It's not niche.  Reverting it would break Linuxulator userlands where the ELF interpreter is an absolute symlink inside /compat/linux

https://reviews.freebsd.org/D58780 (patching linprocfs to handle /proc/self/exe) is the right call here.   Reverting 459ac3044b51 is wrong and suboptimal.
Comment 35 Alex S 2026-08-14 09:01:28 UTC
(In reply to Ricardo Branco from comment #34)

> https://reviews.freebsd.org/D58780 (patching linprocfs to handle /proc/self/exe)
> is the right call here.   Reverting 459ac3044b51 is wrong and suboptimal.

I'm talking about symlinks from linux-rl9-alsa-lib, linux-rl9-fontconfig,
linux-rl9-ca-certificates packages.
Comment 36 Gleb Popov freebsd_committer freebsd_triage 2026-08-14 10:18:57 UTC
Note that security/linux-rl9-ca-certificates has a test target that was created exactly because /bin/trust was being confused by symlinks. The port can now be used as a regression test when changing the behavior of symlink resolving.
Comment 37 Ricardo Branco 2026-08-14 11:20:14 UTC
I'm afraid this issue can't be fully solved for Linux programs outside of a chroot, because sometimes you want them to access files outside /compat/linux (like $HOME) and sometimes you don't (the case with /proc/self/exe).  Otherwise mount linprocfs in /proc.  

Linux programs should run chroot'ed...  If you want them to access $HOME, just bind-mount $HOME in /compat/linux
Comment 38 Gleb Popov freebsd_committer freebsd_triage 2026-08-14 11:23:03 UTC
(In reply to Ricardo Branco from comment #37)
> Linux programs should run chroot'ed...

I think that's too much to ask. If there is no other way, maybe let's strip the native procfs down to /proc/self ?
Comment 39 Alex S 2026-08-14 12:12:31 UTC
procfs is entirely irrelevant here. I can't speek for everyone,
but I would be entirely content with the symlink _targets_
following the same ad hoc overlay logic. That doesn't seem to be
easy to implement, so I'm asking to refrain from breaking the ports
in the meantime.
Comment 40 Alex S 2026-08-14 12:13:51 UTC
s/speek/speak/
Comment 41 Devin Teske freebsd_committer freebsd_triage 2026-08-15 06:53:31 UTC
Created attachment 273783 [details]
linux-proc-self-exe-litmus2.c
Comment 42 Devin Teske freebsd_committer freebsd_triage 2026-08-15 07:15:20 UTC
Abandoned https://reviews.freebsd.org/D58780

New https://reviews.freebsd.org/D58855
Comment 43 commit-hook freebsd_committer freebsd_triage 2026-09-26 18:16:44 UTC
A commit in branch main references this bug:

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

commit b98d169d1f910e0b28c7ea2f26fcc09f83614ec9
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-09-26 18:12:33 +0000
Commit:     Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-09-26 18:12:33 +0000

    tests/sys/vfs: add ABI-root absolute symlink tests

    Pin the overlay namei(9) uses for Linux ABI processes: a target under
    the ABI root wins (PR 289739), a native-only target should retry from
    the native root (PR 297426), an ENOENT past a resolved ABI target is
    not retried, and the plain no-symlink native fallback is unchanged.
    Skip without a Linux userland so CI stays green.  The two native-only
    cases use atf_expect_fail until the retry lands.

    PR:             297426
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D59990

 tests/sys/vfs/Makefile                  |   2 +
 tests/sys/vfs/abi_root_symlink.sh (new) | 279 ++++++++++++++++++++++++++++++++
 2 files changed, 281 insertions(+)
Comment 44 commit-hook freebsd_committer freebsd_triage 2026-10-18 15:49:55 UTC
A commit in branch main references this bug:

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

commit 23b326728778fd3a6c37b33686dea98d010eb1cf
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-10-18 15:44:12 +0000
Commit:     Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-10-18 15:44:12 +0000

    namei: retry absolute symlink expansions from the native root

    For a Linux ABI process, namei() resolves a path first under the ABI
    root (compat.linux.emul_path) and, if that fails, restarts the walk
    of the original path from the native root.  Since 459ac3044b51 an
    absolute symlink target found during the ABI pass stays under the
    ABI root, so self-contained Linux userlands resolve their own
    symlinks correctly (PR 289739); but when the target names a file
    that exists only in the native namespace, the walk fails and the
    restart cannot recover: it re-walks the original path, whose
    ABI-visible prefix (the symlink itself) does not exist natively.

    Casualties are the absolute symlinks planted under the emulator root
    to integrate the host into the Linux namespace -- among them
    linux-rl9-fontconfig's /compat/linux/etc/fonts ->
    /usr/local/etc/fonts (Linux fontconfig cannot load its
    configuration, degrading font matching to arbitrary results) and
    similar links from linux-rl9-alsa-lib and linux-rl9-ca-certificates
    -- and linprocfs' /proc/<pid>/exe, whose target is a host path:
    following it fails for any Linux binary whose text lives outside the
    emulator root (Chromium-based browsers execve /proc/self/exe to
    spawn helpers), unless procfs(5) mounted at the native /proc masks
    the failure.

    Remember the expansion produced while following an absolute symlink
    during the ABI pass and, when that pass fails with ENOENT before the
    target has resolved, perform the one allowed native restart walking
    the saved expansion in place of the original path.  The target has
    resolved once the walk has consumed it, leaving no more than the
    suffix appended past it; an ENOENT after that point restarts from
    the original path as it always has.  Lookups that succeed under the
    ABI root are unaffected, preserving 459ac3044b51; lockless lookups
    are unaffected because cache_fplookup_symlink() already aborts to
    the locked path for absolute symlinks whenever an ABI root is
    active.

    PR:             297426
    Fixes:          459ac3044b51 ("namei: Preserve ABI root for absolute symlinks before fallback")
    MFC after:      1 month
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D58855

 sys/kern/vfs_lookup.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 105 insertions(+), 1 deletion(-)