netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net/sched: act_ife: initalize ife->metalist earlier
@ 2020-01-14 21:51 Eric Dumazet
  2020-01-15  9:14 ` Davide Caratti
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2020-01-14 21:51 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, syzbot, Davide Caratti

It seems better to init ife->metalist earlier in tcf_ife_init()
to avoid the following crash :

kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 10483 Comm: syz-executor216 Not tainted 5.5.0-rc5-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:_tcf_ife_cleanup net/sched/act_ife.c:412 [inline]
RIP: 0010:tcf_ife_cleanup+0x6e/0x400 net/sched/act_ife.c:431
Code: 48 c1 ea 03 80 3c 02 00 0f 85 94 03 00 00 49 8b bd f8 00 00 00 48 b8 00 00 00 00 00 fc ff df 4c 8d 67 e8 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 5c 03 00 00 48 bb 00 00 00 00 00 fc ff df 48 8b
RSP: 0018:ffffc90001dc6d00 EFLAGS: 00010246
RAX: dffffc0000000000 RBX: ffffffff864619c0 RCX: ffffffff815bfa09
RDX: 0000000000000000 RSI: 0000000000000004 RDI: 0000000000000000
RBP: ffffc90001dc6d50 R08: 0000000000000004 R09: fffff520003b8d8e
R10: fffff520003b8d8d R11: 0000000000000003 R12: ffffffffffffffe8
R13: ffff8880a79fc000 R14: ffff88809aba0e00 R15: 0000000000000000
FS:  0000000001b51880(0000) GS:ffff8880ae800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000563f52cce140 CR3: 0000000093541000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 tcf_action_cleanup+0x62/0x1b0 net/sched/act_api.c:119
 __tcf_action_put+0xfa/0x130 net/sched/act_api.c:135
 __tcf_idr_release net/sched/act_api.c:165 [inline]
 __tcf_idr_release+0x59/0xf0 net/sched/act_api.c:145
 tcf_idr_release include/net/act_api.h:171 [inline]
 tcf_ife_init+0x97c/0x1870 net/sched/act_ife.c:616
 tcf_action_init_1+0x6b6/0xa40 net/sched/act_api.c:944
 tcf_action_init+0x21a/0x330 net/sched/act_api.c:1000
 tcf_action_add+0xf5/0x3b0 net/sched/act_api.c:1410
 tc_ctl_action+0x390/0x488 net/sched/act_api.c:1465
 rtnetlink_rcv_msg+0x45e/0xaf0 net/core/rtnetlink.c:5424
 netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
 rtnetlink_rcv+0x1d/0x30 net/core/rtnetlink.c:5442
 netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
 netlink_unicast+0x58c/0x7d0 net/netlink/af_netlink.c:1328
 netlink_sendmsg+0x91c/0xea0 net/netlink/af_netlink.c:1917
 sock_sendmsg_nosec net/socket.c:639 [inline]
 sock_sendmsg+0xd7/0x130 net/socket.c:659
 ____sys_sendmsg+0x753/0x880 net/socket.c:2330
 ___sys_sendmsg+0x100/0x170 net/socket.c:2384
 __sys_sendmsg+0x105/0x1d0 net/socket.c:2417
 __do_sys_sendmsg net/socket.c:2426 [inline]
 __se_sys_sendmsg net/socket.c:2424 [inline]
 __x64_sys_sendmsg+0x78/0xb0 net/socket.c:2424
 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Fixes: 11a94d7fd80f ("net/sched: act_ife: validate the control action inside init()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: Davide Caratti <dcaratti@redhat.com>
---
 net/sched/act_ife.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 5e6379028fc392031f4b84599f666a2c61f071d2..cbc1cfd28d43acdb90a2db5338da2fa1848fbf52 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -530,6 +530,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 			return ret;
 		}
 		ret = ACT_P_CREATED;
+		INIT_LIST_HEAD(&ife->metalist);
 	} else if (!ovr) {
 		tcf_idr_release(*a, bind);
 		kfree(p);
@@ -567,9 +568,6 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 	}
 
 
-	if (ret == ACT_P_CREATED)
-		INIT_LIST_HEAD(&ife->metalist);
-
 	if (tb[TCA_IFE_METALST]) {
 		err = nla_parse_nested_deprecated(tb2, IFE_META_MAX,
 						  tb[TCA_IFE_METALST], NULL,
-- 
2.25.0.rc1.283.g88dfdc4193-goog


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

* Re: [PATCH net] net/sched: act_ife: initalize ife->metalist earlier
  2020-01-14 21:51 [PATCH net] net/sched: act_ife: initalize ife->metalist earlier Eric Dumazet
@ 2020-01-15  9:14 ` Davide Caratti
  2020-01-15 15:56   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Davide Caratti @ 2020-01-15  9:14 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller; +Cc: netdev, Eric Dumazet, syzbot

On Tue, 2020-01-14 at 13:51 -0800, Eric Dumazet wrote:
> It seems better to init ife->metalist earlier in tcf_ife_init()
> to avoid the following crash :

hello Eric, and thanks for the patch.

If I well understand the problem, we have

_tcf_ife_cleanup()

that does dereference of NULL ife->metalist,
because it has not yet initialized by tcf_ife_init(). This happened
probably because the control action was not valid (hence the Fixes:tag):
so, tcf_ife_init() jumped to the error path before doing INIT_LIST_HEAD().

I applied your patch to my tree, and I see this:

net/sched/act_ife.c: In function 'tcf_ife_init':
net/sched/act_ife.c:533:3: warning: 'ife' may be used uninitialized in
this function [-Wmaybe-uninitialized]
   INIT_LIST_HEAD(&ife->metalist);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And I think the warning is telling us a real problem, because

        ife = to_ife(*a);

is done below the if (!exists) { } statement where you are dereferencing
'ife'.

I think the proper fix should do one of these two things:
1) ensure that 'ife' is a valid pointer in the INIT_LIST_HEAD()
2) leave tcf_ife_init() as is, and fix the priblem in _tcf_ife_clenup() by
proper checking the value of ife->metalist  (which should be NULL in the
error path, because tcf_idr_create() does kzalloc() [1].
WDYT?

thanks!
-- 
davide

[1] https://elixir.bootlin.com/linux/latest/source/net/sched/act_api.c#L404



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

* Re: [PATCH net] net/sched: act_ife: initalize ife->metalist earlier
  2020-01-15  9:14 ` Davide Caratti
@ 2020-01-15 15:56   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2020-01-15 15:56 UTC (permalink / raw)
  To: Davide Caratti; +Cc: David S . Miller, netdev, Eric Dumazet, syzbot

On Wed, Jan 15, 2020 at 1:14 AM Davide Caratti <dcaratti@redhat.com> wrote:
>
> On Tue, 2020-01-14 at 13:51 -0800, Eric Dumazet wrote:
> > It seems better to init ife->metalist earlier in tcf_ife_init()
> > to avoid the following crash :
>
> hello Eric, and thanks for the patch.
>
> If I well understand the problem, we have
>
> _tcf_ife_cleanup()
>
> that does dereference of NULL ife->metalist,
> because it has not yet initialized by tcf_ife_init(). This happened
> probably because the control action was not valid (hence the Fixes:tag):
> so, tcf_ife_init() jumped to the error path before doing INIT_LIST_HEAD().
>
> I applied your patch to my tree, and I see this:
>
> net/sched/act_ife.c: In function 'tcf_ife_init':
> net/sched/act_ife.c:533:3: warning: 'ife' may be used uninitialized in
> this function [-Wmaybe-uninitialized]
>    INIT_LIST_HEAD(&ife->metalist);
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> And I think the warning is telling us a real problem, because
>
>         ife = to_ife(*a);
>

Oops right, thanks for catching this. I am sending a V2.

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

end of thread, other threads:[~2020-01-15 15:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 21:51 [PATCH net] net/sched: act_ife: initalize ife->metalist earlier Eric Dumazet
2020-01-15  9:14 ` Davide Caratti
2020-01-15 15:56   ` Eric Dumazet

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 NNTP newsgroup(s).