Current-Users archive

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

setrlimit(2) can set stack segement hard limit lower than soft limit ?



Hi,

Juste encountered a small case where setting stack segement limits
made the hard limit smaller than the soft one, which seems problematic
to me. Soft limit should never be larger than hard limit.

The attached sample illustrate this small issue.

njoly@issan [~]> cc -o setrlimit setrlimit.c 
njoly@issan [~]> ./setrlimit 
set RLIMIT_STACK: 4192256/4192256
get RLIMIT_STACK: 4194304/4192256

Cheching the corresponding code in dosetrlimit() show rlim_cur is page
rounded ... but rlim_max is not :

[...]
                 * Since allocation is done in terms of page, roundup
                 * "rlim_cur" (otherwise, contiguous regions
                 * overlap).  If stack limit is going up make more
                 * accessible, if going down make inaccessible.
                 */
                limp->rlim_cur = round_page(limp->rlim_cur);
                if (limp->rlim_cur != alimp->rlim_cur) {
[...]

Do we need to call round_page() on limp->rlim_max too, or should we
only raise it to limp->rlim_cur if needed ?

Thanks.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
#include <sys/resource.h>

#include <assert.h>
#include <stdio.h>

int main() {
  int res;
  struct rlimit lim, new;

  lim.rlim_cur = lim.rlim_max = 4192256;
  res = setrlimit(RLIMIT_STACK, &lim);
  assert(res != -1);
  printf("set RLIMIT_STACK: %lu/%lu\n", lim.rlim_cur, lim.rlim_max);
  new.rlim_cur = new.rlim_max = 0;
  res = getrlimit(RLIMIT_STACK, &new);
  assert(res != -1);
  printf("get RLIMIT_STACK: %lu/%lu\n", new.rlim_cur, new.rlim_max);

  return 0; }


Home | Main Index | Thread Index | Old Index