Michal Srb via llvm-dev
2017-Jul-15 11:57 UTC
[llvm-dev] SectionMemoryManager::finalizeMemory ... read only data become executable?
On Saturday, 15 July 2017 05:46:35 CEST 陳韋任 wrote:> SectionMemoryManager allocates executable memory section for MCJIT > (JIT emit code then execute). > So the bottomline is making the section sys::Memory::MF_EXEC. As for > RODataMem, we also need > to make sure it's read-only. You can compare it to RWDataMem, which > has write permission.That makes sense. My question is why is RODataMem made READ and EXEC? It sounds like it should be only READ. Michal
陳韋任 via llvm-dev
2017-Jul-15 12:55 UTC
[llvm-dev] SectionMemoryManager::finalizeMemory ... read only data become executable?
Hi Michal, 2017-07-15 19:57 GMT+08:00 Michal Srb <msrb at suse.com>:> On Saturday, 15 July 2017 05:46:35 CEST 陳韋任 wrote: >> SectionMemoryManager allocates executable memory section for MCJIT >> (JIT emit code then execute). >> So the bottomline is making the section sys::Memory::MF_EXEC. As for >> RODataMem, we also need >> to make sure it's read-only. You can compare it to RWDataMem, which >> has write permission. > > That makes sense. My question is why is RODataMem made READ and EXEC? It > sounds like it should be only READ.I guess my reply is a little bit misleading. Since JIT will emit and *execute* code in the memory, the memory should be set as MF_EXEC at least. As RODataMem is read-only, we should make it MF_READ as well. I think MF_EXEC and MF_READ will be set after the code is emitted. Regards, chenwj -- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj
Tim Northover via llvm-dev
2017-Jul-15 12:58 UTC
[llvm-dev] SectionMemoryManager::finalizeMemory ... read only data become executable?
On 15 July 2017 at 08:55, 陳韋任 via llvm-dev <llvm-dev at lists.llvm.org> wrote:> I guess my reply is a little bit misleading. Since JIT will emit and > *execute* code in the memory,Not all bytes that get emitted are intended to be executed. In ELF section terms, .text needs to be executable, but .rodata doesn't. It contains data that will be loaded by the actual instructions so it needs to be readable, but making it executable is a potential security risk. Cheers. Tim.