Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp462800yba; Wed, 15 May 2019 04:33:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNF5qeh5laUgqbKY9yLPZBjcJRskXy69enhmGoNXavvxx2swu1uNdtGa0P+r35+YBU56Rq X-Received: by 2002:a63:495e:: with SMTP id y30mr1170693pgk.185.1557919981819; Wed, 15 May 2019 04:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919981; cv=none; d=google.com; s=arc-20160816; b=f4QHOBieo2np6I+B1GHXmmnD9w7G8RoH+thsMErQLXxKojsfhgoxgxjll4HNSiLsBN vd+apNlLY2sg2+DRbJAXPz9A2zVCMzHjNJDkPIn1T6cPGSbYxUowKjxs7phpP5UGkdSD I8LdSOIO/LgKWgrDrqlMdYSP786rtok5Jc31H1vu/S6PF2qT9s2lNkpdm+G+b6qS446r VhxQXXyIPnMWnbDCyxvQWIsYORo4FKHtXBCESgKPktNr4tXH9pe2n68kZJqhgcurgCZY Onh8IXc/rTDvQlcjt2Cnvp/eRaK22sLINd766P8XyKLC20COmoc8K4l/jL30ovz6K3Fo vhOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bNet+4nnDJooQ3PfVVmXoqViyAJwafjt9ztkoO7Fgy0=; b=M4PchU/3bnFgRKr7//76W8Zg5dtWMHu3vdtm/LbSIh9/USVrg9KGkiyjQJ9e/iaSJw WyZCL6WwFO1rulbvlAC+IVxQ/usIgJW6jS2mviVf2gnx2YJfp6oPNX5Fz7sopE4F56EV EnFb064H9SYh5WE0fkS/vLyQGQBimZgHUHSZ7WrqrXPd0tbyzuFa77K1MQKiG/zPzHWM sFKKmnd+3FDsmuaRLV0CB7YdkJStfc3GwtgyU5Tn5UHWU0IMajoi+kjjHaJTbLDJulwO c45HxeXecePkoHZqpF97GOQIeqrAoKE1uR92uQb/5GELLOZcQ+Vm42oK+wRNR9l1XvuE BsAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j3aRyHvy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si1554029pgo.517.2019.05.15.04.32.46; Wed, 15 May 2019 04:33:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j3aRyHvy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732805AbfEOLaw (ORCPT + 99 others); Wed, 15 May 2019 07:30:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:42430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732793AbfEOLau (ORCPT ); Wed, 15 May 2019 07:30:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4229420843; Wed, 15 May 2019 11:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919849; bh=QfVRAJ/Ne52ihoN9sOBFHEmzsb56LqJqKscfzZHqdsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j3aRyHvywP6x48C2Xn2hYFEwXGeZWUEqaabYiXCGAnl3p8eA6yGG+gpHpVpCKoXyq 0Sqfqd4NGfq9wzCih2n1srLkpIl3c+MF8L1iYRTv1wHKOmYOjg/Q1EpxTyBzObgVQO 3ie4geU8xE0z+FgzfQ4J94Doj8JS4gNiOmS1fNbY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , YueHaibing , "David S. Miller" Subject: [PATCH 5.0 115/137] packet: Fix error path in packet_init Date: Wed, 15 May 2019 12:56:36 +0200 Message-Id: <20190515090701.986217985@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: YueHaibing [ Upstream commit 36096f2f4fa05f7678bc87397665491700bae757 ] kernel BUG at lib/list_debug.c:47! invalid opcode: 0000 [#1 CPU: 0 PID: 12914 Comm: rmmod Tainted: G W 5.1.0+ #47 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+0x53/0x90 Code: 48 8b 32 48 39 fe 75 35 48 8b 50 08 48 39 f2 75 40 b8 01 00 00 00 5d c3 48 89 fe 48 89 c2 48 c7 c7 18 75 fe 82 e8 cb 34 78 ff <0f> 0b 48 89 fe 48 c7 c7 50 75 fe 82 e8 ba 34 78 ff 0f 0b 48 89 f2 RSP: 0018:ffffc90001c2fe40 EFLAGS: 00010286 RAX: 000000000000004e RBX: ffffffffa0184000 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff888237a17788 RDI: 00000000ffffffff RBP: ffffc90001c2fe40 R08: 0000000000000000 R09: 0000000000000000 R10: ffffc90001c2fe10 R11: 0000000000000000 R12: 0000000000000000 R13: ffffc90001c2fe50 R14: ffffffffa0184000 R15: 0000000000000000 FS: 00007f3d83634540(0000) GS:ffff888237a00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555c350ea818 CR3: 0000000231677000 CR4: 00000000000006f0 Call Trace: unregister_pernet_operations+0x34/0x120 unregister_pernet_subsys+0x1c/0x30 packet_exit+0x1c/0x369 [af_packet __x64_sys_delete_module+0x156/0x260 ? lockdep_hardirqs_on+0x133/0x1b0 ? do_syscall_64+0x12/0x1f0 do_syscall_64+0x6e/0x1f0 entry_SYSCALL_64_after_hwframe+0x49/0xbe When modprobe af_packet, register_pernet_subsys fails and does a cleanup, ops->list is set to LIST_POISON1, but the module init is considered to success, then while rmmod it, BUG() is triggered in __list_del_entry_valid which is called from unregister_pernet_subsys. This patch fix error handing path in packet_init to avoid possilbe issue if some error occur. Reported-by: Hulk Robot Signed-off-by: YueHaibing Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4604,14 +4604,29 @@ 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; + 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; - sock_register(&packet_family_ops); - register_pernet_subsys(&packet_net_ops); - register_netdevice_notifier(&packet_netdev_notifier); + 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; }