From: "Michael Kerrisk" <michael.kerrisk@gmx.net>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org, michael.kerrisk@gmx.net
Subject: Off-by-one error for SIGXCPU / RLIMIT_CPU checking
Date: Mon, 02 Aug 2004 15:14:11 +0200 [thread overview]
Message-ID: <410E5A43.2482.19107E9@localhost> (raw)
Hello Andrew,
[Apologies -- resend with fixed subject line for benefit of LKML]
There is a lonstanding off-by-one error that results from an incorrect
comparison when checking whether a process has consumed CPU time in
excess of its RLIMIT_CPU limits.
This means, for example, that if we use setrlimit() to set the soft CPU
limit (rlim_cur) to 5 seconds and the hard limit (rlim_max) to 10 seconds,
then the process only receives a SIGXCPU signal after consuming 6 seconds
of CPU time, and, if it continues consuming CPU after handling that
signal, only receives SIGKILL after consuming 11 seconds of CPU time.
The fix is trivial, and included below.
Cheers,
Michael
--- /spare/KERNEL/linux-2.6.7/kernel/timer.c 2004-06-16 07:19:52.000000000 +0200
+++ /spare/KERNEL/linux-2.6.7-xcpu/kernel/timer.c 2004-08-02 09:34:10.000000000 +0200
@@ -792,12 +792,12 @@
psecs = (p->utime += user);
psecs += (p->stime += system);
- if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
+ if (psecs / HZ >= p->rlim[RLIMIT_CPU].rlim_cur) {
/* Send SIGXCPU every second.. */
if (!(psecs % HZ))
send_sig(SIGXCPU, p, 1);
/* and SIGKILL when we go over max.. */
- if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_max)
+ if (psecs / HZ >= p->rlim[RLIMIT_CPU].rlim_max)
send_sig(SIGKILL, p, 1);
}
}
reply other threads:[~2004-08-02 13:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=410E5A43.2482.19107E9@localhost \
--to=michael.kerrisk@gmx.net \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox