News for hackers. Stuff that matters.
Re:ICPP – Running C++ in anywhere like a script by jokoon on Thursday August 08, 2024 @09:27AM (#41191254)
I don't suppose modern os would let you do that today, sounds like a security nightmare
Re:ICPP – Running C++ in anywhere like a script by fluoridation on Thursday August 08, 2024 @09:46AM (#41191448)
Yes, any modern OS lets any process load into its memory space binaries from anywhere the user has permissions, even if those are binaries it generated just now. It can be a security problem if the binaries are generated from untrusted sources (e.g. you download some, say, Haskell, compile it and run it fully automatically).
Re:ICPP – Running C++ in anywhere like a script by shortrounddev2 on Thursday August 08, 2024 @10:10AM (#41191728)
Windows has a private heap system where you can disable code execution from the pages allocated to `HeapCreate`, if you don't* set that flag:

https://learn.microsoft.com/en-us/windows/win32/api/heapapi/...

> HEAP_CREATE_ENABLE_EXECUTE

> 0x00040000

> All memory blocks that are allocated from this heap allow code execution, if the hardware enforces data execution prevention. Use this flag heap in applications that run code from the heap. If HEAP_CREATE_ENABLE_EXECUTE is not specified and an application attempts to run code from a protected page, the application receives an exception with the status code STATUS_ACCESS_VIOLATION.

I think POSIX has equivalent memory protection calls, but no equivalent to HeapCreate

Re:ICPP – Running C++ in anywhere like a script by fluoridation on Thursday August 08, 2024 @12:05PM (#41193008)
But you can still call VirtualAlloc(), VirtualProtect(), and LoadLibrary(), so this isn't really a security mechanism, but more of a safety mechanism.

I don't think Windows provides a mechanism to disable creating any further executable pages, although I've seen Chrome do it by hooking those functions (and I know it because I've had to bypass it :)).

Re:ICPP – Running C++ in anywhere like a script by pjmlp on Thursday August 08, 2024 @12:52PM (#41193610)
App Sandboxing and VBS enclaves go onto that direction.
Re:ICPP – Running C++ in anywhere like a script by shortrounddev2 on Thursday August 08, 2024 @01:12PM (#41193856)
I wouldn't expect windows to prevent creating further executable pages; there are legitimate use cases for creating dynamically allocated executable memory. It just means that whatever foreign data you load into those pages can't execute, which is a security mechanism (for example, game save data can be loaded into these heaps so that you can load all game state but without the save file potentially running foreign code)
Re:ICPP – Running C++ in anywhere like a script by fluoridation on Thursday August 08, 2024 @02:00PM (#41194407)
There are legitimate uses, but the point would be that the process could ask the system to lock it down with whatever executable code is already present. This could be used to prevent already running code from tampering with the process' behavior by loading new code, or to thwart code injection.

>It just means that whatever foreign data you load into those pages can't execute, which is a security mechanism (for example, game save data can be loaded into these heaps so that you can load all game state but without the save file potentially running foreign code)

But malloc() and all the other standard memory allocation functions already return pointers into non-executable pages, anyway. Perhaps those functions call into this one internally, but using this over whatever your language offers by default offers no additional protection.

Re:ICPP – Running C++ in anywhere like a script by shortrounddev2 on Friday August 09, 2024 @09:08AM (#41201476)
The benefit of heapalloc and heapcreate is that it makes serialization of data simpler because you can define the bounds of the heap so you can easily save pointer offsets. There are other flags available as well. It's a win32 feature so you would only use it if windows is your target platform (and then write other bindings for other platforms)
Re:ICPP – Running C++ in anywhere like a script by fluoridation on Friday August 09, 2024 @09:40AM (#41201726)
I still don't get it. Why can't you do the same with a regular buffer?
Re:ICPP – Running C++ in anywhere like a script by adzm on Thursday August 08, 2024 @01:30PM (#41194101)
All of this calls VirtualAlloc behind the scenes, and you can do that yourself as well for manual page allocation. Each page can have options set with VirtualProtect to allow or disallow execution of code within the pages as well.
Re:ICPP – Running C++ in anywhere like a script by IshKebab on Thursday August 08, 2024 @01:43PM (#41194223)
iOS won't let you do that. Or at least Apple won't let you do that on iOS.
Re:ICPP – Running C++ in anywhere like a script by fluoridation on Thursday August 08, 2024 @02:39PM (#41194804)
What's actually happening is that the SDK doesn't expose the system calls necessary to do it, but I can guarantee that if you can get a native binary to run on the device, you can have it do whatever you want. If that wasn't the case, the few apps that do support JITting wouldn't work.
Re:ICPP – Running C++ in anywhere like a script by shortrounddev2 on Thursday August 08, 2024 @09:37AM (#41191344)
This is just JIT'ing. It's used in python and lua commonly
Re:ICPP – Running C++ in anywhere like a script by pjmlp on Thursday August 08, 2024 @09:46AM (#41191449)
I wish, JIT and Python still isn't something to brag about.
Re:ICPP – Running C++ in anywhere like a script by greenavocado on Thursday August 08, 2024 @10:28AM (#41191918)
Python 3.13 has an experimental JIT compiler https://peps.python.org/pep-0744/
Re:ICPP – Running C++ in anywhere like a script by pjmlp on Thursday August 08, 2024 @11:36AM (#41192670)
As I said, not something to brag about.
Re:ICPP – Running C++ in anywhere like a script by HelloNurse on Friday August 09, 2024 @02:55AM (#41199391)
It's just loading a dynamic library from an arbitrary file, as traditionally done for third party software addons (e.g. Photoshop plugins since the early 1990s and VST instruments and effects since the late 1990s).