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

pam_limits can call setrlimit on unitialized data



	Linux-PAM-0.72/modules/pam_limits/pam_limits.c initializes
an array called "limits" one element at a time based on each resouce
type that it knows about, using getrlimit.  However, it sets the
resources values (using setrlimit) by just iterating from 0 to
RLIMIT_NLIMITS-1.  Recent Linux 2.4.0 kernels have added at least
one new resource id (RLIMIT_LOCKS), which ends up being set to
zero because the extra element in limits[] was not initialized.
This means that processes has no right to lock any files, so
many things break, such as simply sending email.

	I have attached a fix below, which also makes the code slightly
smaller.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."
----------------------------CUT HERE------------------------------------
--- Linux-PAM-0.72/modules/pam_limits/pam_limits.c	Sun Nov  7 21:46:56 1999
+++ pam/modules/pam_limits/pam_limits.c	Thu Oct 26 23:56:41 2000
@@ -229,47 +229,41 @@
     
 static int init_limits(void)
 {
+    int i;
     int retval = PAM_SUCCESS;
 
     D(("called."));
 
-    retval |= getrlimit(RLIMIT_CPU,     &limits[RLIMIT_CPU].limit);
+    for(i = 0; i < RLIMIT_NLIMITS; i++)
+    	retval |= getrlimit(i, &limits[i].limit);
+
     limits[RLIMIT_CPU].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_CPU].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_FSIZE,   &limits[RLIMIT_FSIZE].limit);
     limits[RLIMIT_FSIZE].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_FSIZE].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_DATA,    &limits[RLIMIT_DATA].limit);
     limits[RLIMIT_DATA].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_DATA].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_STACK,   &limits[RLIMIT_STACK].limit);
     limits[RLIMIT_STACK].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_STACK].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_CORE,    &limits[RLIMIT_CORE].limit);
     limits[RLIMIT_CORE].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_CORE].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_RSS,     &limits[RLIMIT_RSS].limit);
     limits[RLIMIT_RSS].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_RSS].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_NPROC,   &limits[RLIMIT_NPROC].limit);
     limits[RLIMIT_NPROC].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_NPROC].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_NOFILE,  &limits[RLIMIT_NOFILE].limit);
     limits[RLIMIT_NOFILE].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_NOFILE].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_MEMLOCK, &limits[RLIMIT_MEMLOCK].limit);
     limits[RLIMIT_MEMLOCK].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_MEMLOCK].src_hard = LIMITS_DEF_NONE;
 
-    retval |= getrlimit(RLIMIT_AS,      &limits[RLIMIT_AS].limit);
     limits[RLIMIT_AS].src_soft = LIMITS_DEF_NONE;
     limits[RLIMIT_AS].src_hard = LIMITS_DEF_NONE;
     priority = 0;





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