Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:254
HistoryMay 26, 2000 - 12:00 a.m.

Security Advisory: FreeBSD-SA-00:19.semconfig

2000-05-2600:00:00
vulners.com
162

=============================================================================
FreeBSD-SA-00:19 Security Advisory
FreeBSD, Inc.

Topic: local users can prevent all processes from exiting

Category: core
Module: kernel
Announced: 2000-05-26
Credits: Peter Wemm <[email protected]>
Affects: 386BSD-derived OSes, including all versions of FreeBSD,
NetBSD and OpenBSD.
Corrected: 2000-05-01
FreeBSD only: NO
Patch: ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-00:19/semconfig.patch

I. Background

System V IPC is a set of interfaces for providing inter-process
communication, in the form of shared memory segments, message queues
and semaphores. These are managed in user-space by ipcs(1) and
related utilities.

II. Problem Description

An undocumented system call is incorrectly exported from the kernel
without access-control checks. This operation causes the acquisition
in the kernel of a global semaphore which causes all processes on the
system to block during exit() handling, thereby preventing any process
from exiting until the corresponding "unblock" system call is issued.

This operation was intended for use only by ipcs(1) to atomically
sample the state of System V IPC resources on the system (i.e., to
ensure that resources are not allocated or deallocated during the
process of sampling itself).

In the future, this functionality may be reimplemented as a sysctl()
node.

III. Impact

An unprivileged local user can cause every process on the system to
hang during exiting. In other words, after the system call is issued,
no process on the system will be able to exit completely until another
user issues the "unblock" call or the system is rebooted. This is a
denial-of-service attack.

IV. Workaround

None available.

V. Solution

Upgrade to FreeBSD 2.1.7.1-STABLE, 2.2.8-STABLE, 3.4-STABLE,
4.0-STABLE or 5.0-CURRENT after the correction date.

Alternatively, apply the following patch and rebuild the kernel and
the src/usr.bin/ipcs utility. This patch removes the semconfig()
syscall. It has been tested to apply cleanly against 3.4-RELEASE,
3.4-STABLE, 4.0-RELEASE and 4.0-STABLE systems.

1) Save this advisory as a file, and run the following commands as root:

cd /usr/src

patch -p < /path/to/advisory

cd usr.bin/ipcs

make all install

2) Rebuild and reinstall the kernel and kernel modules as described in
the FreeBSD handbook (see:
http://www.freebsd.org/handbook/kernelconfig.html for more information)

3) Reboot the system

Patches for FreeBSD systems before the resolution date:

