Re: [RFC] sys_setrlimit() in 2.6.16



Cliff Wickman <cpw@xxxxxxx> wrote:

A test suite uncovered a possible bug in setrlimit(2), in 2.6.16-rc3.

A code that does
mylimits.rlim_cur = 0;
setrlimit(RLIMIT_CPU, &mylimits);
does not set a cpu time limit.

No signal is sent to this code when its "limit" of 0 seconds expires.
Whereas, under the 2.6.5 kernel (SuSE SLESS9) a signal was sent.

I don't see any obvious difference in sys_setrlimit() or
set_process_cpu_timer() between 2.6.5 and 2.6.16.

Is this a correction, or a bug?

Is a cpu time limit of 0 supposed to limit a task to 0 seconds, or
leave it unlimited?


This has to be considered a bug. The spec certainly implies that a limit
of zero should be honoured and, probably more importantly, that's how it
works in 2.4.

Problem is, the code in there all assumes that an it_prof_expires of zero
means "it was never set", and changing that (add a yes-it-has flag?) would
be less than trivial.

So I think the path of least resistance here is to just convert the
caller's zero seconds into one second. That in fact gives the same
behaviour as 2.4: you get whacked after one second or more CPU time.

(This is not a final patch - that revolting expression in sys_setrlimit()
needs help first).


diff -puN kernel/sys.c~a kernel/sys.c
--- devel/kernel/sys.c~a 2006-02-16 00:42:49.000000000 -0800
+++ devel-akpm/kernel/sys.c 2006-02-16 00:45:10.000000000 -0800
@@ -1657,7 +1657,19 @@ asmlinkage long sys_setrlimit(unsigned i
(cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
new_rlim.rlim_cur <= cputime_to_secs(
current->signal->it_prof_expires))) {
- cputime_t cputime = secs_to_cputime(new_rlim.rlim_cur);
+ unsigned long rlim_cur = new_rlim.rlim_cur;
+ cputime_t cputime;
+
+ if (rlim_cur == 0) {
+ /*
+ * The caller is asking for an immediate RLIMIT_CPU
+ * expiry. But we use the zero value to mean "it was
+ * never set". So let's cheat and make it one second
+ * instead
+ */
+ rlim_cur = 1;
+ }
+ cputime = secs_to_cputime(rlim_cur);
read_lock(&tasklist_lock);
spin_lock_irq(&current->sighand->siglock);
set_process_cpu_timer(current, CPUCLOCK_PROF,
_

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



Relevant Pages

  • Re: mapped pages being truncated [was Re: 2.6.5-rc2-aa5]
    ... >> doesn't trigger anymore we still have to wonder about timings. ... I don't think it's a bug in my tree. ... zero page is reserved, so page_add_rmap does nothing on it, zero page is ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: [PATCH] Avoid buffer overflows in get_user_pages()
    ... In particular, "len" is a signed int, and it is only checked at the ... So, if it is passed in as zero, the loop ... I think that, if get_user_pageshas been asked to grab zero pages, ... Which is a bug, and you want to catch it. ...
    (Linux-Kernel)
  • Re: Malcolms new book - Chapter 1 review
    ... I still haven't been able to find this bug. ... Can said integer overflow result in a buffsize value of zero? ... If size was equal to 0, either NULL or a pointer suitable to be passed ...
    (comp.lang.c)
  • Re: Time, time, time is on my mind....
    ... John Chase wrote, ... This says that there is no wait or CPU time limit if TIME=NOLIMIT or 1440. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: REAL x(1)?
    ... On 2006-02-15 12:41:54 -0400, Ron Shepard ... That's not usually a good thing; papering over the bug doesn't make the result correct. ... Zero length arrays and character strings were added to the language for exactly this reason. ...
    (comp.lang.fortran)