proc仮想ファイルシステムのLinuxマウントポイント?

proc仮想ファイルシステムのLinuxマウントポイント?

この質問をstackoverflowからここに移動するように求められました。

私はguitmzのmemrun repoをフォークしました(asmとgo用)。
私のフォークにはCのmemrunとmemfd_createがあります。
https://github.com/Hermann-SW/memrun?organization=Hermann-SW&organization=Hermann-SW#fork-mission-statement

memfd_create.cメモリファイル(/memfd:...)を生成し、プロセスpidとメモリファイル記述子を返します。

pi@raspberrypi400:~/memrun/C $ gcc memfd_create.c -o memfd_create
pi@raspberrypi400:~/memrun/C $ ./memfd_create
1880 3
pi@raspberrypi400:~/memrun/C $ ls -l /proc/1880/fd
total 0
lrwx------ 1 pi pi 64 Oct  6 20:54 0 -> /dev/pts/0
lrwx------ 1 pi pi 64 Oct  6 20:54 1 -> /dev/pts/0
lrwx------ 1 pi pi 64 Oct  6 20:54 2 -> /dev/pts/0
lrwx------ 1 pi pi 64 Oct  6 20:54 3 -> '/memfd:rab.oof (deleted)'
pi@raspberrypi400:~/memrun/C $ 

インメモリファイルに10MBのファイルシステムを作成する方法は次のとおりです。

pi@raspberrypi400:~/memrun/C $ dd if=/dev/zero of=/proc/1880/fd/3 bs=1024 count=10240 2> /dev/null
pi@raspberrypi400:~/memrun/C $ mkfs.ext2 /proc/1880/fd/3 > /dev/null
mke2fs 1.44.5 (15-Dec-2018)
pi@raspberrypi400:~/memrun/C $

32ビットRaspberry Pi OS(debian)および64ビットIntel Ubuntuでは、/ proc(!)の下にファイルシステムをマウントできます。

pi@raspberrypi400:~/memrun/C $ ls -l /proc/1880/fd
total 12
drwx------ 2 root root 12288 Oct  6 20:56 lost+found
pi@raspberrypi400:~/memrun/C $ 

/proc の下の同じマウントは Red Hat Enterprise Linux では機能しません。

$ ./memfd_create
26611 3
$ ls -l /proc/26611/fd
total 0
lrwx------. 1 stammw stammw 64 Oct  6 21:00 0 -> /dev/pts/0
lrwx------. 1 stammw stammw 64 Oct  6 21:00 1 -> /dev/pts/0
lrwx------. 1 stammw stammw 64 Oct  6 21:00 2 -> /dev/pts/0
lrwx------. 1 stammw stammw 64 Oct  6 21:00 3 -> '/memfd:rab.oof (deleted)'
$ 
$ dd if=/dev/zero of=/proc/26611/fd/3 bs=1024 count=10240 2> /dev/null
$ mkfs.ext2 /proc/26611/fd/3 > /dev/null
mke2fs 1.45.6 (20-Mar-2020)
$ 
$ sudo mount /proc/26611/fd/3 /proc/26611/fd
[sudo] password for stammw: 
mount: /proc/26611/fd: cannot mount /dev/loop0 read-only.
$

/proc 以下のインストールはまったく機能しないのですか?
それでは、RHELの/ procに正常にマウントするには何が必要ですか?

おそらく私がこれをしたのは、tcc "-run"オプションがg ++ / gcc、すべてのgcc / g ++一時ファイル、およびRAMの実行可能ファイルを強化し、RAMで実行するためです。

pi@raspberrypi400:~/memrun/C $ fortune -s | bin/g++ -run demo.cpp foo 123
bar foo
Sorry.  I forget what I was going to say.
pi@raspberrypi400:~/memrun/C $ 
pi@raspberrypi400:~/memrun/C $ cat demo.cpp 
/**
*/
#include <iostream>

int main(int argc, char *argv[])
{
  printf("bar %s\n", argc>1 ? argv[1] : "(undef)");

  for(char c; std::cin.read(&c, 1); )  { std::cout << c; }

  return 0;
}
pi@raspberrypi400:~/memrun/C $

他のスレッドの最初の答え:

RHEL 出力には権限の後に . が表示されます。これは、他のSELinux権限が適用されていることを意味します。彼らが何であるかを見ることができますか? - 他の人

RHELから:

$ sudo ls -Z /proc/26611/fd
[sudo] password for stammw: 
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 0
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 1
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 2
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 3
$
$ ls -Z /proc/26611 | grep fd$
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 fd
$

ベストアンサー1

/proc の下の同じマウントは Red Hat Enterprise Linux では機能しません。
mount: /proc/26611/fd: cannot mount /dev/loop0 read-only.

ログを確認し、その中に何があるか試してみてください。

[root@rhel8 ~]# journalctl --no-pager -n1 | sed 's/^ *//'
-- Logs begin at Thu 2021-10-07 03:05:03 BST, end at Thu 2021-10-07 03:10:49 BST. --
Oct 07 03:06:54 rhel8.od platform-python[2154]: SELinux is preventing mount from mounton access on the directory /proc/<pid>/fd.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that mount should be allowed mounton access on the fd directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'mount' --raw | audit2allow -M my-mount
# semodule -X 300 -i my-mount.pp

しかし、私はこれが良い考えだとは思わない。 NETにインストールする代わりに、そのままにして他のものを試すことをお勧めします/proc/<pid>/fd

tcc "-run"オプションはg ++ / gcc、RAM上のすべてのgcc / g ++一時ファイルと実行可能ファイルを強化し、RAM上で実行します。

一時ディレクトリやtmpfsが適しているため、自分自身が複雑すぎます。

おすすめ記事