AUSCERT External Security Bulletin Redistribution

            ESB-2004.0151 -- NetBSD Security Advisory 2004-004
                       shmat reference counting bug
                             23 February 2004


        AusCERT Security Bulletin Summary

Product:                kernel
Publisher:              NetBSD
Operating System:       NetBSD-current source prior to February 6th, 2004
                        NetBSD 1.6.1
                        NetBSD 1.6
Impact:                 Increased Privileges
Access Required:        Existing Account
CVE Name:               CAN-2004-0114

Ref:                    ESB-2004.0102

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


		 NetBSD Security Advisory 2004-004

Topic:		shmat reference counting bug

Version:	NetBSD-current:	source prior to February 6th, 2004
		NetBSD 1.6.1:	affected
		NetBSD 1.6:	affected
		NetBSD-1.5.3:	affected
		NetBSD-1.5.2:	affected
		NetBSD-1.5.1:	affected
		NetBSD-1.5:	affected

Severity:	local privilege escalation

Fixed:		NetBSD-current:		February 7th, 2004
                NetBSD-1.6 branch:      February 8th, 2004
					(1.6.2 will include the fix)

		NetBSD-1.5 branch:	This fix is not yet pulled
					up. This advisory will be
					updated when it has.
					Updating to NetBSD 1.6.2 is


A programming error in the shmat(2) system call can result in a shared
memory segment's reference count being erroneously incremented.

This system call is part of the System-V Shared Memory subsystem;
although this is enabled in the default (GENERIC*) kernels, custom
kernels built without "options SYSVSHM" are not affected.

Technical Details
The shmat(2) function maps a shared memory segment, previously created
with the shmget(2) function, into the address space of the calling

The shmat(2) function first increases the reference count on the
underlying vm_object and then attempts to insert the vm_object into
the process address space.

The vulnerability occurs because the shmat(2) function forgets to
decrease the reference count if the vm_map_find function returns

Since the caller of shmat(2) can specify the address at which the
segment should be mapped it is possible to have vm_map_find return
failure and thus end up with stale references.

In the end, an unprivileged user may have write access to an
unreferenced piece of kernel memory, which could later become part of a
privileged object.

Solutions and Workarounds

If you are unable to apply the patch as described below, you may
workaround the problem by removing SYSVSHM from your kernel config
file and rebuilding and reinstalling your kernel.

*** Patching from sources:

Otherwise, the fix for this issue is contained in the one file,
sys/kern/sysv_shm.c. The following table lists the fixed revisions and
dates of this file for each branch:

  CVS branch     revision     date
  -------------  -----------  ----------------
  HEAD           1.74         2004/02/05
  netbsd-1-6     2004/02/08

The following instructions describe how to upgrade your kernel
binaries by updating your source tree and rebuilding and installing a
new version of the kernel. In these instructions, replace:

  BRANCH   with the appropriate CVS branch (from the above table)
  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 -r BRANCH sys/kern/sysv_shm.c
        # cd sys/arch/ARCH/conf
        # config KERNCONF
        # cd ../compile/KERNCONF
        # make depend;make
        # mv /netbsd /netbsd.old
        # cp netbsd /
        # reboot

* Binary Patch:

	Binary patches are being provided, in the form of replacement
	kernels built with the patches from the GENERIC kernel
	configuration. If you use a custom kernel configuration, these
	may not be suitable for you.

	NOTE: The path below says SA2004-002-kernel intentionally.
	The same kernel includes fixes for NetBSD-SA2004-002 and
	NetBSD-SA2004-004. If you already updated for 2004-002,
	you do not need to perform these steps again.

        To apply the binary patch, perform the following steps,
        replacing ARCH with the NetBSD architecture you are running
        (i.e. i386):

        cd / && cp /path/to/ARCH-kernel.gz /
        gzip -d ARCH-kernel.gz

        The tar file will extract a new copy of:

	Back up your old kernel:
	mv netbsd netbsd.old

        Then either rename:
        mv ARCH-kernel netbsd

        or link, as per local site policy:
        ln ARCH-kernel netbsd

        Then, reboot.

Thanks To

Joost Pol of Pine Digital Security

FreeBSD Security-Officer

Christos Zoulas for supplying a fix.

Revision History

	2004-02-18	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
http://www.NetBSD.org/ and http://www.NetBSD.org/Security/.

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

$NetBSD: NetBSD-SA2004-004.txt,v 1.4 2004/02/19 03:17:33 david Exp $

Version: GnuPG v1.2.4 (NetBSD)


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

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:


If you believe that your computer system has been compromised or attacked in 
any way, we encourage you to let us know by completing the secure National IT 
Incident Reporting Form at:


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.
Comment: http://www.auscert.org.au/render.html?it=1967