Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2027244pxa; Mon, 3 Aug 2020 05:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkD/Tkl0q3d1N5HYUojemcDJvZdTyEKPqhrpzxF94cWy+/leRdmkSK9iI3LRPtVYWXGlTm X-Received: by 2002:a05:6402:60e:: with SMTP id n14mr15599681edv.29.1596458736316; Mon, 03 Aug 2020 05:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458736; cv=none; d=google.com; s=arc-20160816; b=yxs2Q1w2pEStUW7kyCngbn5fiOM9c0cdczCVanmGo5fN9vHkUp439ZynyB0q4gjkrR TdCFaFB5Ehfznxq4mFapPIawByCGEEejVlXenEDjQceN2AG4B/ku4UwkJKFKdM39tCHk /hzQQjQXB79rHlv/vOdYV8Mz8N92EiUBreTRuzKFEkAE54tIihE9kPdJ3adb4x9b04AI tVoY+Pe5IJHOZXDbdWMViUkEO1n46ZzuZmwLoArM40UA8YP5dkKW7a93YnknpFrmrbXU DHkrhUUHM4QB1iwNxcKP5XUW7pjiBUvMszG3XjACQ5LJZz6+/WtXE+6W3t8x2TAjKrxA vC9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wlhFaY0fIdPdZnIKLIrBUAMo0eaFfERVFC3qLLjaosc=; b=gESiFtJUg0Iv8+Ke9HOeOtt7J2Z7NumRqXdZMEI+zodwCNAToEhpyNkWD5WjL1g8aD 0uFOZz0Ak86aXLXsENwtVF8PT4+1Rwrs4qvqSE6qm2+7WDYbZ2KQTGKlNjJysSNe0z+2 1ruJOJObxQ9mQzf72p2FewI2uYA8V1ke+Ks3T1b4TKm1XmwpEJWxG1ETW6G5qgFfRqql NqQPC9l9+Po52whck0VIJT+8dWWX7jCS9B9p6Kf9xRmYGLyaK4DouMPi5U/aJ40YY6Op qRj6yXO2Vm8RMXQSZhHDqIpMNPutYpoXkoJLS4S4gl5VnaCAfE8vg3+kHwxtCjOOFD3w H8oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hKBZgNKG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si10051126edr.516.2020.08.03.05.45.12; Mon, 03 Aug 2020 05:45:36 -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=@kernel.org header.s=default header.b=hKBZgNKG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728620AbgHCMmd (ORCPT + 99 others); Mon, 3 Aug 2020 08:42:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:58472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728601AbgHCMbH (ORCPT ); Mon, 3 Aug 2020 08:31:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE8E42054F; Mon, 3 Aug 2020 12:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457866; bh=KPEQdRBWpj2++NzmpX3wevXP1Ga9IyqWe51CLg9gI0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKBZgNKGVGU/8ZE+cSZN+jN5SsWSL5IvZd5r54pUV0Gm2ehFldtzyBIEJlTVY4Ud7 Aej7EK8rvFev7868wOT/eiCfEAclAIfPQGVQRU93Cw4lxtxHL8YHVPJ27G60H+lhf6 /SurIz2l4ARWV2yL9nPfXjdpElFX+Jyfq/brFOrc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 4.19 11/56] Btrfs: fix selftests failure due to uninitialized i_mode in test inodes Date: Mon, 3 Aug 2020 14:19:26 +0200 Message-Id: <20200803121850.868864740@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana [ Upstream commit 9f7fec0ba89108b9385f1b9fb167861224912a4a ] Some of the self tests create a test inode, setup some extents and then do calls to btrfs_get_extent() to test that the corresponding extent maps exist and are correct. However btrfs_get_extent(), since the 5.2 merge window, now errors out when it finds a regular or prealloc extent for an inode that does not correspond to a regular file (its ->i_mode is not S_IFREG). This causes the self tests to fail sometimes, specially when KASAN, slub_debug and page poisoning are enabled: $ modprobe btrfs modprobe: ERROR: could not insert 'btrfs': Invalid argument $ dmesg [ 9414.691648] Btrfs loaded, crc32c=crc32c-intel, debug=on, assert=on, integrity-checker=on, ref-verify=on [ 9414.692655] BTRFS: selftest: sectorsize: 4096 nodesize: 4096 [ 9414.692658] BTRFS: selftest: running btrfs free space cache tests [ 9414.692918] BTRFS: selftest: running extent only tests [ 9414.693061] BTRFS: selftest: running bitmap only tests [ 9414.693366] BTRFS: selftest: running bitmap and extent tests [ 9414.696455] BTRFS: selftest: running space stealing from bitmap to extent tests [ 9414.697131] BTRFS: selftest: running extent buffer operation tests [ 9414.697133] BTRFS: selftest: running btrfs_split_item tests [ 9414.697564] BTRFS: selftest: running extent I/O tests [ 9414.697583] BTRFS: selftest: running find delalloc tests [ 9415.081125] BTRFS: selftest: running find_first_clear_extent_bit test [ 9415.081278] BTRFS: selftest: running extent buffer bitmap tests [ 9415.124192] BTRFS: selftest: running inode tests [ 9415.124195] BTRFS: selftest: running btrfs_get_extent tests [ 9415.127909] BTRFS: selftest: running hole first btrfs_get_extent test [ 9415.128343] BTRFS critical (device (efault)): regular/prealloc extent found for non-regular inode 256 [ 9415.131428] BTRFS: selftest: fs/btrfs/tests/inode-tests.c:904 expected a real extent, got 0 This happens because the test inodes are created without ever initializing the i_mode field of the inode, and neither VFS's new_inode() nor the btrfs callback btrfs_alloc_inode() initialize the i_mode. Initialization of the i_mode is done through the various callbacks used by the VFS to create new inodes (regular files, directories, symlinks, tmpfiles, etc), which all call btrfs_new_inode() which in turn calls inode_init_owner(), which sets the inode's i_mode. Since the tests only uses new_inode() to create the test inodes, the i_mode was never initialized. This always happens on a VM I used with kasan, slub_debug and many other debug facilities enabled. It also happened to someone who reported this on bugzilla (on a 5.3-rc). Fix this by setting i_mode to S_IFREG at btrfs_new_test_inode(). Fixes: 6bf9e4bd6a2778 ("btrfs: inode: Verify inode mode to avoid NULL pointer dereference") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204397 Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/tests/btrfs-tests.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index 2eec1dd3803af..82d874b104383 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -38,7 +38,13 @@ static struct file_system_type test_type = { struct inode *btrfs_new_test_inode(void) { - return new_inode(test_mnt->mnt_sb); + struct inode *inode; + + inode = new_inode(test_mnt->mnt_sb); + if (inode) + inode_init_owner(inode, NULL, S_IFREG); + + return inode; } static int btrfs_init_test_fs(void) -- 2.25.1