aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2009-09-03 13:21:45 -0400
committerJiri Slaby <jirislaby@gmail.com>2010-07-16 03:48:46 -0400
commit2fb9d2689a0041b88b25bc3187eada2968e25995 (patch)
tree28c25b5092a209cd55d5d3f29dea827bdde70abe /kernel
parent5ab46b345e418747b3a52f0892680c0745c4223c (diff)
rlimits: make sure ->rlim_max never grows in sys_setrlimit
Mostly preparation for Jiri's changes, but probably makes sense anyway. sys_setrlimit() checks new_rlim.rlim_max <= old_rlim->rlim_max, but when it takes task_lock() old_rlim->rlim_max can be already lowered. Move this check under task_lock(). Currently this is not important, we can only race with our sub-thread, this means the application is stupid. But when we change the code to allow the update of !current task's limits, it becomes important to make sure ->rlim_max can be lowered "reliably" even if we race with the application doing sys_setrlimit(). Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sys.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/sys.c b/kernel/sys.c
index f5183b08adfc..f2b2d7aa3818 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1283,10 +1283,6 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
1283 return -EFAULT; 1283 return -EFAULT;
1284 if (new_rlim.rlim_cur > new_rlim.rlim_max) 1284 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1285 return -EINVAL; 1285 return -EINVAL;
1286 old_rlim = current->signal->rlim + resource;
1287 if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
1288 !capable(CAP_SYS_RESOURCE))
1289 return -EPERM;
1290 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open) 1286 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
1291 return -EPERM; 1287 return -EPERM;
1292 1288
@@ -1304,11 +1300,16 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
1304 new_rlim.rlim_cur = 1; 1300 new_rlim.rlim_cur = 1;
1305 } 1301 }
1306 1302
1303 old_rlim = current->signal->rlim + resource;
1307 task_lock(current->group_leader); 1304 task_lock(current->group_leader);
1308 *old_rlim = new_rlim; 1305 if (new_rlim.rlim_max > old_rlim->rlim_max &&
1306 !capable(CAP_SYS_RESOURCE))
1307 retval = -EPERM;
1308 else
1309 *old_rlim = new_rlim;
1309 task_unlock(current->group_leader); 1310 task_unlock(current->group_leader);
1310 1311
1311 if (resource != RLIMIT_CPU) 1312 if (retval || resource != RLIMIT_CPU)
1312 goto out; 1313 goto out;
1313 1314
1314 /* 1315 /*
@@ -1322,7 +1323,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
1322 1323
1323 update_rlimit_cpu(current, new_rlim.rlim_cur); 1324 update_rlimit_cpu(current, new_rlim.rlim_cur);
1324out: 1325out:
1325 return 0; 1326 return retval;
1326} 1327}
1327 1328
1328/* 1329/*