Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Sep 2019 13:51:44 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352244 - head/sys/kern
Message-ID:  <201909121351.x8CDpi9r038288@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu Sep 12 13:51:43 2019
New Revision: 352244
URL: https://svnweb.freebsd.org/changeset/base/352244

Log:
  kenv: assert that an empty static buffer passed in is "empty"
  
  Garbage in the passed-in buffer can cause problems if any attempts to read
  the kenv are inadvertently made between init_static_kenv and the first
  kern_setenv -- assuming there is one.
  
  This is cheap and easy, so do it. This also helps rule out some class of
  bugs as one tries to debug; tunables fetch from the static environment up
  until SI_SUB_KMEM + 1, and many of these buffers are global ~4k buffers that
  rely on BSS clearing while others just grab a page of free memory and use it
  (e.g. xen).

Modified:
  head/sys/kern/kern_environment.c

Modified: head/sys/kern/kern_environment.c
==============================================================================
--- head/sys/kern/kern_environment.c	Thu Sep 12 12:33:09 2019	(r352243)
+++ head/sys/kern/kern_environment.c	Thu Sep 12 13:51:43 2019	(r352244)
@@ -250,6 +250,8 @@ init_static_kenv(char *buf, size_t len)
 	char *eval;
 
 	KASSERT(!dynamic_kenv, ("kenv: dynamic_kenv already initialized"));
+	KASSERT(len == 0 || *buf == '\0',
+	    ("kenv: sized buffer must be initially empty"));
 
 	/*
 	 * We may be called twice, with the second call needed to relocate



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909121351.x8CDpi9r038288>