resource limits bug

Raymond Nijssen (raymond@woensel.ics.ele.tue.nl)
Sun, 5 Sep 1999 01:01:07 -0700 (PDT)


The 2.2.5 kernel lets non-privileged users increase resource limits beyond
maximum value and even beyond kernel maximum values as shown in the code
snippet below.

On 2.0.35 kernels resource limits seem to be totally broken.

BTW, why are most "unlimited" kernel limits set to 2G (that is, LONG_MAX in
include/asm-*/resource.h) while 3G or so would be more correct?

Thanks,
-Raymond

102[linux1:]~/src/test>uname -a
Linux linux1 2.2.5-15smp #1 SMP Mon Apr 19 22:43:28 EDT 1999 i686 unknown

102[linux1:]~/src/test>id
uid=114(raymond) gid=101(utmp) groups=101(utmp),100(users)

103[linux1:]~/src/test>cat rlim.c
#include <sys/resource.h>
#include <stdio.h>

#define linux22

int main() {
struct rlimit rlim;
int rv;

printf("Default: (max,cur)\n");
rv = getrlimit(RLIMIT_DATA,&rlim);
if ( rv == -1 )
perror("getrlimit");
else
printf("rlimit_data:%lu,%lu\n", rlim.rlim_max, rlim.rlim_cur);

#ifdef linux22
rv = getrlimit(RLIMIT_AS,&rlim);
if ( rv == -1 )
perror("getrlimit");
else
printf("rlimit_as:%lu,%lu\n", rlim.rlim_max, rlim.rlim_cur);
#endif

printf("Setting rlimits\n");
rlim.rlim_cur=rlim.rlim_max=(unsigned)(2.75*1024*1024*1024);
#ifdef linux22
rv = setrlimit( RLIMIT_AS, &rlim );
if ( rv == -1 )
perror("setrlimit");
#endif
rv = setrlimit( RLIMIT_DATA, &rlim );
if ( rv == -1 )
perror("setrlimit");


printf("After: (max,cur)\n");
rv = getrlimit(RLIMIT_DATA,&rlim);
if ( rv == -1 )
perror("getrlimit");
else
printf("rlimit_data:%lu,%lu\n", rlim.rlim_max, rlim.rlim_cur);

#ifdef linux22
rv = getrlimit(RLIMIT_AS,&rlim);
if ( rv == -1 )
perror("getrlimit");
else
printf("rlimit_as:%lu,%lu\n", rlim.rlim_max, rlim.rlim_cur);
#endif
return 0;
}

104[linux1:]~/src/test>gcc -Wall rlim.c
105[linux1:]~/src/test>./a.out
Default: (max,cur)
rlimit_data:2147483647,2896167424
rlimit_as:2147483647,2147483647
Setting rlimits
After: (max,cur)
rlimit_data:2952790016,2952790016
rlimit_as:2952790016,2952790016

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/