Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux without memfd support #3

Open
HarryR opened this issue Jan 20, 2017 · 0 comments
Open

Linux without memfd support #3

HarryR opened this issue Jan 20, 2017 · 0 comments

Comments

@HarryR
Copy link
Collaborator

HarryR commented Jan 20, 2017

e.g. Bash on Windows, or 'Linux' zones in Solaris...

__NR_memfd_create is a preprocessor macro, so we can test for it's existence at compile-time and disable code which uses that syscall.

At runtime we already check for errno == ENOSYS, presumably Bash on Windows will act accordingly so the shm_open fallback can be run.

If shm_open fails, which is really just a wrapper around opening from /dev/shm, then the portable UNIX-like file_exec will be used.

Original commit: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9183df25fe7b194563db3fec6dc3202a5855839c

Another interesting option is O_TMPFILE, supported since Linux 3.11, whereas memfd_create is supported only in Linux 3.17, it's unlikely that either are supported by 'Bash on Windows':

          Specifying O_EXCL in conjunction with O_TMPFILE prevents a
          temporary file from being linked into the filesystem in the
          above manner.  (Note that the meaning of O_EXCL in this case
          is different from the meaning of O_EXCL otherwise.)

          There are two main use cases for O_TMPFILE:

          *  Improved tmpfile(3) functionality: race-free creation of
             temporary files that (1) are automatically deleted when
             closed; (2) can never be reached via any pathname; (3) are
             not subject to symlink attacks; and (4) do not require the
             caller to devise unique names.

          *  Creating a file that is initially invisible, which is then
             populated with data and adjusted to have appropriate
             filesystem attributes (fchown(2), fchmod(2), fsetxattr(2),
             etc.)  before being atomically linked into the filesystem
             in a fully formed state (using linkat(2) as described
             above).

          O_TMPFILE requires support by the underlying filesystem; only
          a subset of Linux filesystems provide that support.  In the
          initial implementation, support was provided in the ext2,
          ext3, ext4, UDF, Minix, and shmem filesystems.  Support for
          other filesystems has subsequently been added as follows: XFS
          (Linux 3.15); Btrfs (Linux 3.16); F2FS (Linux 3.16); and ubifs
          (Linux 4.9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant