: ir243_ttp_sock_races-2.diff
PATCH 1/1 : ir243_ttp_sock_races-2.diff
Hi,
Please apply....
Jeanir243_ttp_sock_races-2.diff :
---------------------------
o [CRITICA] Avoid race condition in TSAP closure
o [CRITICA] Avoid race condition in socket closure
o [CRITICA] Avoid various race conditions in IrNET
o [CORRECT] Remove potential skb leaks
o [CORRECT] Remove IrNET discovery log leak
o [CORRECT] Don't export inline function (irda_lock)
o [FEATURE] Use skb_orphan() instead of skb_clone() + kfree_skb()
o [FEATURE] cleanups, comments
o [FEATURE] Reduce verbosity of the stack
include/net/irda/irmod.h renamed from include/net/irda/irmod.d2.h +10 -98
@@ -10,6 +10,7 @@* Modified by: Dag Brattli <[email protected]> * * Copyright (c) 1998-2000 Dag Brattli, All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -25,108 +26,19 @@#ifndef IRMOD_H #define IRMOD_H -#include <linux/skbuff.h> -#include <linux/miscdevice.h> +#include <net/irda/irda.h> /* Notify stuff */ -#include <net/irda/irqueue.h> +/* Nothing much here anymore - Maybe this header should be merged in +* another header like net/irda/irda.h... - Jean II */ -#define IRMGR_IOC_MAGIC 'm' -#define IRMGR_IOCTNPC _IO(IRMGR_IOC_MAGIC, 1) -#define IRMGR_IOC_MAXNR 1 - -/* -* Events that we pass to the user space manager -*/ -typedef enum { -EVENT_DEVICE_DISCOVERED =0 , -EVENT_REQUEST_MODULE , -EVENT_IRLAN_START , -EVENT_IRLAN_STOP , -EVENT_IRLPT_START ,/* Obsolete */ -EVENT_IRLPT_STOP ,/* Obsolete */ -EVENT_IROBEX_START ,/* Obsolete */ -EVENT_IROBEX_STOP ,/* Obsolete */ -EVENT_IRDA_STOP , -EVENT_NEED_PROCESS_CONTEXT , -}IRMGR_EVENT ; - -/* -* Event information passed to the IrManager daemon process -*/ -struct irmanager_event { -IRMGR_EVENT event; -char devname[10 ]; -char info[32 ]; -int service; -__u32 saddr; -__u32 daddr; -}; - -typedef void (*TODO_CALLBACK )(void *self,__u32 param); - -/* -* Same as irmanager_event but this one can be queued and inclueds some -* addtional information -*/ -struct irda_event { -irda_queue_t q;/* Must be first */ - -struct irmanager_event event; -}; - -/* -* Funtions with needs to be called with a process context -*/ -struct irda_todo { -irda_queue_t q;/* Must be first */ - -void *self; -TODO_CALLBACK callback; -__u32 param; -}; - -/* -* Main structure for the IrDA device (not much here :-) -*/ -struct irda_cb { -struct miscdevice dev; -wait_queue_head_t wait_queue; - -int in_use; - -irda_queue_t *event_queue;/* Events queued for the irmanager */ -irda_queue_t *todo_queue;/* Todo list */ -}; - -int irmod_init_module (void ); -void irmod_cleanup_module (void ); - -/* -* Function irda_lock (lock) -* -* Lock variable. Returns false if the lock is already set. -* -*/ -static inline int irda_lock (int *lock) -{ -if (test_and_set_bit (0 , (void *) lock)) { -IRDA_DEBUG (3 , __FUNCTION__ -"(), Trying to lock, already locked variable!\n" ); -return FALSE; - } -return TRUE; -} - -inline int irda_unlock (int *lock); +/* Locking wrapper - Note the inverted logic on irda_lock(). +* Those function basically return false if the lock is already in the +* position you want to set it. - Jean II */ +#define irda_lock (lock) (! test_and_set_bit(0, (void *) (lock))) +#define irda_unlock (lock) (test_and_clear_bit(0, (void *) (lock))) +/* Zero the notify structure */ void irda_notify_init (notify_t *notify); - -void irda_execute_as_process (void *self,TODO_CALLBACK callback,__u32 param); -void irmanager_notify (struct irmanager_event *event); - -extern void irda_proc_modcount (struct inode *,int ); -void irda_mod_inc_use_count (void ); -void irda_mod_dec_use_count (void );#endif /* IRMOD_H */
net/irda/irsyms.c renamed from net/irda/irsyms.d2.c +1 -16
@@ -10,6 +10,7 @@* Modified by: Dag Brattli <[email protected]> * * Copyright (c) 1997, 1999-2000 Dag Brattli, All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -79,7 +80,6 @@ EXPORT_SYMBOL(irttp_dup);EXPORT_SYMBOL (irda_debug);#endif EXPORT_SYMBOL (irda_notify_init); -EXPORT_SYMBOL (irda_lock);#ifdef CONFIG_PROC_FS EXPORT_SYMBOL (proc_irda);#endif
@@ -217,21 +217,6 @@ static void __exit irda_cleanup(void)/* Remove middle layer */ irlmp_cleanup (); -} - -/* -* Function irda_unlock (lock) -* -* Unlock variable. Returns false if lock is already unlocked -* -*/ -inline int irda_unlock (int *lock) -{ -if (!test_and_clear_bit (0 , (void *) lock)) { -printk ("Trying to unlock already unlocked variable!\n" ); -return FALSE; - } -return TRUE; }/*
net/irda/irttp.c renamed from net/irda/irttp.d2.c +57 -48
231 lines not on this page · raw message
net/irda/af_irda.c renamed from net/irda/af_irda.d2.c +33 -24
87 lines not on this page · raw message
net/irda/iriap.c renamed from net/irda/iriap.d2.c +2 -1
@@ -11,6 +11,7 @@* * Copyright (c) 1998-1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -773,7 +774,7 @@ static void iriap_connect_indication(voi {struct iriap_cb *self, *new; -IRDA_DEBUG (0 , __FUNCTION__"()\n" ); +IRDA_DEBUG (1 , __FUNCTION__"()\n" ); self = (struct iriap_cb *) instance;
net/irda/irnet/irnet.h renamed from net/irda/irnet/irnet.d2.h +16 -8
@@ -126,17 +126,17 @@* History : * ------- * -* v1 - 15/5/00 - Jean II +* v1 - 15.5.00 - Jean II * o Basic IrNET (hook to ppp_generic & IrTTP - incl. multipoint) * o control channel on /dev/irnet (set name/address) * o event channel on /dev/irnet (for user space daemon) * -* v2 - 5/6/00 - Jean II +* v2 - 5.6.00 - Jean II * o Enable DROP_NOT_READY to avoid PPP timeouts & other weirdness... * o Add DISCONNECT_TO event and rename DISCONNECT_FROM. * o Set official device number alloaction on /dev/irnet * -* v3 - 30/8/00 - Jean II +* v3 - 30.8.00 - Jean II * o Update to latest Linux-IrDA changes : * - queue_t => irda_queue_t * o Update to ppp-2.4.0 :
@@ -148,17 +148,17 @@* another multilink bug (darn !) * o Remove LINKNAME_IOCTL cruft * -* v3b - 31/8/00 - Jean II +* v3b - 31.8.00 - Jean II * o Dump discovery log at event channel startup * -* v4 - 28/9/00 - Jean II +* v4 - 28.9.00 - Jean II * o Fix interaction between poll/select and dump discovery log * o Add IRNET_BLOCKED_LINK event (depend on new IrDA-Linux patch) * o Add IRNET_NOANSWER_FROM event (mostly to help support) * o Release flow control in disconnect_indication * o Block packets while connecting (speed up connections) * -* v5 - 11/01/01 - Jean II +* v5 - 11.01.01 - Jean II * o Init self->max_header_size, just in case... * o Set up ap->chan.hdrlen, to get zero copy on tx side working. * o avoid tx->ttp->flow->ppp->tx->... loop, by checking flow state
@@ -169,7 +169,7 @@* o Declare hashbin HB_NOLOCK instead of HB_LOCAL to avoid * disabling and enabling irq twice * -* v6 - 31/05/01 - Jean II +* v6 - 31.05.01 - Jean II * o Print source address in Found, Discovery, Expiry & Request events * o Print requested source address in /proc/net/irnet * o Change control channel input. Allow multiple commands in one line.
@@ -186,12 +186,19 @@* o Add ttp_connect flag to prevent rentry on the connect procedure * o Test and fixups to eliminate side effects of retries * -* v7 - 22/08/01 - Jean II +* v7 - 22.08.01 - Jean II * o Cleanup : Change "saddr = 0x0" to "saddr = DEV_ADDR_ANY" * o Fix bug in BLOCK_WHEN_CONNECT introduced in v6 : due to the * asynchronous IAS query, self->tsap is NULL when PPP send the * first packet. This was preventing "connect-delay 0" to work. * Change the test in ppp_irnet_send() to self->ttp_connect. +* +* v8 - 1.11.01 - Jean II +* o Tighten the use of self->ttp_connect and self->ttp_open to +* prevent various race conditions. +* o Avoid leaking discovery log and skb +* o Replace "self" with "server" in irnet_connect_indication() to +* better detect cut'n'paste error ;-) */ /***************************** INCLUDES *****************************/
@@ -204,6 +211,7 @@#include <linux/proc_fs.h> #include <linux/devfs_fs_kernel.h> #include <linux/netdevice.h> +#include <linux/miscdevice.h> #include <linux/poll.h> #include <linux/config.h> #include <linux/ctype.h> /* isspace() */
net/irda/irnet/irnet_irda.c renamed from net/irda/irnet/irnet_irda.d2.c +147 -74
408 lines not on this page · raw message
net/irda/irnet/irnet_ppp.c renamed from net/irda/irnet/irnet_ppp.d2.c +2 -2
@@ -850,7 +850,7 @@ ppp_irnet_send(struct ppp_channel * chanDASSERT (self !=NULL ,0 ,PPP_ERROR ,"Self is NULL !!!\n" );/* Check if we are connected */ -if (self->ttp_open ==0 ) +if (!(test_bit (0 , &self->ttp_open))) {#ifdef CONNECT_IN_SEND /* Let's try to connect one more time... */
@@ -884,7 +884,7 @@ ppp_irnet_send(struct ppp_channel * chan*/ #ifdef BLOCK_WHEN_CONNECT /* If we are attempting to connect */ -if (self->ttp_connect) +if (test_bit (0 , &self->ttp_connect)) {/* Blocking packet, ppp_generic will retry later */ return 0 ;