4 ms·
this talks about locking down network and filesystem access, but does Win32 App Isolation also offer a way to restrict CPU and memory usage? I want to be able
by simonw 3y ago
this talks about locking down network and filesystem access, but does Win32 App Isolation also offer a way to restrict CPU and memory usage?
I want to be able to run untrusted code in a sandbox such that "while True" won't exhaust my system resources, and with a limit on the amount of memory that the sandboxed program can allocate itself.
- fbdab103 3y agoWhat's the best way to accomplish this on Linux? If there is a good mechanism, can you apply it to a currently running process or do you have to pre-define available resources? The only trick I have up my sleeve is to use earlyoom to abort misbehaving processes if I suddenly squander all of my ram.
- NekkoDroid 3y agoI do remember systemd having `CPUQuota` to set an absolute limit, I am not sure if this is only limited to actual units or if this can be applied to slices as well (KDE and GNOME default to running individual desktop apps in their own slice IIRC), but from the quick glance I took on https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html https://www.freedesktop.org/software/systemd/man/latest/syst... I think it should be possible also to do it on a per slice basis.
- marwis 3y agoI'm not an expert on the subject but just happen to know this was possible since XP: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns... See JOB_OBJECT_LIMIT_PROCESS_MEMORY and JOB_OBJECT_LIMIT_PROCESS_TIME. Job is basically Windows equivalent of Linux Control Group.
- dataflow 3y agoNo, the CPU one isn't the same. It's a cumulative limit (resulting in termination when exceeded). The parent is asking for rate limits (resulting in throttling when exceeded).
- marwis 3y agoIt's not really clear from OP that it's about rate. Cumulative limit would still fulfill requirement of stopping while(true) from exhausting resources. But if you need rate there's this: JOB_OBJECT_ CPU_RATE_CONTROL_MIN_MAX_RATE https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns...
- deleted 3y ago[deleted]
- dataflow 3y agoIt's not explicitly written, but it's a pretty unavoidable conclusion. As far as the verbiage goes -- "doesn't exhaust" means "uses less than the full amount available". Given that "total CPU time" isn't something you can run out of, "doesn't exhaust CPU" can only mean "uses less CPU than is currently available", i.e. "utilizes < 100% of the CPU", i.e. throttling. As a practical matter, pretty much ~no user wants to kill a program after N seconds, and ~no program can limit itself to N seconds of work, either. People just want their CPU to have bandwidth to do other work, avoid heating up, etc. So unless you have a strong reason to believe otherwise, it's fair to assume people want to limit CPU utilization, not total CPU time.
- mike_hearn 3y ago> pretty much ~no user wants to kill a program after N seconds This is exactly how the web and cloud FaaS like AWS Lambda does it, so I don't think it's right to say nobody wants this. Runaway code does need to be killed.
- dataflow 3y agoI didn't say nobody wants this, I said no user wants this. We're not talking web servers, we're talking about Windows desktop apps here... with humans using them. User != admin != owner. "Web and cloud FaaS like AWS Lambda" don't have "users" (i.e. the kind who would say "this shouldn't exhaust my system resources" like the parent did). They're cattle, running batch jobs, and/or serving APIs that other client applications invoke...
- anitil 3y ago(Off topic, but heads up I'm getting NET::ERR_CERT_COMMON_NAME_INVALID at https://simonwillison.net/ https://simonwillison.net/ and https://www.simonwillison.net https://www.simonwillison.net is redirecting to 123-reg.co.uk )
- simonw 3y agoShould be fixed now!
- mike_hearn 3y agoApp Isolation is a feature layered on top of low level sandbox primitives and IIRC it doesn't support this. On the other hand, it also wouldn't make sense for App Isolation because that's intended to give apps a lightweight way to opt-in to isolating themselves, in order to restrict the blast radius of exploits. It's not intended to let you run arbitrary third party code sandboxed. For that you would need to use something more like the Chromium sandbox that uses kernel job objects, which a sibling comment describes. Using that would require fluency in Win32.