<<< Date Index >>>     <<< Thread Index >>>

NetBSD Security Advisory 2004-004: shmat reference counting bug



-----BEGIN PGP SIGNED MESSAGE-----


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


Abstract
========

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

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

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     1.64.4.1     2004/02/08
  netbsd-1-5     

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

        
ftp://ftp.netbsd.org/pub/NetBSD/security/patches/SA2004-002-kernel/netbsd-1-6/ARCH-kernel.tgz
        cd / && cp /path/to/ARCH-kernel.gz /
        gzip -d ARCH-kernel.gz

        The tar file will extract a new copy of:
                ARCH-kernel

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

ftp://ftp.freebsd.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-04:02.shmat.asc

http://www.pine.nl/press/pine-cert-20040201.txt

http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0114


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

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.asc,v 1.2 2004/02/19 03:18:38 david Exp $

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iQCVAwUBQDQr1z5Ru2/4N2IFAQE0wwP/bc/7t0ecwb8js4Mqu+MAbWEeGX4I0CH7
zvVR79eie7t/cdTdSBD8vVsCev7z8FUx1DGZgHsK5FDQ5EB4boQB8SaUzI07ZykG
juRdDt/RKy3HhAEvF78lCmK2rbufiFph9QERtAU9aYegX4DSTLikiDxkxFRzWotl
kd5Qm/GDdUY=
=6XAW
-----END PGP SIGNATURE-----