lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Fri, Mar 03, 2017 at 05:00:42PM +0100, Enrico Colombini wrote:
> On 03-Mar-17 13:19, Lorenzo Donati wrote:
> >Anyway the solution is easy, just enclose the function in a
> >wrapper function that does size checking against a limit reasonable for
> >_your_ setup/system.
> A custom allocator limiting total allocation would protect against any
> memory-based DoS, as far as Lua is concerned.

For most Unix-like systems the process memory limit can be set from the
shell envionment using

  $ ulimit -d [SIZE]

Afterwards, the limit will be inherited by any newly invoked processes.

The ulimit command just uses the POSIX-defined interface:

  struct rlimit rlim;
  getrlimit(RILMIT_DATA, &rlim); // get current values
  rlim.rlim_cur = [SIZE]; // change soft limit, keep hard limit
  setrlimit(RLIMIT_DATA, &rlim);

When a process reaches the soft limit malloc will fail, even on Linux with
aggressive overcommit enabled. The soft limit can be adjusted up and down,
but cannot be more than the hard limit. The hard limit can only be adjusted

Most Linux distributions set a data limit of infinity. Other systems, like
OpenBSD, set much stricter defaults.