If the user tries to set kern.randompid to 1 (which is meaningless), set

it to a random value between 100 and 1123, rather than 0 as before.

Submitted by:	Marie Helene Kvello-Aune <marieheleneka@gmail.com>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D5336
This commit is contained in:
Dag-Erling Smørgrav 2017-09-10 15:01:29 +00:00
parent 44832ad99d
commit 008a09355b

View File

@ -208,20 +208,26 @@ sysctl_kern_randompid(SYSCTL_HANDLER_ARGS)
pid = randompid;
error = sysctl_handle_int(oidp, &pid, 0, req);
if (error == 0 && req->newptr != NULL) {
if (pid < 0 || pid > pid_max - 100) /* out of range */
pid = pid_max - 100;
else if (pid < 2) /* NOP */
pid = 0;
else if (pid < 100) /* Make it reasonable */
pid = 100;
randompid = pid;
if (pid == 0)
randompid = 0;
else if (pid == 1)
/* generate a random PID modulus between 100 and 1123 */
randompid = 100 + arc4random() % 1024;
else if (pid < 0 || pid > pid_max - 100)
/* out of range */
randompid = pid_max - 100;
else if (pid < 100)
/* Make it reasonable */
randompid = 100;
else
randompid = pid;
}
sx_xunlock(&allproc_lock);
return (error);
}
SYSCTL_PROC(_kern, OID_AUTO, randompid, CTLTYPE_INT|CTLFLAG_RW,
0, 0, sysctl_kern_randompid, "I", "Random PID modulus");
0, 0, sysctl_kern_randompid, "I", "Random PID modulus. Special values: 0: disable, 1: choose random value");
static int
fork_findpid(int flags)