Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5654951img; Wed, 27 Mar 2019 12:32:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWCbKGrYdt8M4XRrc7b1lcnU/YMaLf0ILyVdz0wrGvvt6LJKKm8JpzwmSl8hFraDeOw8Mz X-Received: by 2002:aa7:91d7:: with SMTP id z23mr37655111pfa.137.1553715150415; Wed, 27 Mar 2019 12:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715150; cv=none; d=google.com; s=arc-20160816; b=gX2ruCnTifqqCRcNH6BZ/Zu6EhRvCzJuGcTBhJmmDcQOvlq62HjJGdUI+QRiO7y0Yd J8Ael7NgADGxp16mrTpnqnh6OTeHSYr1+yuVoqrdnb9mDVMkhy7/zecvW8QAcAwYNnh1 dPfCNMMDMjFoZhmWvfuoe4TdJ9cTX+dlvjgGlZNImVqXArvbMpFNE6swDw4+odmIFHfY x6mS1Lh5ZIbRpHojr3/QHABvDb+6bOqW1xq03cUtlWSnpaQOS0pvbwoamyDqUM/uE0Ig CpiERFyiH52pgouO/zUbHN0VG7o48JC82qlA7R5VMNi0fNXIo/33emw2qojKIwZSIWlv g0kg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/FOMgE2g8nO9Cd0EpF/9Xef+hh0ev4eVEcHHMVAmR88=; b=Qa/YNOFGGbKMtHWfgNsHTzy17QylehLG7QYg/GTdObntH5DPTtG80bRQFBp+ZLfP/3 AuMqzP+J8j84QDKk8z9IZZAqidCrSKh3QMmmwfUnaDuYuk+nUeqrtziY8H5kKO5KRzbo o6IEiTY1Oh1zdunUD8V72qlmNWhgPiDDb6b7gGdrMoVEzG90GsY8lJsIqFTztU4mzkZo Jwc4sPz+fFRXqkUm7XuJKXqPjKrDMj7skP0sEvhn+jL5RnYTOjsk/NLv6zh1NZWRrngp h2v0viI64eihg7oyo+KRwacr08jnH52vyx7s7+jVJtqYTgAhjlUYSkdZF2M56RgMgeU2 7P/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A5VRgT48; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si3894603pgc.157.2019.03.27.12.32.14; Wed, 27 Mar 2019 12:32: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=A5VRgT48; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387667AbfC0Tbb (ORCPT + 99 others); Wed, 27 Mar 2019 15:31:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:43376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732159AbfC0SDP (ORCPT ); Wed, 27 Mar 2019 14:03:15 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1328C217D9; Wed, 27 Mar 2019 18:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709794; bh=bkvAwSRW2kdTBz6wEtsCEVuLtCU6WmdZ3q5g1mqKhYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A5VRgT48xVKd/HrywgW0QAcHDO3yur8EAdz8UVM8gu+BY9S1WRW9j0uNPGZb7QCHY Ym976fxPZlu46cx7GgE7JbT6RlVSTU6UgTAcyjGMLs/rjRT9nZHN+54flHsvL6ammF pNYFeHMR7iC9Nb/WguAo1jC/MqBLtusSiSThZCYA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jia Guo , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL 5.0 040/262] ocfs2: fix a panic problem caused by o2cb_ctl Date: Wed, 27 Mar 2019 13:58:15 -0400 Message-Id: <20190327180158.10245-40-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jia Guo [ Upstream commit cc725ef3cb202ef2019a3c67c8913efa05c3cce6 ] In the process of creating a node, it will cause NULL pointer dereference in kernel if o2cb_ctl failed in the interval (mkdir, o2cb_set_node_attribute(node_num)] in function o2cb_add_node. The node num is initialized to 0 in function o2nm_node_group_make_item, o2nm_node_group_drop_item will mistake the node number 0 for a valid node number when we delete the node before the node number is set correctly. If the local node number of the current host happens to be 0, cluster->cl_local_node will be set to O2NM_INVALID_NODE_NUM while o2hb_thread still running. The panic stack is generated as follows: o2hb_thread \-o2hb_do_disk_heartbeat \-o2hb_check_own_slot |-slot = ®->hr_slots[o2nm_this_node()]; //o2nm_this_node() return O2NM_INVALID_NODE_NUM We need to check whether the node number is set when we delete the node. Link: http://lkml.kernel.org/r/133d8045-72cc-863e-8eae-5013f9f6bc51@huawei.com Signed-off-by: Jia Guo Reviewed-by: Joseph Qi Acked-by: Jun Piao Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/cluster/nodemanager.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c index 0e4166cc23a0..4ac775e32240 100644 --- a/fs/ocfs2/cluster/nodemanager.c +++ b/fs/ocfs2/cluster/nodemanager.c @@ -621,13 +621,15 @@ static void o2nm_node_group_drop_item(struct config_group *group, struct o2nm_node *node = to_o2nm_node(item); struct o2nm_cluster *cluster = to_o2nm_cluster(group->cg_item.ci_parent); - o2net_disconnect_node(node); + if (cluster->cl_nodes[node->nd_num] == node) { + o2net_disconnect_node(node); - if (cluster->cl_has_local && - (cluster->cl_local_node == node->nd_num)) { - cluster->cl_has_local = 0; - cluster->cl_local_node = O2NM_INVALID_NODE_NUM; - o2net_stop_listening(node); + if (cluster->cl_has_local && + (cluster->cl_local_node == node->nd_num)) { + cluster->cl_has_local = 0; + cluster->cl_local_node = O2NM_INVALID_NODE_NUM; + o2net_stop_listening(node); + } } /* XXX call into net to stop this node from trading messages */ -- 2.19.1