ESB-2018.0032 - [NetBSD] kernel: Root compromise - Existing account - 2018-01-03


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

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

                               ESB-2018.0032
                Several vulnerabilities in context handling
                              3 January 2018

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

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

Product:           kernel
Publisher:         NetBSD
Operating System:  NetBSD
Impact/Access:     Root Compromise   -- Existing Account
                   Denial of Service -- Existing Account
Resolution:        Patch/Upgrade

Original Bulletin: 
   http://ftp.NetBSD.org/pub/NetBSD/security/advisories/NetBSD-SA2018-001.txt.asc

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

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


		NetBSD Security Advisory 2018-001
		=================================

Topic:		Several vulnerabilities in context handling


Version:	NetBSD-current:		source prior to Sat, Sep 2nd 2017
		NetBSD 7.1:		affected
		NetBSD 7.0 - 7.0.2:	affected
		NetBSD 6.1 - 6.1.4:	affected
		NetBSD 6.0 - 6.0.5:	affected

Severity:	Privilege escalation / Local DoS

Fixed:		NetBSD-current:		Sat, Sep 2nd 2017
		NetBSD-7-1 branch:	Sun, Oct 1st 2017
		NetBSD-7-0 branch:	Sun, Oct 1st 2017
		NetBSD-7 branch:	Sun, Oct 1st 2017
		NetBSD-6-1 branch:	Fri, Oct 13th 2017
		NetBSD-6-0 branch:	Fri, Oct 13th 2017
		NetBSD-6 branch:	Fri, Oct 13th 2017

Teeny versions released later than the fix date will contain the fix.

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


Abstract
========

Several issues were discovered in several ports of NetBSD:

 1) sparc64: A missing mask in a syscall could allow userland to control a few
    bits from a privileged register, allowing privilege escalations.
 2) amd64: A subtle mistake in compat_linux32 could allow userland to generate
    a particular fault in kernel mode, which caused the kernel to get confused
    and re-enter itself in kernel mode but with the userland Thread-Local
    Storage. This allowed privilege escalations.
 3) i386: An instruction in the #UD exception handler was implicitly using the
    userland %ds register without sanitizing it. This allowed at least local
    DoSes.


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

 1) A mistake in a syscall allowed an unprivileged user process to set
    privileged bits, such as PSTATE_PRIV, in the %pstate register. Upon return
    to userland the process would then be granted kernel privileges on the
    hardware.
 2) The handling of the GDT on amd64 creates a condition where a page fault
    can be generated if a segment register is reloaded with a "high" selector,
    located near the end of the GDT. An incorrect check in a linux32 syscall
    allowed unprivileged user processes to have the kernel page fault in such
    a condition. However, the kernel does not correctly handle such exceptions:
    it re-enters itself but does not switch to the kernel TLS, and instead uses
    userland's. Userland therefore had a way to control a generic kernel
    pointer, which allowed for full privilege escalation.
 3) The #UD exception handler was implicitly using the %ds register, before it
    actually initialized it to the kernel value. This allowed userland to crash
    the system.


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

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 summarize how to upgrade your
kernel. In these instructions, replace:

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

File versions containing the fixes:

 FILE     HEAD     netbsd-7     netbsd-7-0     netbsd-7-1
 ----     ----     --------     ----------     ----------
 sys/arch/sparc64/sparc64/compat_13_machdep.c
          1.24     1.23.38.1    1.23.42.1      1.23.50.1
 sys/compat/linux32/arch/amd64/linux32_machdep.c
          1.39     1.36.4.1     1.36.8.1       1.36.14.1
 sys/arch/i386/i386/i386_trap.S
          1.12     1.5.6.1      1.5.12.1       1.5.20.1

 FILE              netbsd-6     netbsd-6-0     netbsd-6-1
 ----              --------     ----------     ----------
 sys/arch/sparc64/sparc64/compat_13_machdep.c
                   1.23.18.1    1.23.24.1      1.23.32.1
 sys/compat/linux32/arch/amd64/linux32_machdep.c
                   1.29.10.1    1.29.14.1      1.29.16.1
 sys/arch/i386/i386/vector.S
                   1.59.8.1     1.59.12.1      1.59.14.1

Note: in NetBSD 6, the fix for 3) is in a different file.

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

	# cd src
	# cvs update -d -P -r VERSION sys/arch/sparc64/sparc64/compat_13_machdep.c
	# cvs update -d -P -r VERSION sys/compat/linux32/arch/amd64/linux32_machdep.c

then, either
	# cvs update -d -P -r VERSION sys/arch/i386/i386/i386_trap.S
or
	# cvs update -d -P -r VERSION sys/arch/i386/i386/vector.S

	# ./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/guide/en/chap-kernel.html


Thanks To
=========

Maxime Villard for finding and fixing the issues.


Revision History
================

	2018-01-02	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 
  http://ftp.NetBSD.org/pub/NetBSD/security/advisories/NetBSD-SA2018-001.txt.asc

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


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

- -----BEGIN PGP SIGNATURE-----

iQIcBAEBAgAGBQJaS73UAAoJEAZJc6xMSnBu3f8QAIaR/so5X+rylr+0pzRytdjx
xqBwbvepMoJzVC6gftxxtHy+BEtFiVmDFAX2de1GhvKmjCpZHAk9wPzdB97Xr5Vq
t1zPBz9fUkPtFHG+/G4S8k+SLaz1v2qklakvpCyVMjWeNuKKUz9Y5iG3zIVUv90T
fYcVPu6zW46NX3HG/JvnMoxaVNhk6CKbchYrQBmWCx24jpBXU/LA0iuxJjYm3UYp
uJ7F+BJXy30xVs6x+hd4Qa+h/WNFDsi3bJBmwkuWafp2QLf9mMnAk8O8M3Ynf/MG
9jz5o9K4neh92oSRgL+5MEvWPDNIU6GGlZ+3UYoJOMGKJxVhsj6UHW/rclKxrGpP
2dt0Ge2DcOXHL7MsTFsPerwY/N87G1SFVIz59pJzn9shXxQ82+JcNC2ICXRDf0AH
BHry8owRvwefXTfOAWW8JcoyYx4apUR5hCatsZ6rK7otcxVzhZa5QQZXqsZMhbxE
C5/CxWgeIDZDslWMlOJaol38zlo019ZEActi5eVMfv7KfTq/TTgLaUEZgofLKx3R
3Yfv0lWKcKdW4QL01qsiucQb5tFGjLFuc7BAS8I5hLaVIwaJTHrByJJVjxqS5cbB
hPlJRYtyLsOXFS8cuPzrp7pmwiWj5ck0ba+JkRvMQwm4Qv+AFOxkUVL6VvL4WxG/
1CAvMaO/BGunH17VHpYI
=QqHl
- -----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

iQIUAwUBWkwRcYx+lLeg9Ub1AQjbvQ/3XS5p34QeyaNP7on/SqtZl9T5LOkqtIPQ
ZPep4YTR5/i6mGdJaoHSiz03YF3RDDX2kLMArI4oYNy68uk4YYYxFHYVENx+Gky+
dlbzeiXSQQdplLTchjExmADOKhlMEoidhXgJmLKDblEdzJDwW6s+lHG8jw94EnW7
WwdTB2OunEuekrM3s7uvUkyggm3R8IA75e+RkIS0qPLKVqVkiHsX3slUcBiJ2UC/
HQsBVwpMkYuETfnHWdQuQ0K42RPZonXBsmkQO5rfJd5r3dqIM1xPNGWnprwL5aSL
lo0xg7Zs5s1JRtXHgpsTp5980H2MP6OQOshWejo2nbOkVmAbnZxG9GPTTMnGAAFe
goIx3JjWD4YBWNX76lWHk5XIThceSpQpS0Mhkqd6rZLyyXh4Z1jKJ4kOTD8I4mJg
yJ/2Vnq33gvyUZGQgsGad1vrTTWo3ICT23TIs1kmIa/NhLs2LQdDs7uRu9Ceh6MI
QaGVZO+2r4M2AFY+hNy4s6JKtTZPDYA4Ct0uc6MJyCezcpCNCGfJLGIy5Uev5vVD
W29iKH33l4EdgfCIXMRZGnAG4D9ontFF75J04Pd3jl+9Xo3wQ0GpRUhU4/FGn6bw
6aampPRUi/26bB5i88D0Dc6vuF3hiDUBB6LZR6g/7M3QiGMvW97yxLlfUntRXStU
iMo0a5cxaw==
=KfCP
-----END PGP SIGNATURE-----