Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5616059img; Wed, 27 Mar 2019 11:46:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGq6r3oi50pAH56bE+Cx+xHQwks/5CjIdapsgdKk2hbUX3+3+7fUWQE7d3nKVCwmb9NGG9 X-Received: by 2002:a63:f80f:: with SMTP id n15mr35895157pgh.283.1553712415386; Wed, 27 Mar 2019 11:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712415; cv=none; d=google.com; s=arc-20160816; b=aU70UmdqiRdWMWElM0pnHBFoMbUca2xpom0pPciW53f8HijaTna0LZDJfVoUk8jmoH 1j6vs425bv0YlQ2CLXzd8U+XEYmo9KsuySkUNNLo30YisuRiN4T9KYVZuu3l0POQKsND U0OJsP3VzwLYWTJ8mGwUq+Ozzx8TBjNEpWGdA39B4bjNcLciRCaGi33T7xVngQJxKCPv I4Mt9gFC4f5fiMSoQokdhkad6UvzzHweP7CXj1CQmUt8IbvBYqlVYwPgj4u3dfxGh5dQ 2pgD9QD1q5Yt+3Ef0KBblPo5V1KaldNRqZ5BljBWTAPLAgco8mWEQHEZKmDD9Ngs59Bo UEcQ== 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=tGt2VTYHrmfL9n6p8QOFLdnjp5o9AWKZ/zBp0HqzTTg=; b=SGU/2ck2oqLTgXdWwPdJ5BcZJKDQEZCg7ow2leI3WFFOdhYxLYiI1txNrWq8UHtNEv QplzrhYNxr045qb/h+PDwE+DB6pYWSl6pHTxANnKcyOANniWwnyRRgTt+fhShi0lSPU8 fFVV1GOhG+I94DSm/IxIR8uHU0BYzMx4zbfn3eNYnzZkHZGGG5WV6CUEG0om5tIMtff+ WXoJNeQrHrWbtYjJMfz9nIjTmmv+dgopKqdKIBOPbvG4aLXDiM8dyVs/H71gtM0rx4q0 auaMGcohJC8CzTAEoqQcS5ztRL2Ewcnp313EFAhseB+HSC2Cs0LeSHFUMCKttJwIyFyT kHcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cylfIBbM; 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 32si19687111plb.278.2019.03.27.11.46.39; Wed, 27 Mar 2019 11:46:55 -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=cylfIBbM; 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 S2391084AbfC0SVL (ORCPT + 99 others); Wed, 27 Mar 2019 14:21:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391041AbfC0SVJ (ORCPT ); Wed, 27 Mar 2019 14:21:09 -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 A0E8A2147C; Wed, 27 Mar 2019 18:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710868; bh=C90KdFVurOru+27x9lvZAq2zZZcarX0PSb/kb3PzBaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cylfIBbMv5PHDcPZ70wLkJ8TneMaHXw6AagdgA5aEkOqwXMDgCkRylr/Am9LYdmJL WivlkPXfzlw7JMO7ezu6M19PxYXmMbEh4ZwurDZy2MRBiRVkgYMfXFd1jIZccg0pzP zMDcaHgr1Z5uMdf7vFgd+kGxBBVzukiOrwu4y3jk= 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 4.9 14/87] ocfs2: fix a panic problem caused by o2cb_ctl Date: Wed, 27 Mar 2019 14:19:27 -0400 Message-Id: <20190327182040.17444-14-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-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 c204ac9b49e5..81a0d5d82757 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