[PATCH] riscv: mmap with PROT_WRITE but no PROT_READ is invalid

Coelacanthus coelacanthushex at gmail.com
Tue Oct 11 04:31:34 PDT 2022


On 2022/10/11 19:23, Heinrich Schuchardt wrote:

> 
> On 10/6/22 21:17, Eva Kotova wrote:
>> On Tue, 31 May 2022 00:56:52 PDT (-0700), coelacanthus at outlook.com wrote:
>>  > As mentioned in Table 4.5 in RISC-V spec Volume 2 Section 4.3, write
>>  > but not read is "Reserved for future use.". For now, they are not 
>> valid.
>>  > In the current code, -wx is marked as invalid, but -w- is not marked
>>  > as invalid.
>>
>> This patch breaks OpenJDK/Java on RISC-V, as it tries to create a 
>> w-only protective page:
>>
>> #
>> # There is insufficient memory for the Java Runtime Environment to 
>> continue.
>> # Native memory allocation (mmap) failed to map 4096 bytes for failed 
>> to allocate memory for PaX check.
>> # An error report file with more information is saved as:
>> # /root/hs_err_pid107.log
>>
>> I bisected to this commit since on Linux 5.19+ java no longer works.
>> Perhaps some fallback should be implemented, to prevent userspace 
>> breakage. It is currently documented, that at least on i386 PROT_WRITE 
>> mappings imply PROT_READ (See man mmap(2) NOTES), this would be a good 
>> place to start.
> 
> Which test case demonstrates the issue?
> 
> Best regards
> 
> Heinrich
> 

In check_pax function[1], jdk use mmap with PROT_WRITE.

    void* p = ::mmap(NULL, size, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,0);


[1]: https://github.com/openjdk/jdk/blob/f694f8a7671002559e7d23fdb65d5e9c768f9c03/src/hotspot/os/linux/os_linux.cpp#L4306

Best regards,
Celeste
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x15F4180E73787863.asc
Type: application/pgp-keys
Size: 8359 bytes
Desc: OpenPGP public key
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20221011/e14ceb91/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20221011/e14ceb91/attachment.sig>


More information about the linux-riscv mailing list