🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
8 messages
8 total messages Started by Tim Fardell Tue, 10 Jun 2008 14:37
Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79113
Author: Tim Fardell
Date: Tue, 10 Jun 2008 14:37
60 lines
3296 bytes
Hello again, all! More problems, I'm afraid :-(

I have compiled nnrpd with SSL support, and am running this from xinetd.

With one specific group only, and no others, when the client requests
XOVER for the full range of articles, instead of sending the overview
data back to the client, there is a short pause (about 5 seconds) and
nnrpd dies, closing the connection to the client.

It works fine for all other groups on the server, and only occurs when
connecting over SSL.

Nothing is logged - nnrpd just dies silently.

If the client does XOVER for a smaller range (say, the last 500
messages), it works fine.

I tried rebuilding Overview for the bad group, but the problem still
occurs.

I also tried running nnrpd in Daemon mode, and the same thing happened.

Also happens with a version 2.4.3 nnrpd binary.

The problem occurs with any newsreader requesting all headers from the
group, but here is a 'sanitised' log generated by MS Outlook Express,
which shows the problem admirably:

Microsoft Internet Messaging API 6.00.2900.2180 (xpsp_sp2_rtm.040803-2158)
NNTP Log started at 06/10/2008 12:56:30
NNTP: 12:56:30 [db] Connecting to '<news-server-name>' on port 563.
NNTP: 12:56:30 [db] Negotiating secure connection with 'Microsoft Unified 
Security Protocol Provider'.
NNTP: 12:56:30 [rx] 200 <news-server-name> InterNetNews NNRP server INN 
2.4.4 ready (posting ok).
NNTP: 12:56:30 [tx] MODE READER
NNTP: 12:56:30 [rx] 200 <news-server-name> InterNetNews NNRP server INN 
2.4.4 ready (posting ok).
NNTP: 12:56:30 [tx] AUTHINFO USER <username>
NNTP: 12:56:30 [rx] 381 PASS required
NNTP: 12:56:30 [tx] AUTHINFO PASS <password>
NNTP: 12:56:30 [rx] 281 Ok
NNTP: 12:56:30 [tx] GROUP <newsgroup-name>
NNTP: 12:56:30 [rx] 211 126454 1 127344 <newsgroup-name>
NNTP: 12:56:30 [tx] XOVER 1-127344
NNTP: 12:56:30 [rx] 224 1-127344 fields follow
NNTP: 12:56:36 [db] Connection to '<news-server-name>' closed.

Any ideas what might be causing this, and how I can fix it?

It's strange that one, and only one, group is affected, and rebuilding
Overview didn't help.

