🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
9 messages
9 total messages Started by J. Porter Clark Sun, 10 Aug 1997 00:00
Fix for core dumps in INN-1.6b3 (innd/art.c)
#20355
Author: J. Porter Clark
Date: Sun, 10 Aug 1997 00:00
71 lines
2916 bytes
As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
1.6b3's innd/art.c that may cause innd to dump core as the indirect
result of receiving a control message without a Control header.  The
fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
to have been correct and safe after all.

Also included in the fix is a rearrangement of the order in which some
of the newsfeeds tests occur.  The idea is that it is quicker to count
the number of hops ('H' flag) than it is to search for Path exclusions,
so we do the hop count check first.  This does actually seem to make a
difference in my environment, and I can't see why it would hurt, ever.


*** innd/art.c.orig	Thu Jul 31 15:08:57 1997
--- innd/art.c	Fri Aug  8 20:51:20 1997
***************
*** 1089,1104 ****
  	if (*p == 'c' && EQn(p, "cmsg ", 5)) {
  	    for (p += 5; *p && ISWHITE(*p); )
  		p++;
! 	    if (*p) {
! 		if (strlen(p) > ARTheaders[_control].Length) {
! 		    ARTheaders[_control].Length = strlen(p) + 1;
! 		    ARTheaders[_control].Value =
! 			RENEW(ARTheaders[_control].Value,
! 			char, ARTheaders[_control].Length);
! 		    in = HDR(_control);
! 		}
  		(void)strcpy(in, p);				/* safe -of */
- 	    }
  	}
      }
  
--- 1089,1096 ----
  	if (*p == 'c' && EQn(p, "cmsg ", 5)) {
  	    for (p += 5; *p && ISWHITE(*p); )
  		p++;
! 	    if (*p)
  		(void)strcpy(in, p);				/* safe -of */
  	}
      }
  
***************
*** 1765,1773 ****
  	    /* Too small for the site. */
  	    continue;
  
! 	if ((!sp->IgnorePath && ListHas(hops, sp->Name))
! 	 || (sp->Hops && hopcount > sp->Hops)
! 	 || (sp->Groupcount && Groupcount > sp->Groupcount))
  	    /* Site already saw the article; path too long; or too much
  	     * cross-posting. */
  	    continue;
--- 1757,1765 ----
  	    /* Too small for the site. */
  	    continue;
  
! 	if ((sp->Hops && hopcount > sp->Hops)
! 	 || (sp->Groupcount && Groupcount > sp->Groupcount)
! 	 || (!sp->IgnorePath && ListHas(hops, sp->Name)))
  	    /* Site already saw the article; path too long; or too much
  	     * cross-posting. */
  	    continue;


-- 
J. Porter Clark    jpc@drum.msfc.nasa.gov
NASA/MSFC Flight Data Systems Branch

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20376
Author: Stephen R. van den Berg
Date: Mon, 11 Aug 1997 00:00
26 lines
1607 bytes
J. Porter Clark <jpc@drum.msfc.nasa.gov> wrote:
>As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
>1.6b3's innd/art.c that may cause innd to dump core as the indirect
>result of receiving a control message without a Control header.  The
>fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
>to have been correct and safe after all.

>*** innd/art.c.orig	Thu Jul 31 15:08:57 1997
>--- innd/art.c	Fri Aug  8 20:51:20 1997
>  		p++;
>! 	    if (*p)
>  		(void)strcpy(in, p);				/* safe -of */

You mean, there is never any danger in overflowing the available bufferspace
here?

