summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authordan <dan@FreeBSD.org>1999-11-28 17:51:09 +0000
committerdan <dan@FreeBSD.org>1999-11-28 17:51:09 +0000
commitc08e8bdab034508e671d6fb41eb590407fb70fad (patch)
tree2e25813b211bffa6faa57f93df369219caaac650 /sys/kern
parentbd4a9519d9129db340eceb6bf445a32cd1c7a2b4 (diff)
downloadFreeBSD-src-c08e8bdab034508e671d6fb41eb590407fb70fad.zip
FreeBSD-src-c08e8bdab034508e671d6fb41eb590407fb70fad.tar.gz
Introduce OpenBSD-like Random PIDs. Controlled by a sysctl knob
(kern.randompid), which is currently defaulted off. Use ARC4 (RC4) for our random number generation, which will not get me executed for violating crypto laws; a Good Thing(tm). Reviewed and Approved by: bde, imp
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_fork.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index c12c965..9f3feb2 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -142,6 +142,9 @@ rfork(p, uap)
int nprocs = 1; /* process 0 */
static int nextpid = 0;
+static int randompid = 0;
+SYSCTL_INT(_kern, OID_AUTO, randompid, CTLFLAG_RW, &randompid, 0, "");
+
int
fork1(p1, flags, procp)
struct proc *p1;
@@ -262,8 +265,8 @@ retry:
* restart somewhat above 0, as the low-numbered procs
* tend to include daemons that don't exit.
*/
- if (nextpid >= PID_MAX) {
- nextpid = 100;
+ if (nextpid >= PID_MAX || randompid) {
+ nextpid = (randompid) ? arc4random() % PID_MAX : 100;
pidchecked = 0;
}
if (nextpid >= pidchecked) {
OpenPOWER on IntegriCloud