Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3049210rwe; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6tMNk5fLMVX+0T4gorR3KkRzNNY4TPRKjyU+F8T/5qyUd7pFPEyVfs784N+xu4q6Ktf4l4 X-Received: by 2002:a17:907:7e92:b0:741:5f7e:f1ac with SMTP id qb18-20020a1709077e9200b007415f7ef1acmr5778049ejc.176.1661774911378; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661774911; cv=none; d=google.com; s=arc-20160816; b=swq1wIRWcpoe/hBIYgbgE4kh6X7G3KWPRKfDVhIzXxuJnF4ex9a5223w0E+F68752g odpZ7bg6O1EPNrhSvYcRvFVgrqub5mtOUx2XQcYTrO8ycGqpASviQfF7fzv3RQy916Yh avKdDJDIuAxGQ5pJoibbKLUrhocsQhqB2A2S0OQfB9wQw7d+nfLpCRQb+aQpBoV+MBr2 zSRkVFRF3ID+Ss0S4TmBPtuGRM5+UJ/UgqDdCO3zvBNqh2FkCZ4Dsidf30YdWXNvApZ2 Q8xuLOPVGamhKpjl3lprkHqPUgZMH6bH7g4JeG3LVLEvU7hs8+zJdZf8BO/GSNtkB7Ea NWdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GDT2qNwqd5vNN4a9q4nPHbF5a7fdxWrHoZRQ3FzYrLg=; b=MByHa4OLSGUY78gSJ6WlcnL5TOJkwkOhRDJnSQMn3fxKWfR8ln1srqUha5I63QUyit YZR7UM2aUyDRiqhjWdCBOlz/9X09UOw8lB/LfE2YOsj+U/71HNa5CadWD5CCxqI/TnHX AfcZyinOgLI7oMNu7FluEbvc9oNvaqKgCTxrrVzdKyuF9hlHe4HgA8xWUNbLs+8MegdK +iSjmGF6ba5UB/BEkzzQWvh0ushAKg3yZ8I8hOyWZ9M7zsDa3ppbjI1CrTQXvf9GCFw1 svWsa2Wr1jZ4Yj9dQkqy1yhD+ELZ1XKbSNj9XZcL497lzuLFSApscHb+KkJGfrcG5g+k uBnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CpMfQy3Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg11-20020a170907a40b00b0073c227a5543si6443284ejc.169.2022.08.29.05.08.01; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CpMfQy3Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232555AbiH2LdT (ORCPT + 99 others); Mon, 29 Aug 2022 07:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232371AbiH2La3 (ORCPT ); Mon, 29 Aug 2022 07:30:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A99C77B1C4; Mon, 29 Aug 2022 04:18:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F164E6125C; Mon, 29 Aug 2022 11:17:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2E0EC433D6; Mon, 29 Aug 2022 11:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771875; bh=2wXPY9Vp+sFiohSlj8lahdsF/s7CwW0NniH6x4fkHI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CpMfQy3YG/82/htlzppEoBGSa+Jw8z5LZsuMiEfc8q59Oz0nJUW8CVyai0OQJ0luH flVd5sblvz4s/eZvvi9GJBOvu8G0+vsjmZDxgPrBAd+TurKFgqE08IQqTJPPqefLYZ 7mF3rQMOlpCPV5MuEmSvabUpKfM8zYsk45gfNvnw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heming Zhao , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Andrew Morton Subject: [PATCH 5.19 127/158] ocfs2: fix freeing uninitialized resource on ocfs2_dlm_shutdown Date: Mon, 29 Aug 2022 12:59:37 +0200 Message-Id: <20220829105814.414055139@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heming Zhao commit 550842cc60987b269e31b222283ade3e1b6c7fc8 upstream. After commit 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job before return error"), any procedure after ocfs2_dlm_init() fails will trigger crash when calling ocfs2_dlm_shutdown(). ie: On local mount mode, no dlm resource is initialized. If ocfs2_mount_volume() fails in ocfs2_find_slot(), error handling will call ocfs2_dlm_shutdown(), then does dlm resource cleanup job, which will trigger kernel crash. This solution should bypass uninitialized resources in ocfs2_dlm_shutdown(). Link: https://lkml.kernel.org/r/20220815085754.20417-1-heming.zhao@suse.com Fixes: 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job before return error") Signed-off-by: Heming Zhao Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Gang He Cc: Jun Piao Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/dlmglue.c | 8 +++++--- fs/ocfs2/super.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -3403,10 +3403,12 @@ void ocfs2_dlm_shutdown(struct ocfs2_sup ocfs2_lock_res_free(&osb->osb_nfs_sync_lockres); ocfs2_lock_res_free(&osb->osb_orphan_scan.os_lockres); - ocfs2_cluster_disconnect(osb->cconn, hangup_pending); - osb->cconn = NULL; + if (osb->cconn) { + ocfs2_cluster_disconnect(osb->cconn, hangup_pending); + osb->cconn = NULL; - ocfs2_dlm_shutdown_debug(osb); + ocfs2_dlm_shutdown_debug(osb); + } } static int ocfs2_drop_lock(struct ocfs2_super *osb, --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -1914,8 +1914,7 @@ static void ocfs2_dismount_volume(struct !ocfs2_is_hard_readonly(osb)) hangup_needed = 1; - if (osb->cconn) - ocfs2_dlm_shutdown(osb, hangup_needed); + ocfs2_dlm_shutdown(osb, hangup_needed); ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats); debugfs_remove_recursive(osb->osb_debug_root);