From c08e8bdab034508e671d6fb41eb590407fb70fad Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 28 Nov 1999 17:51:09 +0000 Subject: 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 --- sys/kern/kern_fork.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_fork.c') 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) { -- cgit v1.1