deadsimple BSD Security Advisories and Announcements

NetBSD Security Advisory 2021-002: Incorrect permissions in kernfs

Hash: SHA1

		 NetBSD Security Advisory 2021-002

Topic:		Incorrect permissions in kernfs

Version:	NetBSD-current:		affected between March 3, 2020 and July 6, 2021
		NetBSD 9.2:		affected
		NetBSD 9.1:		affected
		NetBSD 9.0:		affected
		NetBSD 8.*:		not affected

Severity:	Local user may read any file on the root volume

Fixed:		NetBSD-current:		July 6, 2021
		NetBSD-9 branch:	July 6, 2021

Please note that NetBSD releases prior to 8.0 are no longer supported.
It is recommended that all users upgrade to a supported release.


The /kern file system contains references to the device the root
volume was mounted from. It was discovered that the permissions were
incorrect and allow any local user to read the device, thus allowing
any local user to read any file on the root volume.

Technical Details

The files /kern/rootdev and /kern/rrootdev are internally-generated
device special files that refer to the device the root volume was
mounted from. Until July 6, 2021 they were presented as mode 444
(readable to all users). Prior to February 3, 2020 (February 12 on the
NetBSD-9 branch, then at 9.0_RC2) this was harmless because these
device special files did not actually work; however, that problem was
corrected without noticing that the permissions were unsafe.

Solutions and Workarounds

Immediate workaround: unmount /kern and mark it "noauto" in
/etc/fstab. This will work (without impacting system functionality)
for all systems other than Xen DOM0. Unfortunately Xen requires access
to other elements in kernfs. 

Note that while chmod on the offending files appears to succeed, it
does not take and is not an adequate workaround.

To fix the underlying problem, update the kernel.

To apply a fixed version from a releng build, fetch a fitting
kern-GENERIC.tar.xz, kern-GENERIC_KASLR.tar.xz, kern-XEN3_DOM0.tar.xz,
or kern-XEN3_DOMU.tar.xz (depending on which kernel you are using;
uname -v will show, among other things, the name of the running
kernel) from and extract the fixed binaries:

cd /var/tmp
ftp (or whichever)
cd /
tar xzpf /var/tmp/kern-GENERIC.tar.xz

with the following replacements:
REL   = the release version you are using
BUILD = the source date of the build. 202107060400Z and later will fit
ARCH  = your system's architecture

The following instructions describe how to upgrade your kernel by
updating your source tree and rebuilding and installing a new version.

For affected NetBSD versions, you need to obtain fixed kernel sources,
rebuild and install the new kernel, and reboot the system.
The fixed source may be obtained from the NetBSD CVS repository.        
The following instructions briefly summarise how to upgrade your        
kernel.  In these instructions, replace:

  ARCH     with your architecture (from uname -m), and                  
  KERNCONF with the name of your kernel configuration file.    

To update from CVS, re-build, and re-install the kernel:

	# cd src
	# cvs update -d -P sys/miscfs/kernfs/kernfs_vnops.c
	# ./ kernel=KERNCONF
	# mv /netbsd /netbsd.old
	# cp sys/arch/ARCH/compile/obj/KERNCONF/netbsd /netbsd 
	# shutdown -r now

For more information on how to do this, see:

Thanks To

David A. Holland
Martin Husemann
Jonathan A. Kollasch
Jared McNeill

Revision History

	2021-07-14	Initial release

More Information

Advisories may be updated as new information becomes available.
The most recent version of this advisory (PGP signed) can be found at

Information about NetBSD and NetBSD security can be found at and

Copyright 2021, The NetBSD Foundation, Inc.  All Rights Reserved.
Redistribution permitted only in full, unmodified form.

$NetBSD: NetBSD-SA2021-002.txt,v 1.1 2021/07/14 17:48:26 christos Exp $