2017-06-10 09:01:17

by Jia-Ju Bai

[permalink] [raw]
Subject: [PATCH] net: tipc: Fix a sleep-in-atomic bug in tipc_msg_reverse

The kernel may sleep under a rcu read lock in tipc_msg_reverse, and the
function call path is:
tipc_l2_rcv_msg (acquire the lock by rcu_read_lock)
tipc_rcv
tipc_sk_rcv
tipc_msg_reverse
pskb_expand_head(GFP_KERNEL) --> may sleep
tipc_node_broadcast
tipc_node_xmit_skb
tipc_node_xmit
tipc_sk_rcv
tipc_msg_reverse
pskb_expand_head(GFP_KERNEL) --> may sleep

To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".

Signed-off-by: Jia-Ju Bai <[email protected]>
---
net/tipc/msg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index 312ef7d..ab30876 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -508,7 +508,7 @@ bool tipc_msg_reverse(u32 own_node, struct sk_buff **skb, int err)
}

if (skb_cloned(_skb) &&
- pskb_expand_head(_skb, BUF_HEADROOM, BUF_TAILROOM, GFP_KERNEL))
+ pskb_expand_head(_skb, BUF_HEADROOM, BUF_TAILROOM, GFP_ATOMIC))
goto exit;

/* Now reverse the concerned fields */
--
1.7.9.5



2017-06-10 13:18:13

by Jon Maloy

[permalink] [raw]
Subject: RE: [PATCH] net: tipc: Fix a sleep-in-atomic bug in tipc_msg_reverse

Acked.

///jon


> -----Original Message-----
> From: Jia-Ju Bai [mailto:[email protected]]
> Sent: Saturday, June 10, 2017 05:04
> To: Jon Maloy <[email protected]>; Ying Xue
> <[email protected]>; [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Jia-Ju Bai <[email protected]>
> Subject: [PATCH] net: tipc: Fix a sleep-in-atomic bug in tipc_msg_reverse
>
> The kernel may sleep under a rcu read lock in tipc_msg_reverse, and the
> function call path is:
> tipc_l2_rcv_msg (acquire the lock by rcu_read_lock)
> tipc_rcv
> tipc_sk_rcv
> tipc_msg_reverse
> pskb_expand_head(GFP_KERNEL) --> may sleep tipc_node_broadcast
> tipc_node_xmit_skb
> tipc_node_xmit
> tipc_sk_rcv
> tipc_msg_reverse
> pskb_expand_head(GFP_KERNEL) --> may sleep
>
> To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".
>
> Signed-off-by: Jia-Ju Bai <[email protected]>
> ---
> net/tipc/msg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 312ef7d..ab30876 100644
> --- a/net/tipc/msg.c
> +++ b/net/tipc/msg.c
> @@ -508,7 +508,7 @@ bool tipc_msg_reverse(u32 own_node, struct
> sk_buff **skb, int err)
> }
>
> if (skb_cloned(_skb) &&
> - pskb_expand_head(_skb, BUF_HEADROOM, BUF_TAILROOM,
> GFP_KERNEL))
> + pskb_expand_head(_skb, BUF_HEADROOM, BUF_TAILROOM,
> GFP_ATOMIC))
> goto exit;
>
> /* Now reverse the concerned fields */
> --
> 1.7.9.5
>


2017-06-10 22:21:45

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: tipc: Fix a sleep-in-atomic bug in tipc_msg_reverse

From: Jia-Ju Bai <[email protected]>
Date: Sat, 10 Jun 2017 17:03:35 +0800

> The kernel may sleep under a rcu read lock in tipc_msg_reverse, and the
> function call path is:
> tipc_l2_rcv_msg (acquire the lock by rcu_read_lock)
> tipc_rcv
> tipc_sk_rcv
> tipc_msg_reverse
> pskb_expand_head(GFP_KERNEL) --> may sleep
> tipc_node_broadcast
> tipc_node_xmit_skb
> tipc_node_xmit
> tipc_sk_rcv
> tipc_msg_reverse
> pskb_expand_head(GFP_KERNEL) --> may sleep
>
> To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".
>
> Signed-off-by: Jia-Ju Bai <[email protected]>

Applied and queued up for -stable.