Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663794pxb; Tue, 5 Apr 2022 17:51:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqCWosZgmML3KIpG6rV6MVlv4jrDY4w9ua5onbNj4M3oCvLZM4q1JEnZq/IdxyCH2MzjIr X-Received: by 2002:a17:906:e5b:b0:6e7:f3a7:7b66 with SMTP id q27-20020a1709060e5b00b006e7f3a77b66mr6077207eji.355.1649206305246; Tue, 05 Apr 2022 17:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206305; cv=none; d=google.com; s=arc-20160816; b=mJepXv25zh20Z5QcHQ4+Uk3ph3QxMw6ypOkbHDVnFr+B9sTH4jTdGpbh5N/+0sKlWz TpGEISE1aeMf0hdwFIahD4PBMIIbMhf5vjbuktJuQ4yXoMtvqkzqE28Rh8GHoc0foZzA YCsmFE+MouOcMSoMHmg1SckYRd3AoKQukVB07sb5+m/wRO7x2OhzWt210OhYRCnzSzdx fn8otqoCIdTxikvCzhnIVywV3OPhopHH0lIKm28RDcW6u3VOWq3hvh2p5LWSot4m3Ede LhzPy+y1/8mxooSrocnvKL7IOI9BNP0b//3TVsETQb5T/XP7HdUwdJ4zcS1wocphoYh5 ANcw== 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=cuCbVr++ksctbWNtACha67mMq2pk2q3/8ke2gBvB1Q0=; b=MkOaVVB9/s+CfQjdXU6pIlyvH12cbvCcL1hPLPjJ1F9sWBF64nCISHnhIyIROxO8Mm aLY3Q9ERkv25NDD/glCz+Dee9n9c6N61sKwGYU5JXc4dcQNWruc2r/1ve+0rVGIU2qKA yVtCg+do8DyAWeXi0IIP1QzoKIduMaV6oWT/TLWK/SILmyE6gPT/f/YW5Le8RsTRuJAS /IMoREiSq4MXAsarn0py/kADJXQzddwJhzmYgqjreLnaZyj2KrqV2QxltRz7RukoyHFP m/9wQla/dQ8uupFzSSTxazx8Afi3DjA2+XkUPZ5W5rAx06sgJdxXu3mjn+mP5oOrEAc3 kMHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VbtE5C6t; 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 u8-20020a05640207c800b0041cdbbdfe61si4186997edy.551.2022.04.05.17.51.15; Tue, 05 Apr 2022 17:51:45 -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=VbtE5C6t; 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 S232670AbiDEHy1 (ORCPT + 99 others); Tue, 5 Apr 2022 03:54:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233539AbiDEHr4 (ORCPT ); Tue, 5 Apr 2022 03:47:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53CDE91AEE; Tue, 5 Apr 2022 00:45:09 -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 DA91C616C3; Tue, 5 Apr 2022 07:45:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6BDCC340EE; Tue, 5 Apr 2022 07:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144708; bh=r14M1DWPwRyo4+jvdjnECycfq43gChG0BjIE5UEYJjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbtE5C6tPzYBrcQs+ljUTrJMFaSNILYNPWk08vfIOwaMPswwB8Gke7T6LBkNw4QdB pc/Vrs3HvdaT2LM39QkARFOSozMP+pBbaZj824vKigvo6Geaz85oyWQ8ccP1NUegQC 5+jNEcXbpkMIhtCesYU0rnZhUT9mXDGQu32Lcdng= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joseph Qi , Dayvison , Valentin Vidic , Andrew Morton , Linus Torvalds Subject: [PATCH 5.17 0103/1126] ocfs2: fix crash when mount with quota enabled Date: Tue, 5 Apr 2022 09:14:10 +0200 Message-Id: <20220405070410.592049559@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 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: Joseph Qi commit de19433423c7bedabbd4f9a25f7dbc62c5e78921 upstream. There is a reported crash when mounting ocfs2 with quota enabled. RIP: 0010:ocfs2_qinfo_lock_res_init+0x44/0x50 [ocfs2] Call Trace: ocfs2_local_read_info+0xb9/0x6f0 [ocfs2] dquot_load_quota_sb+0x216/0x470 dquot_load_quota_inode+0x85/0x100 ocfs2_enable_quotas+0xa0/0x1c0 [ocfs2] ocfs2_fill_super.cold+0xc8/0x1bf [ocfs2] mount_bdev+0x185/0x1b0 legacy_get_tree+0x27/0x40 vfs_get_tree+0x25/0xb0 path_mount+0x465/0xac0 __x64_sys_mount+0x103/0x140 It is caused by when initializing dqi_gqlock, the corresponding dqi_type and dqi_sb are not properly initialized. This issue is introduced by commit 6c85c2c72819, which wants to avoid accessing uninitialized variables in error cases. So make global quota info properly initialized. Link: https://lkml.kernel.org/r/20220323023644.40084-1-joseph.qi@linux.alibaba.com Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1007141 Fixes: 6c85c2c72819 ("ocfs2: quota_local: fix possible uninitialized-variable access in ocfs2_local_read_info()") Signed-off-by: Joseph Qi Reported-by: Dayvison Tested-by: Valentin Vidic Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/quota_global.c | 23 ++++++++++++----------- fs/ocfs2/quota_local.c | 2 -- 2 files changed, 12 insertions(+), 13 deletions(-) --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c @@ -337,7 +337,6 @@ void ocfs2_unlock_global_qf(struct ocfs2 /* Read information header from global quota file */ int ocfs2_global_read_info(struct super_block *sb, int type) { - struct inode *gqinode = NULL; unsigned int ino[OCFS2_MAXQUOTAS] = { USER_QUOTA_SYSTEM_INODE, GROUP_QUOTA_SYSTEM_INODE }; struct ocfs2_global_disk_dqinfo dinfo; @@ -346,29 +345,31 @@ int ocfs2_global_read_info(struct super_ u64 pcount; int status; + oinfo->dqi_gi.dqi_sb = sb; + oinfo->dqi_gi.dqi_type = type; + ocfs2_qinfo_lock_res_init(&oinfo->dqi_gqlock, oinfo); + oinfo->dqi_gi.dqi_entry_size = sizeof(struct ocfs2_global_disk_dqblk); + oinfo->dqi_gi.dqi_ops = &ocfs2_global_ops; + oinfo->dqi_gqi_bh = NULL; + oinfo->dqi_gqi_count = 0; + /* Read global header */ - gqinode = ocfs2_get_system_file_inode(OCFS2_SB(sb), ino[type], + oinfo->dqi_gqinode = ocfs2_get_system_file_inode(OCFS2_SB(sb), ino[type], OCFS2_INVALID_SLOT); - if (!gqinode) { + if (!oinfo->dqi_gqinode) { mlog(ML_ERROR, "failed to get global quota inode (type=%d)\n", type); status = -EINVAL; goto out_err; } - oinfo->dqi_gi.dqi_sb = sb; - oinfo->dqi_gi.dqi_type = type; - oinfo->dqi_gi.dqi_entry_size = sizeof(struct ocfs2_global_disk_dqblk); - oinfo->dqi_gi.dqi_ops = &ocfs2_global_ops; - oinfo->dqi_gqi_bh = NULL; - oinfo->dqi_gqi_count = 0; - oinfo->dqi_gqinode = gqinode; + status = ocfs2_lock_global_qf(oinfo, 0); if (status < 0) { mlog_errno(status); goto out_err; } - status = ocfs2_extent_map_get_blocks(gqinode, 0, &oinfo->dqi_giblk, + status = ocfs2_extent_map_get_blocks(oinfo->dqi_gqinode, 0, &oinfo->dqi_giblk, &pcount, NULL); if (status < 0) goto out_unlock; --- a/fs/ocfs2/quota_local.c +++ b/fs/ocfs2/quota_local.c @@ -702,8 +702,6 @@ static int ocfs2_local_read_info(struct info->dqi_priv = oinfo; oinfo->dqi_type = type; INIT_LIST_HEAD(&oinfo->dqi_chunk); - oinfo->dqi_gqinode = NULL; - ocfs2_qinfo_lock_res_init(&oinfo->dqi_gqlock, oinfo); oinfo->dqi_rec = NULL; oinfo->dqi_lqi_bh = NULL; oinfo->dqi_libh = NULL;