Bug 248070 - kernel panic sysctl -a
Summary: kernel panic sysctl -a
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-18 15:45 UTC by lampa
Modified: 2020-07-20 14:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lampa 2020-07-18 15:45:46 UTC
uname -a
FreeBSD xxx 12.1-STABLE FreeBSD 12.1-STABLE r363310 xxxx  amd64

sysctl -a
kern.ostype: FreeBSD
kern.osrelease: 12.1-STABLE
kern.osrevision: 199506
kern.version: FreeBSD 12.1-STABLE r363310 VOJEN

kern.maxvnodes: 620153
kern.maxproc: 38036
kern.maxfiles: 1044518
kern.argmax: 524288
kern.securelevel: -1
kern.hostname: xxx
kern.hostid: 2119532645
kern.clockrate: { hz = 1000, tick = 1000, profhz = 8128, stathz = 127 }
<<<---- panic at eip 0x20:0xfffffff8058946b

bt
pget() at pget+0x200/frame 0xfffffe009f4987e0
sysctl_kern_proc_kstack() at sysctl_kern_proc_kstack+0x27
sysctl_root_handler_locked() at sysctl_root_handler_locked+0x7d
sysctl_root() at sysctl_root+0x192
userland_sysctl() ...

Source of panic is mismerge of kern_proc.c in 363038 at line 413, original was:

	 } else {
	       if (pid <= PID_MAX) {
...
               } else if ((flags & PGET_NOTID) == 0) {
                        p = pfind_tid_locked(pid);
               } else {
                        p = NULL;
               }

revision 363038:

         } else {
	       if (pid <= PID_MAX) {
...
               } else if ((flags & PGET_NOTID) == 0) {
                        td1 = tdfind(pid, -1);
                        if (td1 != NULL)
                                p = td1->td_proc;
               }

If tdfind() fails, p is not reset to NULL and also NOTID case was lost. Merge missed assignment p = NULL before if (pid <= PID_MAX):

         } else {
	       p = NULL;   /* THIS STATEMENT IS IN HEAD, NOT IN STABLE */
	       if (pid <= PID_MAX) {
...
               } else if ((flags & PGET_NOTID) == 0) {
                        td1 = tdfind(pid, -1);
                        if (td1 != NULL)
                                p = td1->td_proc;
               }

With this change, sysctl -a no longer panics.
Comment 1 commit-hook freebsd_committer freebsd_triage 2020-07-18 20:18:09 UTC
A commit references this bug:

Author: kib
Date: Sat Jul 18 20:17:41 UTC 2020
New revision: 363312
URL: https://svnweb.freebsd.org/changeset/base/363312

Log:
  Fix mismerge of r363038.

  The reset of p to NULL for non-curproc was missed, cauing ESRCH error not
  returned as it should be.

  Reported by:	lampa@fit.vutbr.cz
  PR:	248070

Changes:
  stable/12/sys/kern/kern_proc.c