Date: Sun, 10 Sep 2017 15:01:29 +0000 (UTC) From: =?UTF-8?Q?Dag-Erling_Sm=c3=b8rgrav?= <des@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323390 - head/sys/kern Message-ID: <201709101501.v8AF1Tr4061705@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: des Date: Sun Sep 10 15:01:29 2017 New Revision: 323390 URL: https://svnweb.freebsd.org/changeset/base/323390 Log: 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 Modified: head/sys/kern/kern_fork.c Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Sun Sep 10 13:53:42 2017 (r323389) +++ head/sys/kern/kern_fork.c Sun Sep 10 15:01:29 2017 (r323390) @@ -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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201709101501.v8AF1Tr4061705>