And even if that is true, then I wonder why the original code (with the >= fix)
is causing problems at all (it shouldn't be triggered then at all).
-- 
Sincerely,                                                          srb@cuci.nl
           Stephen R. van den Berg (AKA BuGless).

Warning: Dates in calendar are closer than they appear.

Re: Fix for core dumps in INN-1.6b3 (innd/art.c) - also 1.5.1sec2
#20379
Author: USENET news
Date: Mon, 11 Aug 1997 00:00
33 lines
2259 bytes
In article <5slt04$c65$1@hammer.msfc.nasa.gov>,
J. Porter Clark <jpc@drum.msfc.nasa.gov> wrote:
>As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
>1.6b3's innd/art.c that may cause innd to dump core as the indirect
>result of receiving a control message without a Control header.  The
>fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
>to have been correct and safe after all.

I got hit by the same problem, but with 1.5.1sec2, overnight 
Saturday/Sunday. 

It's worth noting for people using 1.5.1sec2 that the first part of the
patch (the second is an unrelated change) is equally relevant to 1.5.1sec2
since it has the same, incorrect, change. The line numbers from the 1.6b3
patch will be high by around 64 lines compared to the 1.5.1sec2 art.c - look
around line 1025 if patch has problems. As a result of the earlier
discussion by you and Forrest Cavalier, as soon as I saw the call trace from
the core file I recognised the problem and was able to fix it immediately -
thank you for saving a lot of time!

[For anyone who hasn't seen any problems and thinks "I don't need that 
patch", it's triggered by a sequence of control messages with the lengths of
the Control: header varying in particular ways. So it may not happen often - 
I'd had servers running 1.5.1sec2 for more than a week without seeing it -
but it almost certainly will happen, sooner or later.]

                                John Line
-- 
Cambridge University Computing Service - USENET news manager. Usually John Line
newsmaster@ucs.cam.ac.uk    (alias {newsmaster,news,usenet}@news.cam.ac.uk)

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20386
Author: Forrest J. Cavalier III
Date: Mon, 11 Aug 1997 00:00
153 lines
7253 bytes
In article <5smo7a$lkp$1@zeus.fw.cuci.nl>, srb@zeus.fw.cuci.nl wrote...
>
>J. Porter Clark <jpc@drum.msfc.nasa.gov> wrote:
>>As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
>>1.6b3's innd/art.c that may cause innd to dump core as the indirect
>>result of receiving a control message without a Control header.  The
>>fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
>>to have been correct and safe after all.
>
>>*** innd/art.c.orig    Thu Jul 31 15:08:57 1997
>>--- innd/art.c Fri Aug  8 20:51:20 1997
>>               p++;
>>!          if (*p)
>>               (void)strcpy(in, p);                            /* safe -of */
>
>You mean, there is never any danger in overflowing the available bufferspace
>here?
>
>And even if that is true, then I wonder why the original code (with the >= fix)
>is causing problems at all (it shouldn't be triggered then at all).

....All the gory details, from my post to inn-workers.

BTW, J. Porter Clark is being a bit modest.  He replied to my
message saying that he had it all figured out that morning, but
was unable to respond because of his schedule that day.  When
he returned in the evening, it turns out that I had posted
independently.  But it was important that he confirmed my thinking
on the subject.  I'm glad he responded.

Here it is....


From:             "Forrest J. Cavalier III" <mibsoft@epix.net>
To:               "J. Porter Clark" <jpc@drum.msfc.nasa.gov>, inn-bugs@isc.org,
        inn-workers@vix.com
Date sent:        Fri, 8 Aug 1997 12:21:02 -0400
Subject:          Something rotten in art.c-- Revisited
Send reply to:    mibsoft@epix.net
Copies to:        inn-workers@vix.com
Priority:         normal

And when you thought it was over.....

I was looking at this section of code again.  And I think
there are still some major problems with it.  Here is what
I think, does anyone agree?

To refresh your memories....

This code is handling the case when there is no control header, but
the Subject header starts with "cmsg".  The action taken is to copy
the tail part of the subject line into the buffer holding the 
contents of the control field.  A test ensures the destination is 
large enough.  The error reported by jpc is that strcpy() actually
needs strlen(p)+1 bytes.

As it appears in 1.6b3, and 1.5.1sec2/innd/art.c  ARTclean()

    /* If there is no control header, see if the article starts with
     * "cmsg ". */
    in = HDR(_control);
    if (*in == '\0') {
       p = HDR(_subject);
       if (*p == 'c' && EQn(p, "cmsg ", 5)) {
         for (p += 5; *p && ISWHITE(*p); )
           p++;
         if (*p) {
           if (strlen(p) > ARTheaders[_control].Length) {
              ARTheaders[_control].Length = strlen(p) + 1;
              ARTheaders[_control].Value =
              RENEW(ARTheaders[_control].Value,
                 char, ARTheaders[_control].Length);
              in = HDR(_control);
           }
           (void)strcpy(in, p);
        }
   ...

And in 1.5.1, there is simply a strcpy(), without the test
and conditional RENEW().

After inspecting every single strcpy ->strncpy, and sprintf->snprintf code
change, and finding most of them to be unnecessary (Rich Salz had it right)
I got to thinking about this some more: Why did the code NOT fail in 1.5.1?

The answer is that p points into HDR(_subject) which is a buffer of MAXHEADERSIZE,
and HDR(_control), (a.k.a. ARTheaders[_control].Value) is a buffer of MAXHEADERSIZE.
The code to prevent strings longer than MAXHEADERSIZE appears in ARTparseheader().

And you look in ARTparseheader() and find that it makes assumptions that ARTheaders[].Value
points to MAXHEADERSIZE bytes! So
               RENEW(ARTheaders[_control].Value,
                 char, ARTheaders[_control].Length);
is a VERY BAD thing to do, since the next time ARTparseheader() tries to store something
bigger, it isn't going to RENEW().

Philosophically, I think ARTheaders[_control].Length is invalid at that point anyway:
it is the Length of the previous message's header, which is gone.  Using it at
all is not right.  (ARTclean(), which does article processing, sets *(hp->Value) = '\0'
and does not initialize .Length)


If that isn't bad enough....
ARTheaders[].Length is supposed to be the length of the string at ARTheaders[].Value.
So the 1.6b3/1.5.1sec2 code which sets:
              ARTheaders[_control].Length = strlen(p) + 1;
is wrong, I think.  Compare to the code in ARTparseheader() which does:
             (void)memcpy((POINTER)hp->Value, (POINTER)p, (SIZE_T)i);
              hp->Value[i] = '\0';

I think setting .Length high by 1, is going to send out the null terminator.
-----------------------------------------------------------------------------
Back to the first problem:
 Why didn't jpc find the problem of RENEW() with less than MAXHEADERSIZE?

I'm not sure he was looking for it.  I think the sequence which causes
failure would have to be this:
    A message with Control: with a .Value of X bytes.
    A later message with "Subject: cmsg", with the part after the cmsg of Y bytes,
      where Y is greater than X.  This triggers the RENEW()
    A later message with "Control: ", with the .Value of Z bytes,
      where Z is greater than Y.  This causes ARTparseheaders() to store Z bytes
      at the place of the previous RENEW()
    
Whereas jpc was probably testing this sequence:
    A message with Control: with a .Value of X bytes.
    A later message with "Subject: cmsg", with the part after the cmsg of Y bytes,
      where Y is greater than X.  This triggers the RENEW()
    Another later message with "Subject: cmsg ", with the .Value of Z bytes,
      where Z is greater than Y.  This causes ARTparseheaders() to store Z bytes
      at the place of the previous RENEW()

IOW, jpc was testing with cmsg messages WITHOUT a control header, but the bug
needs a Control: header BIGGER than the last cmsg subject to trigger it.

Fortunately, most Control messages HAVE both a Subject: and a Control: header, so
the RENEW is not ever triggered.  If I am right about it, this would be a simple
one-two punch DoS attack -- just delay the second message by an hour or so.

I vote for going back to the 1.5.1 code in this section: do the strcpy() which
was completely safe.  RENEW() on any ARTheaders[] is bad.


Forrest Cavalier, Mib Software, INN customization and consulting.

BTW, All my work on inn-1.5.1corr is available to the ISC.  Just pay for my time, and you 
can do with it what you wish.



Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20390
Author: Ian Dunkin
Date: Mon, 11 Aug 1997 00:00
15 lines
1093 bytes
J. Porter Clark wrote:
> 
> As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
> 1.6b3's innd/art.c that may cause innd to dump core as the indirect
> result of receiving a control message without a Control header.  The
> fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
> to have been correct and safe after all.

Thanks for posting this.  Another problem we have with 1.6b3 is that it 
dies EVERY time when sent a `reload newsfeeds'.  Anyone else seen this?

   I.

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20393
Author: J. Porter Clark
Date: Mon, 11 Aug 1997 00:00
33 lines
1854 bytes
srb@zeus.fw.cuci.nl (Stephen R. van den Berg) writes:

>J. Porter Clark <jpc@drum.msfc.nasa.gov> wrote:
>>As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
>>1.6b3's innd/art.c that may cause innd to dump core as the indirect
>>result of receiving a control message without a Control header.  The
>>fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
>>to have been correct and safe after all.

>>*** innd/art.c.orig	Thu Jul 31 15:08:57 1997
>>--- innd/art.c	Fri Aug  8 20:51:20 1997
>>  		p++;
>>! 	    if (*p)
>>  		(void)strcpy(in, p);				/* safe -of */

>You mean, there is never any danger in overflowing the available bufferspace
>here?

Correct.

>And even if that is true, then I wonder why the original code (with the >= fix)
>is causing problems at all (it shouldn't be triggered then at all).

It is triggered, because ARTheaders[_control].Length has irrelevant
data at that point.

FWIW, RENEW(ARTheaders[_control].Value...) should *never* be executed.
-- 
J. Porter Clark    jpc@drum.msfc.nasa.gov
NASA/MSFC Flight Data Systems Branch

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20502
Author: Petter Nilsen
Date: Thu, 14 Aug 1997 00:00
18 lines
1350 bytes
In article <33EF2192.363800B3@glaxowellcome.co.uk>,
imd1707@glaxowellcome.co.uk (Ian Dunkin) wrote:

> Thanks for posting this.  Another problem we have with 1.6b3 is that it
> dies EVERY time when sent a `reload newsfeeds'.  Anyone else seen this?

Sounds like a syntax error in the newsfeeds file. This makes INN 1.5.1 die, I
assume that behaviour hasn't changed in 1.6b3 (I just found this out today
myself with 1.5.1). It probably shouldn't, atleast not on reload. On startup,
it's not much else to do but die, but in these cases it should revert to what
it had before, and log an error in the logfile.  

--
- Petter Nilsen - Salgsnett AS (Icenet) -  mailto:pettern@thule.no


Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20505
Author: Ian Dunkin
Date: Thu, 14 Aug 1997 00:00
19 lines
1109 bytes
Petter Nilsen wrote:

> > Thanks for posting this.  Another problem we have with 1.6b3 is that it
> > dies EVERY time when sent a `reload newsfeeds'.  Anyone else seen this?
> 
> Sounds like a syntax error in the newsfeeds file. 

Petter,

Well, maybe, but it doesn't *seem* to be: same file worked with 
previous versions, and passes inncheck.   innd 1.6(b3) dies with a 
Segmentation fault at site.c:107 on 

  Sites[sp->Next].Prev = sp->Prev;

     I.

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
#20527
Author: Forrest J. Cavalier III
Date: Thu, 14 Aug 1997 00:00
39 lines
1774 bytes
In article <33F2DA3E.25F46AFC@glaxowellcome.co.uk>, imd1707@glaxowellcome.co.uk 
wrote...
>
>Petter Nilsen wrote:
>
>> > Thanks for posting this.  Another problem we have with 1.6b3 is that it
>> > dies EVERY time when sent a `reload newsfeeds'.  Anyone else seen this?
>> 
>> Sounds like a syntax error in the newsfeeds file. 
>
>Petter,
>
>Well, maybe, but it doesn't *seem* to be: same file worked with 
>previous versions, and passes inncheck.   innd 1.6(b3) dies with a 
>Segmentation fault at site.c:107 on 
>
>  Sites[sp->Next].Prev = sp->Prev;
>
>     I.

This jogged my memory.... I don't know if it is related...

1.6b3 did change some code in newsfeeds parsing.  Now
lines which have only tabs and spaces are treated as
comments.

Of course you know about the string limit patches, perhaps
you are running up against some problem there?

If you intend to inspect the source code, see all the changes
in a unified source at:

http://www.mibsoftware.com/userkt/inn/unified97/innd/newsfeeds.c

Forrest Cavalier, Mib Software, INN customization and consulting.


Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads