All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] net: xfrm: Two possible sleep-in-atomic-context bugs
@ 2018-08-10  2:02 bai
  2018-08-10  5:36 ` Steffen Klassert
  0 siblings, 1 reply; 3+ messages in thread
From: bai @ 2018-08-10  2:02 UTC (permalink / raw)
  To: steffen.klassert, herbert, davem; +Cc: netdev, linux-kernel

The code may sleep in interrupt handler.
xfrm_trans_reinject() is an interrupt handler set in tasklet_init().
The function call paths (from bottom to top) in Linux-4.16 are:

[FUNC] schedule_timeout
net/core/sock.c, 2044: schedule_timeout in sock_wait_for_wmem
net/core/sock.c, 2083: sock_wait_for_wmem in sock_alloc_send_pskb
net/core/sock.c, 2102: sock_alloc_send_pskb in sock_alloc_send_skb
net/ipv6/mcast.c, 1989: sock_alloc_send_skb in igmp6_send
net/ipv6/mcast.c, 2391: igmp6_send in igmp6_join_group
net/ipv6/mcast.c, 670: igmp6_join_group in igmp6_group_added
net/ipv6/mcast.c, 914: igmp6_group_added in ipv6_dev_mc_inc
net/ipv6/ndisc.c, 379: ipv6_dev_mc_inc in pndisc_constructor
net/core/neighbour.c, 640: [FUNC_PTR]pndisc_constructor in pneigh_lookup
net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward
./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject

[FUNC] kmalloc(GFP_KERNEL)
net/core/neighbour.c, 630: kmalloc in pneigh_lookup
net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward
./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject

Note that [FUNC_PTR] means a function pointer call is used.

I do not find a good way to fix them, so I only report.
These possible bugs are found by my static analysis tool (DSAC) and 
checked by my code review.


Best wishes,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] net: xfrm: Two possible sleep-in-atomic-context bugs
  2018-08-10  2:02 [BUG] net: xfrm: Two possible sleep-in-atomic-context bugs bai
@ 2018-08-10  5:36 ` Steffen Klassert
  2018-08-10  7:30   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Steffen Klassert @ 2018-08-10  5:36 UTC (permalink / raw)
  To: bai; +Cc: herbert, davem, netdev, linux-kernel

On Fri, Aug 10, 2018 at 10:02:42AM +0800, bai wrote:
> The code may sleep in interrupt handler.
> xfrm_trans_reinject() is an interrupt handler set in tasklet_init().
> The function call paths (from bottom to top) in Linux-4.16 are:
> 
> [FUNC] schedule_timeout
> net/core/sock.c, 2044: schedule_timeout in sock_wait_for_wmem
> net/core/sock.c, 2083: sock_wait_for_wmem in sock_alloc_send_pskb
> net/core/sock.c, 2102: sock_alloc_send_pskb in sock_alloc_send_skb
> net/ipv6/mcast.c, 1989: sock_alloc_send_skb in igmp6_send

igmp6_send calls sock_alloc_send_skb with 'noblock = 1',
this means that sock_wait_for_wmem is not executed in
sock_alloc_send_pskb.

> net/ipv6/mcast.c, 2391: igmp6_send in igmp6_join_group
> net/ipv6/mcast.c, 670: igmp6_join_group in igmp6_group_added
> net/ipv6/mcast.c, 914: igmp6_group_added in ipv6_dev_mc_inc
> net/ipv6/ndisc.c, 379: ipv6_dev_mc_inc in pndisc_constructor
> net/core/neighbour.c, 640: [FUNC_PTR]pndisc_constructor in pneigh_lookup
> net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward
> ./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
> net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
> net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject
> 
> [FUNC] kmalloc(GFP_KERNEL)
> net/core/neighbour.c, 630: kmalloc in pneigh_lookup
> net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward

ip6_forward calls pneigh_lookup with 'creat = 0',
this means that pneigh_lookup does not do the kmalloc.

> ./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
> net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
> net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject
> 
> Note that [FUNC_PTR] means a function pointer call is used.
> 
> I do not find a good way to fix them, so I only report.
> These possible bugs are found by my static analysis tool (DSAC) and checked
> by my code review.

Both codepaths are ok, maybe you should fix your tool ;-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] net: xfrm: Two possible sleep-in-atomic-context bugs
  2018-08-10  5:36 ` Steffen Klassert
@ 2018-08-10  7:30   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2018-08-10  7:30 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: herbert, davem, netdev, linux-kernel

Thanks for your reply :)


On 2018/8/10 13:36, Steffen Klassert wrote:
> On Fri, Aug 10, 2018 at 10:02:42AM +0800, bai wrote:
>> The code may sleep in interrupt handler.
>> xfrm_trans_reinject() is an interrupt handler set in tasklet_init().
>> The function call paths (from bottom to top) in Linux-4.16 are:
>>
>> [FUNC] schedule_timeout
>> net/core/sock.c, 2044: schedule_timeout in sock_wait_for_wmem
>> net/core/sock.c, 2083: sock_wait_for_wmem in sock_alloc_send_pskb
>> net/core/sock.c, 2102: sock_alloc_send_pskb in sock_alloc_send_skb
>> net/ipv6/mcast.c, 1989: sock_alloc_send_skb in igmp6_send
> igmp6_send calls sock_alloc_send_skb with 'noblock = 1',
> this means that sock_wait_for_wmem is not executed in
> sock_alloc_send_pskb.
>
>> net/ipv6/mcast.c, 2391: igmp6_send in igmp6_join_group
>> net/ipv6/mcast.c, 670: igmp6_join_group in igmp6_group_added
>> net/ipv6/mcast.c, 914: igmp6_group_added in ipv6_dev_mc_inc
>> net/ipv6/ndisc.c, 379: ipv6_dev_mc_inc in pndisc_constructor
>> net/core/neighbour.c, 640: [FUNC_PTR]pndisc_constructor in pneigh_lookup
>> net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward
>> ./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
>> net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
>> net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject
>>
>> [FUNC] kmalloc(GFP_KERNEL)
>> net/core/neighbour.c, 630: kmalloc in pneigh_lookup
>> net/ipv6/ip6_output.c, 483: pneigh_lookup in ip6_forward
> ip6_forward calls pneigh_lookup with 'creat = 0',
> this means that pneigh_lookup does not do the kmalloc.
>
>> ./include/net/dst.h, 449: [FUNC_PTR]ip6_forward in dst_input
>> net/ipv6/ip6_input.c, 71: dst_input in ip6_rcv_finish
>> net/xfrm/xfrm_input.c, 511: [FUNC_PTR]ip6_rcv_finish in xfrm_trans_reinject
>>
>> Note that [FUNC_PTR] means a function pointer call is used.
>>
>> I do not find a good way to fix them, so I only report.
>> These possible bugs are found by my static analysis tool (DSAC) and checked
>> by my code review.
> Both codepaths are ok, maybe you should fix your tool ;-)

It seems that the path condition checking in my tool needs to be improved.
I will do it, thanks :)


Best wishes,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-10  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-10  2:02 [BUG] net: xfrm: Two possible sleep-in-atomic-context bugs bai
2018-08-10  5:36 ` Steffen Klassert
2018-08-10  7:30   ` Jia-Ju Bai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.