Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 910561 - sys-apps/sandbox blocks open on /proc/self/fd/N for memfd files
Summary: sys-apps/sandbox blocks open on /proc/self/fd/N for memfd files
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Sandbox (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Sandbox Maintainers
URL:
Whiteboard:
Keywords:
: 911162 916468 (view as bug list)
Depends on:
Blocks: 911162
  Show dependency tree
 
Reported: 2023-07-19 18:39 UTC by Mike Gilbert
Modified: 2024-01-11 21:03 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
julia's sandbox.log (sandbox.log,5.97 KB, text/plain)
2023-07-24 01:30 UTC, foufou33
Details
julia's build log (build.log.gz,224.43 KB, application/gzip)
2023-07-24 01:31 UTC, foufou33
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Gilbert gentoo-dev 2023-07-19 18:39:26 UTC
From the systemd test suite:

floppym@naomi systemd-254-rc2-abi_x86_32.x86 % sudo -u portage sandbox ./test-fileio
/* test_test_fdopen_independent */
 * ACCESS DENIED:  open_wr:            /proc/self/fd/3
Assertion 'fdopen_independent(fd, "r+e", &f) >= 0' failed at src/test/test-fileio.c:1118, function test_test_fdopen_independent(). Aborting.
Sandboxed process killed by signal: Aborted
 * ----------------------- SANDBOX ACCESS VIOLATION SUMMARY -----------------------
 * LOG FILE: "/var/log/sandbox/sandbox-991957.log"
 *
VERSION 1.0
FORMAT: F - Function called
FORMAT: S - Access Status
FORMAT: P - Path as passed to function
FORMAT: A - Absolute Path (not canonical)
FORMAT: R - Canonical Path
FORMAT: C - Command Line

F: open_wr
S: deny
P: /proc/self/fd/3
A: /proc/self/fd/3
R: /memfd:fdopen_independent (deleted)
C: ./test-fileio
 * --------------------------------------------------------------------------------
Comment 1 foufou33 2023-07-23 23:35:54 UTC
julia-1.8.5-r1 fails to build with sanbox-2.37. The offending ops are fchmod and fchown on something similar (/proc/self/fd/N)
downgrading to 2.32 (no ~amd64 on this system) fixes the build.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-23 23:39:09 UTC
(In reply to foufou33 from comment #1)
> julia-1.8.5-r1 fails to build with sanbox-2.37. The offending ops are fchmod
> and fchown on something similar (/proc/self/fd/N)
> downgrading to 2.32 (no ~amd64 on this system) fixes the build.

Please share the full logs.
Comment 3 foufou33 2023-07-24 01:30:06 UTC
Created attachment 866037 [details]
julia's sandbox.log
Comment 4 foufou33 2023-07-24 01:31:18 UTC
Created attachment 866038 [details]
julia's build log
Comment 5 Mike Gilbert gentoo-dev 2023-07-24 14:41:45 UTC
It's the same issue.

sandbox-2.32 does not check fchmod. sandbox-2.37 does.
Comment 6 Michael Orlitzky gentoo-dev 2023-07-25 13:40:11 UTC
This is the code for that test:

  assert_se(fdopen_independent(fd, "r+e", &f) >= 0);
  zero(buf);
  assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT));
  assert_se(streq(buf, TEST_TEXT));
  assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE) == O_RDWR);
  assert_se(FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC));
  f = safe_fclose(f);

It's not actually writing anything, it's only checking that the "r+e" mode results in O_RDWR (earlier tests confirm the contents of the file).
Comment 7 Mike Gilbert gentoo-dev 2023-07-25 14:30:04 UTC
I think the leading slash in "/memfd:" is causing sandbox to think this is an actual path rather than an abstract object. Other objects like sockets and pipes show up as "socket:..." and "pipe:..." in /proc/self/fd, and sandbox just ignores them.

I really wish the kernel devs had maintained that convention for memfd, but I guess we will just need to work around it by looking for "/memfd:" and skipping the access check.
Comment 8 Larry the Git Cow gentoo-dev 2023-08-01 14:14:33 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=27232d52fee4abecd5f709acc616fa1296e0464f

commit 27232d52fee4abecd5f709acc616fa1296e0464f
Author:     Mike Gilbert <floppym@gentoo.org>
AuthorDate: 2023-07-31 15:39:40 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2023-07-31 15:42:59 +0000

    libsandbox: always permit access to '/memfd:'
    
    For memfd objects, the kernel populates the target for symlinks under
    /proc/$PID/fd as "/memfd:name". Said target does not actually exist.
    
    It is unfortunate that the kernel includes the leading slash, but we
    will just have to work around it.
    
    Bug: https://bugs.gentoo.org/910561
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 libsandbox/libsandbox.c | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 9 Larry the Git Cow gentoo-dev 2023-08-06 00:51:57 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=761c8d19f1549cd137d2b0a0cbcb12f569dfba5e

commit 761c8d19f1549cd137d2b0a0cbcb12f569dfba5e
Author:     Mike Gilbert <floppym@gentoo.org>
AuthorDate: 2023-08-06 00:50:57 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2023-08-06 00:51:49 +0000

    sys-apps/sandbox: add 2.38
    
    Closes: https://bugs.gentoo.org/906234
    Closes: https://bugs.gentoo.org/910273
    Closes: https://bugs.gentoo.org/910561
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 sys-apps/sandbox/Manifest            |  1 +
 sys-apps/sandbox/sandbox-2.38.ebuild | 64 ++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-29 08:07:06 UTC
*** Bug 916468 has been marked as a duplicate of this bug. ***
Comment 11 Mike Gilbert gentoo-dev 2024-01-11 21:03:43 UTC
*** Bug 911162 has been marked as a duplicate of this bug. ***