linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] packet: Fix error path in packet_init
@ 2019-05-08 15:32 YueHaibing
  2019-05-08 15:50 ` Eric Dumazet
  2019-05-09 14:52 ` [PATCH v2] " YueHaibing
  0 siblings, 2 replies; 5+ messages in thread
From: YueHaibing @ 2019-05-08 15:32 UTC (permalink / raw)
  To: davem, willemb; +Cc: linux-kernel, netdev, edumazet, maximmi, YueHaibing

 kernel BUG at lib/list_debug.c:47!
 invalid opcode: 0000 [#1
 CPU: 0 PID: 11195 Comm: rmmod Tainted: G        W         5.1.0+ #33
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
 RIP: 0010:__list_del_entry_valid+0x55/0x90
 Code: 12 48 39 d7 75 39 48 8b 50 08 48 39 d7 75 1d b8 01 00 00 00 5d c3 48 89 c2 48 89 fe 
 31 c0 48 c7 c7 40 3a fe 82 e8 74 c1 78 ff <0f> 0b 48 89 fe 31 c0 48 c7 c7 f0 3a fe 82 e8 61 c1 78 ff 0f 0b 48
 RSP: 0018:ffffc90001b8be48 EFLAGS: 00010246
 RAX: 000000000000004e RBX: ffffffffa0210000 RCX: 0000000000000000
 RDX: 0000000000000000 RSI: ffff888237a16808 RDI: 00000000ffffffff
 RBP: ffffc90001b8be48 R08: 0000000000000000 R09: 0000000000000001
 R10: 0000000000000000 R11: ffffffff842c1640 R12: 0000000000000800
 R13: 0000000000000000 R14: ffffc90001b8be58 R15: ffffffffa0210000
 FS:  00007f58963c7540(0000) GS:ffff888237a00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 000056064c7af818 CR3: 00000001e9895000 CR4: 00000000000006f0
 Call Trace:
  unregister_pernet_operations+0x34/0x110
  unregister_pernet_subsys+0x1c/0x30
  packet_exit+0x1c/0x1dd [af_packet
  __x64_sys_delete_module+0x16b/0x290
  ? trace_hardirqs_off_thunk+0x1a/0x1c
  do_syscall_64+0x6b/0x1d0
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

Fix error handing path in packet_init to
avoid possilbe issue if some error occur.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 net/packet/af_packet.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 90d4e3c..3917c75 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4598,14 +4598,30 @@ static void __exit packet_exit(void)
 
 static int __init packet_init(void)
 {
-	int rc = proto_register(&packet_proto, 0);
+	int rc;
 
-	if (rc != 0)
+	rc = proto_register(&packet_proto, 0);
+	if (rc)
 		goto out;
 
-	sock_register(&packet_family_ops);
-	register_pernet_subsys(&packet_net_ops);
-	register_netdevice_notifier(&packet_netdev_notifier);
+	rc = sock_register(&packet_family_ops);
+	if (rc)
+		goto out_proto;
+	rc = register_pernet_subsys(&packet_net_ops);
+	if (rc)
+		goto out_sock;
+	rc = register_netdevice_notifier(&packet_netdev_notifier);
+	if (rc)
+		goto out_pernet;
+
+	return 0;
+
+out_pernet:
+	unregister_pernet_subsys(&packet_net_ops);
+out_sock:
+	sock_unregister(PF_PACKET);
+out_proto:
+	proto_unregister(&packet_proto);
 out:
 	return rc;
 }
-- 
1.8.3.1



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

end of thread, other threads:[~2019-05-09 20:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 15:32 [PATCH] packet: Fix error path in packet_init YueHaibing
2019-05-08 15:50 ` Eric Dumazet
2019-05-09  2:48   ` YueHaibing
2019-05-09 14:52 ` [PATCH v2] " YueHaibing
2019-05-09 20:46   ` David Miller

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).