--- sys/kern/syscalls.master        2000/01/19 06:01:07     1.72
+++ sys/kern/syscalls.master        2000/05/01 11:15:10     1.72.2.1
@@ -342,7 +342,7 @@
 221        STD     BSD     { int semget&#40;key_t key, int nsems, int semflg&#41;; }
 222        STD     BSD     { int semop&#40;int semid, struct sembuf *sops, &#92;
                        u_int nsops&#41;; }
-223        STD     BSD     { int semconfig&#40;int flag&#41;; }
+223        UNIMPL  NOHIDE  semconfig
 224        STD     BSD     { int msgctl&#40;int msqid, int cmd, &#92;
                        struct msqid_ds *buf&#41;; }
 225        STD     BSD     { int msgget&#40;key_t key, int msgflg&#41;; }
--- sys/kern/init_sysent.c  2000/01/19 06:02:29     1.79
+++ sys/kern/init_sysent.c  2000/05/01 11:15:56     1.79.2.1
@@ -243,7 +243,7 @@
    { 4, &#40;sy_call_t *&#41;__semctl },                   /* 220 = __semctl */
    { 3, &#40;sy_call_t *&#41;semget },                     /* 221 = semget */
    { 3, &#40;sy_call_t *&#41;semop },                      /* 222 = semop */
-   { 1, &#40;sy_call_t *&#41;semconfig },                  /* 223 = semconfig */
+   { 0, &#40;sy_call_t *&#41;nosys },                      /* 223 = semconfig */
    { 3, &#40;sy_call_t *&#41;msgctl },                     /* 224 = msgctl */
    { 2, &#40;sy_call_t *&#41;msgget },                     /* 225 = msgget */
    { 4, &#40;sy_call_t *&#41;msgsnd },                     /* 226 = msgsnd */
--- sys/kern/syscalls.c     2000/01/19 06:02:29     1.71
+++ sys/kern/syscalls.c     2000/05/01 11:15:56     1.71.2.1
@@ -230,7 +230,7 @@
    &quot;__semctl&quot;,                     /* 220 = __semctl */
    &quot;semget&quot;,                       /* 221 = semget */
    &quot;semop&quot;,                        /* 222 = semop */
-   &quot;semconfig&quot;,                    /* 223 = semconfig */
+   &quot;#223&quot;,                 /* 223 = semconfig */
    &quot;msgctl&quot;,                       /* 224 = msgctl */
    &quot;msgget&quot;,                       /* 225 = msgget */
    &quot;msgsnd&quot;,                       /* 226 = msgsnd */
--- sys/kern/sysv_ipc.c     2000/02/29 22:58:59     1.13
+++ sys/kern/sysv_ipc.c     2000/05/01 11:15:56     1.13.2.1
@@ -107,15 +107,6 @@
 semsys&#40;p, uap&#41;
    struct proc *p;
    struct semsys_args *uap;
-{
-   sysv_nosys&#40;p, &quot;SYSVSEM&quot;&#41;;
-   return nosys&#40;p, &#40;struct nosys_args *&#41;uap&#41;;
-};
-
-int
-semconfig&#40;p, uap&#41;
-   struct proc *p;
-   struct semconfig_args *uap;
 {
    sysv_nosys&#40;p, &quot;SYSVSEM&quot;&#41;;
    return nosys&#40;p, &#40;struct nosys_args *&#41;uap&#41;;
--- sys/kern/sysv_sem.c     2000/04/02 08:47:08     1.24.2.1
+++ sys/kern/sysv_sem.c     2000/05/01 11:15:56     1.24.2.2
@@ -26,8 +26,6 @@
 int semget __P&#40;&#40;struct proc *p, struct semget_args *uap&#41;&#41;;
 struct semop_args;
 int semop __P&#40;&#40;struct proc *p, struct semop_args *uap&#41;&#41;;
-struct semconfig_args;
-int semconfig __P&#40;&#40;struct proc *p, struct semconfig_args *uap&#41;&#41;;
 #endif
 
 static struct sem_undo *semu_alloc __P&#40;&#40;struct proc *p&#41;&#41;;
@@ -38,7 +36,7 @@
 /* XXX casting to &#40;sy_call_t *&#41; is bogus, as usual. */
 static sy_call_t *semcalls[] = {
    &#40;sy_call_t *&#41;__semctl, &#40;sy_call_t *&#41;semget,
-   &#40;sy_call_t *&#41;semop, &#40;sy_call_t *&#41;semconfig
+   &#40;sy_call_t *&#41;semop
 };
 
 static int semtot = 0;
@@ -47,8 +45,6 @@
 static struct sem_undo *semu_list;         /* list of active undo structures */
 int        *semu;                  /* undo structure pool */
 
-static struct proc *semlock_holder = NULL;
-
 void
 seminit&#40;dummy&#41;
    void *dummy;
@@ -87,64 +83,12 @@
    } */ *uap;
 {
 
-   while &#40;semlock_holder != NULL &amp;&amp; semlock_holder != p&#41;
-           &#40;void&#41; tsleep&#40;&#40;caddr_t&#41;&amp;semlock_holder, &#40;PZERO - 4&#41;, &quot;semsys&quot;, 0&#41;;
-
    if &#40;uap-&gt;which &gt;= sizeof&#40;semcalls&#41;/sizeof&#40;semcalls[0]&#41;&#41;
            return &#40;EINVAL&#41;;
    return &#40;&#40;*semcalls[uap-&gt;which]&#41;&#40;p, &amp;uap-&gt;a2&#41;&#41;;
 }
 
 /*
- * Lock or unlock the entire semaphore facility.
- *
- * This will probably eventually evolve into a general purpose semaphore
- * facility status enquiry mechanism &#40;I don&#39;t like the &quot;read /dev/kmem&quot;
- * approach currently taken by ipcs and the amount of info that we want
- * to be able to extract for ipcs is probably beyond what the capability
- * of the getkerninfo facility.
- *
- * At the time that the current version of semconfig was written, ipcs is
- * the only user of the semconfig facility.  It uses it to ensure that the
- * semaphore facility data structures remain static while it fishes around
- * in /dev/kmem.
- */
-
-#ifndef _SYS_SYSPROTO_H_
-struct semconfig_args {
-   semconfig_ctl_t flag;
-};
-#endif
-
-int
-semconfig&#40;p, uap&#41;
-   struct proc *p;
-   struct semconfig_args *uap;
-{
-   int eval = 0;
-
-   switch &#40;uap-&gt;flag&#41; {
-   case SEM_CONFIG_FREEZE:
-           semlock_holder = p;
-           break;
-
-   case SEM_CONFIG_THAW:
-           semlock_holder = NULL;
-           wakeup&#40;&#40;caddr_t&#41;&amp;semlock_holder&#41;;
-           break;
-
-   default:
-           printf&#40;&quot;semconfig: unknown flag parameter value &#40;&#37;d&#41; - ignored&#92;n&quot;,
-               uap-&gt;flag&#41;;
-           eval = EINVAL;
-           break;
-   }
-
-   p-&gt;p_retval[0] = 0;
-   return&#40;eval&#41;;
-}
-
-/*
  * Allocate a new sem_undo structure for a process
  * &#40;returns ptr to structure or NULL if no more room&#41;
  */
@@ -873,17 +817,6 @@
    register struct sem_undo **supptr;
    int did_something;
 
-   /*
-    * If somebody else is holding the global semaphore facility lock
-    * then sleep until it is released.
-    */
-   while &#40;semlock_holder != NULL &amp;&amp; semlock_holder != p&#41; {
-#ifdef SEM_DEBUG
-           printf&#40;&quot;semaphore facility locked - sleeping ...&#92;n&quot;&#41;;
-#endif
-           &#40;void&#41; tsleep&#40;&#40;caddr_t&#41;&amp;semlock_holder, &#40;PZERO - 4&#41;, &quot;semext&quot;, 0&#41;;
-   }
-
    did_something = 0;
 
    /*
@@ -898,7 +831,7 @@
    }
 
    if &#40;suptr == NULL&#41;
-           goto unlock;
+           return;
 
 #ifdef SEM_DEBUG
    printf&#40;&quot;proc @&#37;08x has undo structure with &#37;d entries&#92;n&quot;, p,
@@ -955,14 +888,4 @@
 #endif
    suptr-&gt;un_proc = NULL;
    *supptr = suptr-&gt;un_next;
-
-unlock:
-   /*
-    * If the exiting process is holding the global semaphore facility
-    * lock then release it.
-    */
-   if &#40;semlock_holder == p&#41; {
-           semlock_holder = NULL;
-           wakeup&#40;&#40;caddr_t&#41;&amp;semlock_holder&#41;;
-   }
 }

--- sys/sys/sem.h   1999/12/29 04:24:46     1.20
+++ sys/sys/sem.h   2000/05/01 11:15:58     1.20.2.1
@@ -163,13 +163,5 @@
  * Process sem_undo vectors at proc exit.
  */
 void       semexit __P&#40;&#40;struct proc *p&#41;&#41;;
-
-/*
- * Parameters to the semconfig system call
- */
-typedef enum {
-   SEM_CONFIG_FREEZE,      /* Freeze the semaphore facility. */
-   SEM_CONFIG_THAW         /* Thaw the semaphore facility. */
-} semconfig_ctl_t;
 #endif /* _KERNEL */
 
--- sys/sys/syscall-hide.h  2000/01/19 06:02:31     1.65
+++ sys/sys/syscall-hide.h  2000/05/01 11:15:58     1.65.2.1
@@ -191,7 +191,6 @@
 HIDE_BSD&#40;__semctl&#41;
 HIDE_BSD&#40;semget&#41;
 HIDE_BSD&#40;semop&#41;
-HIDE_BSD&#40;semconfig&#41;
 HIDE_BSD&#40;msgctl&#41;
 HIDE_BSD&#40;msgget&#41;
 HIDE_BSD&#40;msgsnd&#41;
--- sys/sys/syscall.h       2000/01/19 06:02:31     1.69
+++ sys/sys/syscall.h       2000/05/01 11:15:59     1.69.2.1
@@ -196,7 +196,6 @@
 #define    SYS___semctl    220
 #define    SYS_semget      221
 #define    SYS_semop       222
-#define    SYS_semconfig   223
 #define    SYS_msgctl      224
 #define    SYS_msgget      225
 #define    SYS_msgsnd      226
--- sys/sys/syscall.mk      2000/01/19 06:07:34     1.23
+++ sys/sys/syscall.mk      2000/05/01 11:15:59     1.23.2.1
@@ -148,7 +148,6 @@
    __semctl.o &#92;
    semget.o &#92;
    semop.o &#92;
-   semconfig.o &#92;
    msgctl.o &#92;
    msgget.o &#92;
    msgsnd.o &#92;
--- sys/sys/sysproto.h      2000/01/19 06:02:31     1.59
+++ sys/sys/sysproto.h      2000/05/01 11:16:00     1.59.2.1
@@ -662,9 +662,6 @@
    struct sembuf * sops;   char sops_[PAD_&#40;struct sembuf *&#41;];
    u_int   nsops;  char nsops_[PAD_&#40;u_int&#41;];
 };
-struct     semconfig_args {
-   int     flag;   char flag_[PAD_&#40;int&#41;];
-};
 struct     msgctl_args {
    int     msqid;  char msqid_[PAD_&#40;int&#41;];
    int     cmd;    char cmd_[PAD_&#40;int&#41;];
@@ -1158,7 +1155,6 @@
 int        __semctl __P&#40;&#40;struct proc *, struct __semctl_args *&#41;&#41;;
 int        semget __P&#40;&#40;struct proc *, struct semget_args *&#41;&#41;;
 int        semop __P&#40;&#40;struct proc *, struct semop_args *&#41;&#41;;
-int        semconfig __P&#40;&#40;struct proc *, struct semconfig_args *&#41;&#41;;
 int        msgctl __P&#40;&#40;struct proc *, struct msgctl_args *&#41;&#41;;
 int        msgget __P&#40;&#40;struct proc *, struct msgget_args *&#41;&#41;;
 int        msgsnd __P&#40;&#40;struct proc *, struct msgsnd_args *&#41;&#41;;
--- usr.bin/ipcs/ipcs.c     1999/12/29 05:05:32     1.12
+++ usr.bin/ipcs/ipcs.c     2000/05/01 10:51:37     1.12.2.1
@@ -56,7 +56,6 @@
 struct shminfo     shminfo;
 struct shmid_ds    *shmsegs;
 
-int        semconfig __P&#40;&#40;int,...&#41;&#41;;
 void       usage __P&#40;&#40;void&#41;&#41;;
 
 static struct nlist symbols[] = {
@@ -420,11 +419,6 @@
                        seminfo.semaem&#41;;
            }
            if &#40;display &amp; SEMINFO&#41; {
-                   if &#40;semconfig&#40;SEM_CONFIG_FREEZE&#41; != 0&#41; {
-                           perror&#40;&quot;semconfig&quot;&#41;;
-                           fprintf&#40;stderr,
-                               &quot;Can&#39;t lock semaphore facility - winging it...&#92;n&quot;&#41;;
-                   }
                    kvm_read&#40;kd, symbols[X_SEMA].n_value, &amp;sema, sizeof&#40;sema&#41;&#41;;
                    xsema = malloc&#40;sizeof&#40;struct semid_ds&#41; * seminfo.semmni&#41;;
                    kvm_read&#40;kd, &#40;u_long&#41; sema, xsema, sizeof&#40;struct semid_ds&#41; *

seminfo.semmni);
@@ -470,8 +464,6 @@
printf("\n");
}
}
-
- (void) semconfig(SEM_CONFIG_THAW);

                    printf&#40;&quot;&#92;n&quot;&#41;;
            }