public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Hans H?bner <hans@huebner.org>
Cc: Will Lentz <will_lentz@trimble.com>, ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] uipc_socket.c (and cyg_tcp_maxidle)
Date: Fri, 17 Jun 2005 20:12:00 -0000	[thread overview]
Message-ID: <20050617200916.GB17597@lunn.ch> (raw)
In-Reply-To: <20050616083626.U69813@web.m68k.de>

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

On Thu, Jun 16, 2005 at 09:01:23AM +0200, Hans H?bner wrote:
> On Wed, 15 Jun 2005, Will Lentz wrote:
> 
> >I may have found a potential bug in
> >packages/net/bsd_tcpip/current/src/sys/kern/uipc_socket.c (or I may be
> >completely wrong :-).
> >
> >At the end of sodealloc(), the following code exists:
> >      zfreei(so->so_zone, so);
> >      wakeup(so->so_zone);
> >The problem is that zfreei() changes so->so_zone.  Shouldn't wakeup() be
> >done on the original so->so_zone?  I only noticed this problem by:
> >1- while(1) {
> >  sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
> >  connect( sock, ... );
> >  close( sock );
> >  }
> >  Eventually this pauses in socket() (in cyg_tsleep()) when you run out
> >of eCos sockets.
> >
> >2- After 2*MSL or so, cyg_wakeup() gets called with chan == 0x0.  Why?
> >The zfreei() call in sodealloc() changes so->so_zone to 0 before the
> >wakeup() call.

This is not quite correct. zfreei() does not change so->so_zone. What
it does is return the memory for the so structure to the pool. The
wakeup then uses the memory which has just been returned to the
pool. There is a race condition. Once back into the pool the memory
could be allocated to another thread before the call to wakeup is
made.

Attached is a patch to fix this.

        Andrew

[-- Attachment #2: sodealloc.diff --]
[-- Type: text/plain, Size: 1495 bytes --]

Index: net/bsd_tcpip/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.52
diff -u -r1.52 ChangeLog
--- net/bsd_tcpip/current/ChangeLog	27 Mar 2005 18:18:13 -0000	1.52
+++ net/bsd_tcpip/current/ChangeLog	17 Jun 2005 20:08:29 -0000
@@ -1,3 +1,8 @@
+2005-06-17  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* src/sys/kern/uipc_socket.c (sodealloc): Fixed a race condition
+	when freeing the socket memory. Problem reported by Will Lent.
+
 2005-03-27  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* src/sys/net/if.c (ifioctl): Fixed a compiler warning about 
Index: net/bsd_tcpip/current/src/sys/kern/uipc_socket.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/src/sys/kern/uipc_socket.c,v
retrieving revision 1.3
diff -u -r1.3 uipc_socket.c
--- net/bsd_tcpip/current/src/sys/kern/uipc_socket.c	24 Jul 2003 18:04:25 -0000	1.3
+++ net/bsd_tcpip/current/src/sys/kern/uipc_socket.c	17 Jun 2005 20:08:31 -0000
@@ -188,8 +188,10 @@
 void
 sodealloc(so)
 	struct socket *so;
+        
 {
-
+        vm_zone_t zone;
+  
 	so->so_gencnt = ++so_gencnt;
 #ifdef INET
 	if (so->so_accf != NULL) {
@@ -202,8 +204,9 @@
 		FREE(so->so_accf, M_ACCF);
 	}
 #endif /* INET */
-	zfreei(so->so_zone, so);
-        wakeup(so->so_zone);
+        zone = so->so_zone;
+        zfreei(zone, so);
+        wakeup(zone);
 }
 
 int


[-- Attachment #3: Type: text/plain, Size: 148 bytes --]

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

  parent reply	other threads:[~2005-06-17 20:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 22:39 [ECOS] uipc_socket.c Will Lentz
2005-06-16  7:06 ` [ECOS] uipc_socket.c (and cyg_tcp_maxidle) Hans Hübner
2005-06-16 15:36   ` Will Lentz
2005-06-16 15:51     ` Hans Hübner
2005-06-16 16:06       ` Will Lentz
     [not found]         ` <20050616183534.N69813@web.m68k.de>
2005-06-16 23:45           ` Will Lentz
2005-06-17  7:15             ` Andrew Lunn
2005-06-17 20:12   ` Andrew Lunn [this message]
2005-06-17 21:00     ` Will Lentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050617200916.GB17597@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=hans@huebner.org \
    --cc=will_lentz@trimble.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).