RFR: 8356597: AOT cache and CDS archive should not be created in read-only mode
Ioi Lam
iklam at openjdk.org
Fri May 9 15:44:52 UTC 2025
On Fri, 9 May 2025 11:33:55 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> src/hotspot/share/cds/filemap.cpp line 750:
>>
>>> 748: // allow processes that have it open continued access to the file.
>>> 749: remove(_full_path);
>>> 750: int fd = os::open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
>>
>> Why `0666`, though, i.e. world-writable? None of the tools, AFAICS from your examples, do world-writability. Should be at most `0664`?
>
> Also matches what Linux does:
>
>
> $ rm 1; touch 1; stat 1 | grep Access
> Access: (0664/-rw-rw-r--) Uid: ( 1000/ shade) Gid: ( 1000/ shade)
We have existing code that uses `0666`
./share/ci/ciEnv.cpp: int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
./share/ci/ciEnv.cpp: int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
./share/runtime/os.cpp: int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
./share/utilities/vmError.cpp: fd = open(buf, mode, 0666);
`0666` is the default mode on Linux (posix?). The actual file mode will be combined with umask.
(And your umask happens to be `002` so you get `rw-rw-r--` instead of `rw-r--r--` :-) )
$ umask
0002
$ rm -f foo
$ strace -f touch foo 2>&1 | grep 'foo.*O_CREAT'
openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
$ ls -l foo
-rw-rw-r-- 1 iklam iklam 0 May 9 08:36 foo
Also Javac does the same:
$ rm -f HelloWorld.class
$ strace -f jdk24/bin/javac HelloWorld.java 2>&1 | grep O_CREAT.*HelloWorld.class
[pid 3673548] openat(AT_FDCWD, "/tmp/HelloWorld.class", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
$ ls -l HelloWorld.class
-rw-rw-r-- 1 iklam iklam 425 May 9 08:37 HelloWorld.class
and
$ umask 022
$ rm -f HelloWorld.class
$ strace -f /jdk3/official/jdk24/bin/javac HelloWorld.java 2>&1 | grep HelloWorld.class | grep O_CREAT
[pid 3674853] openat(AT_FDCWD, "/jdk3/tmp/HelloWorld.class", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
$ ls -l HelloWorld.class
-rw-r--r-- 1 iklam iklam 425 May 9 08:37 HelloWorld.class
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25137#discussion_r2081959509
More information about the hotspot-runtime-dev
mailing list