svn commit: r359991 - head/lib/libc/gen

Brooks Davis brooks at FreeBSD.org
Wed Apr 15 20:28:20 UTC 2020


Author: brooks
Date: Wed Apr 15 20:28:20 2020
New Revision: 359991
URL: https://svnweb.freebsd.org/changeset/base/359991

Log:
  Attempt to use AT_PS_STRINGS to get the ps_strings pointer.
  
  This saves a system call and avoids one of the (relatively rare) cases
  of the kernel exporting pointers via sysctl.
  
  As a temporary measure, keep the sysctl support to allow limited
  compatability with old kernels.
  
  Fail gracefully if ps_strings can't be found (should never happen).
  
  Reviewed by:	kib
  Obtained from:	CheriBSD
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D24407

Modified:
  head/lib/libc/gen/setproctitle.c

Modified: head/lib/libc/gen/setproctitle.c
==============================================================================
--- head/lib/libc/gen/setproctitle.c	Wed Apr 15 20:26:41 2020	(r359990)
+++ head/lib/libc/gen/setproctitle.c	Wed Apr 15 20:28:20 2020	(r359991)
@@ -20,6 +20,7 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
+#include <sys/elf_common.h>
 #include <sys/exec.h>
 #include <sys/sysctl.h>
 
@@ -112,6 +113,10 @@ setproctitle_internal(const char *fmt, va_list ap)
 		/* Nothing to restore */
 		return (NULL);
 
+	if (ps_strings == NULL)
+		(void)_elf_aux_info(AT_PS_STRINGS, &ps_strings,
+		    sizeof(ps_strings));
+
 	if (ps_strings == NULL) {
 		len = sizeof(ul_ps_strings);
 		if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &len, NULL,
@@ -119,6 +124,9 @@ setproctitle_internal(const char *fmt, va_list ap)
 			return (NULL);
 		ps_strings = (struct ps_strings *)ul_ps_strings;
 	}
+
+	if (ps_strings == NULL)
+		return (NULL);
 
 	/*
 	 * PS_STRINGS points to zeroed memory on a style #2 kernel.


More information about the svn-src-all mailing list