staging: batman-adv: check kmalloc() return value
Subsystems (2)
PATCH 1/1 staging: batman-adv: check kmalloc() return value
kmalloc() may fail, if so drop current packet.
---
Compile tested.
drivers/staging/batman-adv/routing.c | 6 ++++-- drivers/staging/batman-adv/unicast.c | 8 ++++++-- drivers/staging/batman-adv/unicast.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)
drivers/staging/batman-adv/routing.c +4 -2
@@ -1232,8 +1232,10 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if) orig_node->last_frag_packet = jiffies; -if (list_empty (&orig_node->frag_list)) -create_frag_buffer (&orig_node->frag_list); +if (list_empty (&orig_node->frag_list)) { +if (create_frag_buffer (&orig_node->frag_list)) +return NET_RX_DROP ; + } tmp_frag_entry search_frag_packet(&orig_node->frag_list,
drivers/staging/batman-adv/unicast.c +6 -2
@@ -78,7 +78,7 @@ void create_frag_entry(struct list_head *head, struct sk_buff *skb)return ; } -void create_frag_buffer (struct list_head *head) +int create_frag_buffer (struct list_head *head) {int i;struct frag_packet_list_entry *tfp;
@@ -86,13 +86,17 @@ void create_frag_buffer(struct list_head *head)for (i =0 ; i <FRAG_BUFFER_SIZE ; i++) { tfp =kmalloc (sizeof (struct frag_packet_list_entry ),GFP_ATOMIC ); +if (tfp =NULL ) { +frag_list_free (head); +return -ENOMEM ; + } tfp->skb =NULL ; tfp->seqno =0 ;INIT_LIST_HEAD (&tfp->list);list_add (&tfp->list, head); } -return ; +return 0 ; } struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
drivers/staging/batman-adv/unicast.h +1 -1
@@ -30,7 +30,7 @@ struct sk_buff *merge_frag_packet(struct list_head *head, struct sk_buff *skb);void create_frag_entry (struct list_head *head,struct sk_buff *skb); -void create_frag_buffer (struct list_head *head); +int create_frag_buffer (struct list_head *head);struct frag_packet_list_entry *search_frag_packet (struct list_head *head,struct unicast_frag_packet *up);void frag_list_free (struct list_head *head);
Signature · 1 line
1.7.0.4
Quoted 3 lines · On Sunday 12 September 2010 20:56:26 Vasiliy Kulikov wrote:
kmalloc()may fail, if so drop current packet.Signed-off-by Vasiliy Kulikov <[email protected]>
Looks good to me. Added this patch to our repos.
Thanks,
Marek
Quoted 1 line · Vasiliy Kulikov
kmalloc()may fail, if so drop current packet.
Thanks for your patch. The indention is right, but it adds just another bug (locking related).
Quoted 26 lines
Signed-off-by Vasiliy Kulikov <[email protected]>---
Compile tested.drivers/staging/batman-adv/routing.c | 6 ++++-- drivers/staging/batman-adv/unicast.c | 8 ++++++-- drivers/staging/batman-adv/unicast.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/drivers/staging/batman-adv/routing.cindex e12fd99..e545260 100644drivers/staging/batman-adv/routing.c +4
-2@@ -1232,8 +1232,10 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if) orig_node->last_frag_packet = jiffies; -if (list_empty (&orig_node->frag_list)) -create_frag_buffer (&orig_node->frag_list); +if (list_empty (&orig_node->frag_list)) { +if (create_frag_buffer (&orig_node->frag_list)) +return NET_RX_DROP ; + } tmp_frag_entry =
Quoted 1 line
search_frag_packet(&orig_node->frag_list,
You must spin_unlock_irqrestore before you return from that function.
Best regards,
Sven
PATCH 1/1 batman-adv: Unlock on failure during fragmentation rx
When we detect a failure in create_frag_buffer we must drop the packet and unlock the orig_has which was locked before. 69d187ffb8e22024a87d8457e5dcb10e297108e9 forgot that and created a potential deadlock of the complete system.
--- routing.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
routing.c +5 -3
@@ -1233,9 +1233,11 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if) orig_node->last_frag_packet = jiffies; -if (list_empty (&orig_node->frag_list)) { -if (create_frag_buffer (&orig_node->frag_list)) -return NET_RX_DROP ; +if (list_empty (&orig_node->frag_list) && +create_frag_buffer (&orig_node->frag_list)) { +spin_unlock_irqrestore (&bat_priv->orig_hash_lock, + flags); +return NET_RX_DROP ; } tmp_frag_entry =
Signature · 1 line
1.7.2.3
Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Unlock on failure during fragmentation rx
Quoted 6 lines · On Sunday 12 September 2010 23:00:42 Sven Eckelmann wrote:
When we detect a failure in
create_frag_bufferwe must drop the packet and unlock theorig_haswhich was locked before.69d187ffb8e22024a87d8457e5dcb10e297108e9forgot that and created a potential deadlock of the complete system.Signed-off-by Sven Eckelmann <[email protected]>
Good catch - applied in revision 1791.
Thanks,
Marek