Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2189250ybm; Thu, 23 May 2019 12:50:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQQe7SSjsev5ZaGJ+bFInjjhekG+Njs3vrSHSItWVmUMFIn7GCbhHkRCtiu4UbSmZhFagO X-Received: by 2002:a17:90a:c587:: with SMTP id l7mr3692744pjt.50.1558641030162; Thu, 23 May 2019 12:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558641030; cv=none; d=google.com; s=arc-20160816; b=w1Im4IgC6GXaHuxNXP83l5mTFPPyobGykNljEcGLAS9bzb2G7+usPTpB0/CQUd2jKD ePlayNCFOLep8CFxrFeN5nnBdKVpl/TyyKIaWtebpl36xZzOvQ6R67aAFrFBMe+1l4AA 8ot9YPawh3V091yXsq3kwANnd2JjXCrzZTLlFDkcOWf+S4S0C/SyUll+YQ9C3U7aoxvx oGMWwuPQoaJDLSGkaSDfuSN+1RlxdERnSLjOgzK9tylzWit3rpDvYwhUTO/5tPU7C20g VPQaaKorpQ4jkgirg3Ysj5YbhRhH1UQ7cXPfZoKTq8N3S27W2jyILegmXI18qgHlPkor hRFw== 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=EDp6oulHXBoOv1IcGgabDG/MBzW+veD0KQstgBZCVEI=; b=pD6iG+GjQWRjU/8rgCfOOHE1lmacbpXWtqC8Br9UPSXG/UNwb3pWYqEfElVKASHXIa Oc7O2EjI5vlWl/xwoN6MenUpr8AZ0R0yxeiB2OtYxLWFC/SNoGtQ4Tm8C4GiLUB8JQ9n ZuykW5WLWC5/g3UOVgKio8U/d86Py3YSzi52Fk1uTWRgDFUaQmasm0T4ObbjL8Kk43DI yWMdKLAZiWEJer7U0QUFxRRHNiQthY/aS0LWSQx7szcsJ4kmEW53pvBUqWbSgt77v4Lr SD6R8yw68kd2OGX3TaVMuFWGGSc4w0VCuLxRQRqOA9URrIqWn4pgFXVXAt0Gg1qpqhPz R7zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V7TLqjq9; 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 a66si363098pje.2.2019.05.23.12.50.15; Thu, 23 May 2019 12:50:30 -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=V7TLqjq9; 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 S2388096AbfEWTLM (ORCPT + 99 others); Thu, 23 May 2019 15:11:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:44526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388079AbfEWTLH (ORCPT ); Thu, 23 May 2019 15:11:07 -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 B7283217D7; Thu, 23 May 2019 19:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638667; bh=x6thWel1AU0LQgl9B8M1qfwthnSUJktIQxfj+isHwWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V7TLqjq9nlen6IADBYXLeXof1RUYhbhBoQnNpaPNGK7Ee+Lb6anHbxkUNsNr/6wQ0 uOsZkRC/tKCjmV1ovU75W0zLEzQ9IbSGN0eNXCFBThc8/z3y+8AR8+F5wywAOVRQKB M2i3Ag0NxsETnfRlE+uo43lXIiN1V6fHHS8ZzRM8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junwei Hu , Wang Wang , Xiaogang Wang , "David S. Miller" Subject: [PATCH 4.14 06/77] tipc: switch order of device registration to fix a crash Date: Thu, 23 May 2019 21:05:24 +0200 Message-Id: <20190523181720.958407871@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@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: Junwei Hu [ Upstream commit 7e27e8d6130c5e88fac9ddec4249f7f2337fe7f8 ] When tipc is loaded while many processes try to create a TIPC socket, a crash occurs: PANIC: Unable to handle kernel paging request at virtual address "dfff20000000021d" pc : tipc_sk_create+0x374/0x1180 [tipc] lr : tipc_sk_create+0x374/0x1180 [tipc] Exception class = DABT (current EL), IL = 32 bits Call trace: tipc_sk_create+0x374/0x1180 [tipc] __sock_create+0x1cc/0x408 __sys_socket+0xec/0x1f0 __arm64_sys_socket+0x74/0xa8 ... This is due to race between sock_create and unfinished register_pernet_device. tipc_sk_insert tries to do "net_generic(net, tipc_net_id)". but tipc_net_id is not initialized yet. So switch the order of the two to close the race. This can be reproduced with multiple processes doing socket(AF_TIPC, ...) and one process doing module removal. Fixes: a62fbccecd62 ("tipc: make subscriber server support net namespace") Signed-off-by: Junwei Hu Reported-by: Wang Wang Reviewed-by: Xiaogang Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -125,10 +125,6 @@ static int __init tipc_init(void) if (err) goto out_netlink_compat; - err = tipc_socket_init(); - if (err) - goto out_socket; - err = tipc_register_sysctl(); if (err) goto out_sysctl; @@ -137,6 +133,10 @@ static int __init tipc_init(void) if (err) goto out_pernet; + err = tipc_socket_init(); + if (err) + goto out_socket; + err = tipc_bearer_setup(); if (err) goto out_bearer; @@ -144,12 +144,12 @@ static int __init tipc_init(void) pr_info("Started in single node mode\n"); return 0; out_bearer: + tipc_socket_stop(); +out_socket: unregister_pernet_subsys(&tipc_net_ops); out_pernet: tipc_unregister_sysctl(); out_sysctl: - tipc_socket_stop(); -out_socket: tipc_netlink_compat_stop(); out_netlink_compat: tipc_netlink_stop(); @@ -161,10 +161,10 @@ out_netlink: static void __exit tipc_exit(void) { tipc_bearer_cleanup(); + tipc_socket_stop(); unregister_pernet_subsys(&tipc_net_ops); tipc_netlink_stop(); tipc_netlink_compat_stop(); - tipc_socket_stop(); tipc_unregister_sysctl(); pr_info("Deactivated\n");