NetBSD Security Advisory 2004-004: shmat reference counting bug

From: NetBSD Security-Officer (
Date: 02/19/04

  • Next message: Joshua Miller: "LiveJournal XSS"
    Date: Thu, 19 Feb 2004 08:37:17 -0500


                     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 and

    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 $

    Version: GnuPG v1.2.3 (NetBSD)

    -----END PGP SIGNATURE-----

  • Next message: Joshua Miller: "LiveJournal XSS"

    Relevant Pages