Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4366366pxj; Tue, 8 Jun 2021 12:32:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL9oBTZ/bDI4dTd9H+1P82uzkyMEHDO5jKhjFITJNIpnu+RhxzeHZ4Lji10CZoKwezD6pG X-Received: by 2002:a17:906:4e81:: with SMTP id v1mr24833048eju.125.1623180720133; Tue, 08 Jun 2021 12:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180720; cv=none; d=google.com; s=arc-20160816; b=zbMYgPkPRFhpnKZ0r2WCSaYicFU/OfVASin/AupODRRhrwU3e/32t1AIgPT7beRDt+ CBaIJqHepLtIEt21nXv7dh05SWuF/cl3AbteKOXu+zP0g6dkqMjDQ69QPzwBBIg6xG9j FM8Bbx5AySp0TZqBlpw2ZmIyIrm19LVLmFD/3JDtKuWOcRXZWO+DsPs1zP3TzE1+Kyty GtFyoy7G8tEuNaEss1JZB5fgeO8nBU6mTW/uy/Oj+0m2mHFLlRH9yQfG/Q+Csd7Zj3wU 0HHwzecdc9722r4XzY5ZGGSeBIH7h4QbYAtIs+nQGnFZ15DVAB+LpFM2CEzEx23G2ApO EEsA== 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=OH//CjTCKwKZHkymKnYJXnQdq76mCWsKObXy5MaWzBM=; b=ER5UDqb5uQWns6sbinFzx6RSDBFvbGUC21+88li8pvyG5uUBofA1jBaFrZiNNraAca GerjZI6ZOFvSywVOTVKwLRgRMtkxR5X/0tq0MqGdSA8EEqGWNfvXV65zWQsI/2QAzneQ X8yDIVER+HWDJIab1ePOEi6tPeU0xWUFm2DO09CPaX8pEfNICxFGPDVmmXmWuxMxA5tX kTDQvs8ues1ijJFyDfNlrfBn2hhx5enOjkSuGvFX9Lr3JvgxJEgKg9SbcAVbRIFMhtC3 jjZzECjOTJQJpO2JFjhUOD/MRidhyGG3F6vtkggbUdn+Je1DrXx7DliRg8aEN4//tXtr ResQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tL34VpGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si460291ejl.150.2021.06.08.12.31.35; Tue, 08 Jun 2021 12:32:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tL34VpGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237605AbhFHT2h (ORCPT + 99 others); Tue, 8 Jun 2021 15:28:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:39586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237269AbhFHTPu (ORCPT ); Tue, 8 Jun 2021 15:15:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A07461468; Tue, 8 Jun 2021 18:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178237; bh=wIPv2GZY4Cpx/p3MX5n+ZRapTROsVz1th+wUTzZ2C6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tL34VpGvLFwMmp+eUOQTay03899VEmkQwx70xHHEX5pZ3zYqEc+mK+pjhgG9ggjmJ p6U4eQOw0xy0C/ILl1CZZCxK7S74nmP0SJHDyvgGPpqnfBQ0nF+QqV6oKx3LU7vwBh SaYEvrSQ9M3l1A+d7JGpECOwFCKkq3u/iZiSliRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ritesh Harjani , Harshad Shirwadkar , Theodore Tso Subject: [PATCH 5.12 120/161] ext4: fix accessing uninit percpu counter variable with fast_commit Date: Tue, 8 Jun 2021 20:27:30 +0200 Message-Id: <20210608175949.502316763@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ritesh Harjani commit b45f189a19b38e01676628db79cd3eeb1333516e upstream. When running generic/527 with fast_commit configuration, the following issue is seen on Power. With fast_commit, during ext4_fc_replay() (which can be called from ext4_fill_super()), if inode eviction happens then it can access an uninitialized percpu counter variable. This patch adds the check before accessing the counters in ext4_free_inode() path. [ 321.165371] run fstests generic/527 at 2021-04-29 08:38:43 [ 323.027786] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: block_validity. Quota mode: none. [ 323.618772] BUG: Unable to handle kernel data access on read at 0x1fbd80000 [ 323.619767] Faulting instruction address: 0xc000000000bae78c cpu 0x1: Vector: 300 (Data Access) at [c000000010706ef0] pc: c000000000bae78c: percpu_counter_add_batch+0x3c/0x100 lr: c0000000006d0bb0: ext4_free_inode+0x780/0xb90 pid = 5593, comm = mount ext4_free_inode+0x780/0xb90 ext4_evict_inode+0xa8c/0xc60 evict+0xfc/0x1e0 ext4_fc_replay+0xc50/0x20f0 do_one_pass+0xfe0/0x1350 jbd2_journal_recover+0x184/0x2e0 jbd2_journal_load+0x1c0/0x4a0 ext4_fill_super+0x2458/0x4200 mount_bdev+0x1dc/0x290 ext4_mount+0x28/0x40 legacy_get_tree+0x4c/0xa0 vfs_get_tree+0x4c/0x120 path_mount+0xcf8/0xd70 do_mount+0x80/0xd0 sys_mount+0x3fc/0x490 system_call_exception+0x384/0x3d0 system_call_common+0xec/0x278 Cc: stable@kernel.org Fixes: 8016e29f4362 ("ext4: fast commit recovery path") Signed-off-by: Ritesh Harjani Reviewed-by: Harshad Shirwadkar Link: https://lore.kernel.org/r/6cceb9a75c54bef8fa9696c1b08c8df5ff6169e2.1619692410.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ialloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -322,14 +322,16 @@ void ext4_free_inode(handle_t *handle, s if (is_directory) { count = ext4_used_dirs_count(sb, gdp) - 1; ext4_used_dirs_set(sb, gdp, count); - percpu_counter_dec(&sbi->s_dirs_counter); + if (percpu_counter_initialized(&sbi->s_dirs_counter)) + percpu_counter_dec(&sbi->s_dirs_counter); } ext4_inode_bitmap_csum_set(sb, block_group, gdp, bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8); ext4_group_desc_csum_set(sb, block_group, gdp); ext4_unlock_group(sb, block_group); - percpu_counter_inc(&sbi->s_freeinodes_counter); + if (percpu_counter_initialized(&sbi->s_freeinodes_counter)) + percpu_counter_inc(&sbi->s_freeinodes_counter); if (sbi->s_log_groups_per_flex) { struct flex_groups *fg;