Any help appreciated as this is affecting lots of our users :-(

Tim.

-- 
Please remove all-your-clothes before replying. 
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79114
Author: Russ Allbery
Date: Tue, 10 Jun 2008 16:02
22 lines
2084 bytes
Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:

> Hello again, all! More problems, I'm afraid :-(
>
> I have compiled nnrpd with SSL support, and am running this from xinetd.
>
> With one specific group only, and no others, when the client requests
> XOVER for the full range of articles, instead of sending the overview
> data back to the client, there is a short pause (about 5 seconds) and
> nnrpd dies, closing the connection to the client.

This is fixed in STABLE.  The problem was that nnrpd was using alloca to
allocate memory for the SSL encryption buffer, which exploded if the data
to be encrypted was larger than the stack size limit.  It wasn't a good
place to use alloca and the current STABLE version switches to allocating
regular heap memory for this purpose.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79115
Author: Tim Fardell
Date: Tue, 10 Jun 2008 17:17
30 lines
2493 bytes
On Tue, 10 Jun 2008, Russ Allbery wrote:

> Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:
> > With one specific group only, and no others, when the client requests
> > XOVER for the full range of articles, instead of sending the overview
> > data back to the client, there is a short pause (about 5 seconds) and
> > nnrpd dies, closing the connection to the client.
> 
> This is fixed in STABLE.  The problem was that nnrpd was using alloca to
> allocate memory for the SSL encryption buffer, which exploded if the data
> to be encrypted was larger than the stack size limit.  It wasn't a good
> place to use alloca and the current STABLE version switches to allocating
> regular heap memory for this purpose.

Thanks Russ. 

Is there any way to work around this with 2.4.4? 

I don't like the idea of running a development snapshot on a live server. 

Another, unrelated problem - I notice that nnrpd isn't always dieing when 
the user disconnects, resulting in hundreds of 'orphan' nnrpd processes 
hanging around. I had to do a 'killall nnrpd' today because users started 
reporting that they couldn't log in to the server. Is this also fixed? 

Tim. 

-- 
Please remove all-your-clothes before replying. 
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79116
Author: Chris Caputo
Date: Tue, 10 Jun 2008 21:19
155 lines
6179 bytes
Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:
>On Tue, 10 Jun 2008, Russ Allbery wrote:
>> Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:
>> > With one specific group only, and no others, when the client requests
>> > XOVER for the full range of articles, instead of sending the overview
>> > data back to the client, there is a short pause (about 5 seconds) and
>> > nnrpd dies, closing the connection to the client.
>> 
>> This is fixed in STABLE.  The problem was that nnrpd was using alloca to
>> allocate memory for the SSL encryption buffer, which exploded if the data
>> to be encrypted was larger than the stack size limit.  It wasn't a good
>> place to use alloca and the current STABLE version switches to allocating
>> regular heap memory for this purpose.
>
>Thanks Russ. 
>
>Is there any way to work around this with 2.4.4? 
>
>I don't like the idea of running a development snapshot on a live server. 

The fix for this is attached below.

>Another, unrelated problem - I notice that nnrpd isn't always dieing when 
>the user disconnects, resulting in hundreds of 'orphan' nnrpd processes 
>hanging around. I had to do a 'killall nnrpd' today because users started 
>reporting that they couldn't log in to the server. Is this also fixed? 

If a user does not gracefully disconnect, nnrpd won't notice until it 
times out or tries to send data.  Activating keepalive packets on your TCP 
streams can help also detect a missing endpoint.  In my nnrpd.c main() 
function I add the following after the SO_REUSEADDR setsockopt().

---
        if (setsockopt(lfd, SOL_SOCKET, SO_KEEPALIVE,
                       (char *)&one, sizeof(one)) < 0) {
            syslog(L_FATAL, "can't setsockopt(SO_KEEPALIVE) (%m)");
            exit(1);
        }
---

Not sure of your OS, but under Linux I also add the following to 
sysctl.conf to speed up the detection of clients which have disappeared:

---
# KEEPALIVE tweaks - detect dead peers within 87 seconds...
# default: net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_intvl = 3
# default: net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_probes = 9
# default: net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_keepalive_time = 60
# On a LAN '7' timesout in 57 seconds with SIGPIPE.  '15' was 16 minutes!
# default: net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_retries2 = 7
---

Chris

---

Date: Wed, 21 May 2008 15:11:52 +0000 (UTC)
From: Chris Caputo <ccaputo@alt.net>
To: inn-workers@isc.org
Subject: PATCH: nnrpd/tls.c - fix stack overflow

Please consider the following patch for nnrpd/tls.c.  It should apply to 
inn-2.4.2 through 2.4.4.

When an article of a size greater than remaining stack are retrieved via 
SSL, a segmentation fault will occur due to the use of alloca().

The below patch uses heap based realloc() instead of stack based alloca(), 
with a static buffer growing as needed.

I used realloc() instead of malloc() for performance reasons since this 
function is called frequently.  The caveat is that the memory is never 
free()'ed, so if more correct code is desired you may want to adjust this.

Thanks,
Chris

diff -upr nnrpd-stock/tls.c nnrpd/tls.c
--- nnrpd-stock/tls.c	2004-12-22 04:21:19.000000000 +0000
+++ nnrpd/tls.c	2008-05-21 14:55:52.000000000 +0000
@@ -32,37 +32,6 @@
 #include <sys/stat.h>
 #include <sys/uio.h>
 
-/* taken from lib/parsedate.c */
-#ifndef WRITEV_USE_ALLOCA
-#ifdef alloca
-#define WRITEV_USE_ALLOCA
-#else /* alloca not defined */
-#ifdef __GNUC__
-#define WRITEV_USE_ALLOCA
-#define alloca __builtin_alloca
-#else /* not GNU C.  */
-#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
-#define WRITEV_USE_ALLOCA
-#include <alloca.h>
-#else /* not sparc */
-#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
-#else /* not MSDOS, or __TURBOC__ */
-#if defined(_AIX)
- #pragma alloca
-#define WRITEV_USE_ALLOCA
-#endif /* not _AIX */
-#endif /* not MSDOS, or __TURBOC__ */
-#endif /* not sparc */
-#endif /* not GNU C */
-#endif /* alloca not defined */
-#endif /* WRITEV_USE_ALLOCA not defined */
-#ifdef WRITEV_USE_ALLOCA
-#define WRITEV_ALLOC alloca
-#else
-#define WRITEV_ALLOC malloc
-#endif
-
-
 #endif
 
 /* outside the ifdef so `make depend` works even ifndef HAVE_SSL */
@@ -698,7 +667,8 @@ SSL_writev (ssl, vector, count)
      const struct iovec *vector;
      int count;
 {
-  char *buffer;
+  static char *buffer = NULL;
+  static size_t allocsize = 0;
   char *bp;
   size_t bytes, to_copy;
   int i;
@@ -706,8 +676,20 @@ SSL_writev (ssl, vector, count)
   bytes = 0;
   for (i = 0; i < count; ++i)
     bytes += vector[i].iov_len;
-  /* Allocate a temporary buffer to hold the data.  */
-  buffer = (char *) WRITEV_ALLOC (bytes);
+  /* Allocate a buffer to hold the data.  */
+  if (NULL == buffer)
+    {
+      buffer = (char *) xmalloc(bytes);
+      allocsize = bytes;
+    }
+  else
+    {
+      if (bytes > allocsize)
+        {
+          buffer = (char *) xrealloc (buffer, bytes);
+          allocsize = bytes;
+	}
+    }
   /* Copy the data into BUFFER.  */
   to_copy = bytes;
   bp = buffer;
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79117
Author: Julien ÉLIE
Date: Tue, 10 Jun 2008 21:53
22 lines
2375 bytes
Hi Tim,

> Is there any way to work around this with 2.4.4?
> I don't like the idea of running a development snapshot on a live server.

INN 2.4.4 is also the development snapshot of a certain day (only a changelog
file, not included in a snapshot, is shipped with the release).


By the way, in order to address the issues discovered since the release of 2.4.4,
a new version of INN will be released within a couple of weeks.

If you cannot wait for INN 2.4.5, you can also take inn-STABLE-20080611.tar.gz
(not 20080610, unless you do not use Python filters because it will not
compile owing to a mistake in the name of a variable).  I think this snapshot
will be almost the same as the final 2.4.5 release.

-- 
Julien ÉLIE

« Les idées fausses ne sont pas toujours mauvaises. » (Marcel Aymé) 
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79118
Author: Tim Fardell
Date: Wed, 11 Jun 2008 10:48
35 lines
2709 bytes
On Tue, 10 Jun 2008, Chris Caputo wrote:

> Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:
> >On Tue, 10 Jun 2008, Russ Allbery wrote:
> >> Tim Fardell <tim.fardell.all-your-clothes@virgin.net> writes:
> >> > With one specific group only, and no others, when the client requests
> >> > XOVER for the full range of articles, instead of sending the overview
> >> > data back to the client, there is a short pause (about 5 seconds) and
> >> > nnrpd dies, closing the connection to the client.
> >> 
> >> This is fixed in STABLE.  The problem was that nnrpd was using alloca to
> >> allocate memory for the SSL encryption buffer, which exploded if the data
> >> to be encrypted was larger than the stack size limit.  It wasn't a good
> >> place to use alloca and the current STABLE version switches to allocating
> >> regular heap memory for this purpose.
> >
> >Thanks Russ. 
> >
> >Is there any way to work around this with 2.4.4? 
> >
> >I don't like the idea of running a development snapshot on a live server. 
> 
> The fix for this is attached below.

Brilliant! Your patch against 2.4.4 seems to have fixed this one - many 
thanks Chris! 

Still working on the Keepalive problem, but I'll post again if I can't 
solve that one. 

Tim. 

-- 
Please remove all-your-clothes before replying. 
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79119
Author: Tim Fardell
Date: Wed, 11 Jun 2008 10:50
11 lines
1873 bytes
On Tue, 10 Jun 2008, Julien ÉLIE wrote:

> By the way, in order to address the issues discovered since the release of 2.4.4,
> a new version of INN will be released within a couple of weeks.

Thanks Julien. I think we will wait for the next "release" now, unless 
further problems occur with 2.4.4. 

-- 
Please remove all-your-clothes before replying. 
Re: Strange problem with nnrpd 2.4.4 and XOVER over SSL connection
#79137
Author: Julien ÉLIE
Date: Sun, 22 Jun 2008 10:42
20 lines
2310 bytes
Hi Tim,

>> By the way, in order to address the issues discovered since the release of 2.4.4,
>> a new version of INN will be released within a couple of weeks.
>
> Thanks Julien. I think we will wait for the next "release" now, unless
> further problems occur with 2.4.4.

Just to tell that I am a bit late for the release because of a bug report about
Python hook scripts which are not working (both on INN 2.4.x and 2.5).
I think it is now solved but it took me much time.

The 2.4.5 Release Candidate will come today or tomorrow.  It will normally works,
so I hope it will be released soon.

-- 
Julien ÉLIE

« Qui joue des flûtes perd sa hutte ! » (Astérix)
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