Date: Fri, 16 Mar 2001 20:23:51 -0800 From: Dima Dorfman <dima@unixfreak.org> To: hackers@freebsd.org Subject: sysctl_kern_proc doesn't handle the case when no procs match given criteria Message-ID: <20010317042351.C1B283E23@bazooka.unixfreak.org>
next in thread | raw e-mail | index | archive | help
Hello -hackers The sysctl_kern_proc routine in kern_proc.c doesn't handle the case when no processes match the given criteria. I.e., if no processes match, it will return 0 even though it never called SYSCTL_OUT; thus, the output data is junk. This can be demonstrated by giving ps(1) arguments such that no processes match. In this example, the user `nobody' isn't running anything: dd@ref5% ps U nobody ps: kinfo_proc size mismatch (expected 648, got -791621424) Obviously, this isn't the desired mode of failure. Attached is a patch that will make sysctl_kern_proc return ESRCH if it didn't find any processes. AFAIK, without the patch, the only way to detect this condition (no processes match search criteria) is to check that a call into this routine via sysctl didn't modify whatever is pointed at by the oldp pointer (see sysctl(3)). Comments? Suggestions? Thanks Dima Dorfman dima@unixfreak.org P.S. libkvm and/or ps(1) should probably be taught to check for this condition and react more gently (on -stable, ps just prints the column labels when this happens). I'll probably do this later. Index: kern_proc.c =================================================================== RCS file: /st/src/FreeBSD/src/sys/kern/kern_proc.c,v retrieving revision 1.89 diff -u -r1.89 kern_proc.c --- kern_proc.c 2001/03/07 06:52:12 1.89 +++ kern_proc.c 2001/03/17 04:20:49 @@ -555,6 +555,7 @@ struct proc *p; int doingzomb; int error = 0; + int match = 0; if (oidp->oid_number == KERN_PROC_PID) { if (namelen != 1) @@ -640,9 +641,12 @@ ALLPROC_LOCK(AP_RELEASE); return (error); } + match = 1; } } ALLPROC_LOCK(AP_RELEASE); + if (!match) + return (ESRCH); return (0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010317042351.C1B283E23>