<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>181324</bug_id>
          
          <creation_ts>2007-06-08 16:50 0000</creation_ts>
          <short_desc>mail-filter/policyd &lt; 1.81 heap based buffer overflow in w_read() (CVE-2007-3791)</short_desc>
          <delta_ts>2007-07-30 04:19:01 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>~1? [noglsa]</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>falco@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>net-mail@gentoo.org</cc>
    
    <cc>strerror@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>falco@gentoo.org</who>
            <bug_when>2007-06-08 16:50:42 0000</bug_when>
            <thetext>policyd.h defines:

  char buf[MAXFDS][MAXLINE];

policyd.c calls:

  rres = w_read(sockfd,buf[sockfd]);

in sockets.c, w_read begins with:

ssize_t
w_read(unsigned int fd, char *ptr)
{
  ssize_t  n;
  size_t   data_read = 0;                                    /* for
debug only */

  /* receive data. disable signals are do not wait */
  while ((n = recv(fd, (void *) ptr + buf_counter[fd], 1, MSG_DONTWAIT |
MSG_NOSIGNAL)) == 1)
...



unfortunately the while() loop can go further than the allocated size of
*ptr. (by entering overly long SMTP commands, &gt;1024 bytes).

This loop needs to be changed like this, for example:

ssize_t w_read(unsigned int fd, char *ptr, unsigned int w_size)
while(( n = (....)) &amp;&amp; buf_counter[fd] &lt; w_size ){...}

you also may want to properly set buf[sockfd][MAXSIZE-1] = &apos;\n&apos;; , that
can&apos;t hurt.

with a lot of connections, buf_counter[MAXFDS-1][] will be overflowed
and the next variables that reside in .bss will be overwritten. This can
potentialy be used to overwrite random stuff in the heap, and maybe
terminate the daemon or remotely execute arbitrary code.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>falco@gentoo.org</who>
            <bug_when>2007-06-08 16:51:33 0000</bug_when>
            <thetext>upstream mailed</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2007-07-29 21:52:40 0000</bug_when>
            <thetext>This is public now. strerror, please provide the updated ebuild.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>strerror@gentoo.org</who>
            <bug_when>2007-07-30 00:58:45 0000</bug_when>
            <thetext>apologies on the delay, in cvs now</thetext>
          </long_desc>
      
    </bug>

</bugzilla>