[Bug 247790] PIDs are no longer randomized after reaching pid_max
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Sun Jul 5 20:30:37 UTC 2020
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247790
Bug ID: 247790
Summary: PIDs are no longer randomized after reaching pid_max
Product: Base System
Version: CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs at FreeBSD.org
Reporter: kd-dev at pm.me
Created attachment 216234
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=216234&action=edit
Wrap `trypid' with a modulus.
Overview:
If `random' pushes `trypid' over the `max_pid' threshold then
`trypid' is reset to 2 and is no-longer randomized.
Steps to Reproduce:
# sysctl kern.randompid=10240 # Unreasonably large for a smaller test
# for x in `jot 100`; do
> sh -c 'echo $$'
> done | awk '{print length}' | sort -n | uniq -c
Expected Results:
Longer PIDs are orders of magnitude more likely than smaller PIDs.
> 1 3
> 8 4
> 91 5
Actual Results:
Two-digit PIDs are far more likely than they should be.
> 5 2
> 10 4
> 85 5
Additional Information:
Only CURRENT is affected.
Patch:
The attached patch wraps `trypid' with a modulus rather than simply
setting it to 2. I have successfully compiled the patch without
warnings, and am currently running the patched kernel.
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list