From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Gong, Sishuai" <sishuai@purdue.edu>
Cc: "tytso@mit.edu" <tytso@mit.edu>,
"adilger.kernel@dilger.ca" <adilger.kernel@dilger.ca>,
"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
"adilger@dilger.ca" <adilger@dilger.ca>
Subject: Re: PROBLEM: another potential concurrency bug in swap_inode_boot_loader()
Date: Tue, 8 Sep 2020 19:44:50 -0700 [thread overview]
Message-ID: <20200909024450.GA7948@magnolia> (raw)
In-Reply-To: <CBFCE964-34D6-47ED-BB71-E8975C16F808@purdue.edu>
On Wed, Sep 09, 2020 at 12:28:36AM +0000, Gong, Sishuai wrote:
> Hi,
>
> We found a potential concurrency bug in linux kernel 5.3.11. We were able to reproduce this bug in x86 under specific thread interleavings. This bug causes a “bad header/extent” EXT4-fs error.
>
> In addition, we think this bug may be related to another bug we reported earlier. Similar to a concern mentioned in your reply, this time the inode had a correct checksum but a wrong header data.
>
> https://lore.kernel.org/linux-ext4/459EE6E3-1CB2-4898-8C5F-283E821B2A75@dilger.ca/T/#t
>
>
> ------------------------------------------
> Kernel console output
>
> EXT4-fs error (device sda1): ext4_ext_check_inode:498: inode #5: comm ski-executor: pblk 0 bad header/extent: invalid magic - magic 0, entries 0, max 0(0), depth 0(0)
>
> ------------------------------------------
> Test input
>
> This bug occurs when a kernel test program is executed twice in different threads and ran concurrently. Our analysis has located that it happens when syscall ioctl with the EXT4_IOC_SWAP_BOOT flag is called twice and interleaves with itself.
> The test program is generated by Syzkaller as follows:
> r0 = creat(&(0x7f0000000080)='./file0\x00', 0x0)
> ioctl$FS_IOC_SETFLAGS(r0, 0x40046602, &(0x7f0000000040))
> r1 = creat(&(0x7f0000000000)='./file0\x00', 0x0)
> pwrite64(r1, &(0x7f00000000c0)='\x00', 0x1, 0x1010000)
> r2 = creat(&(0x7f0000000000)='./file0\x00', 0x0)
> ioctl$EXT4_IOC_SWAP_BOOT(r2, 0x6611)
>
> ------------------------------------------
> Thread interleaving
>
> Our analysis revealed that the following interleaving triggers this bug.
>
> CPU0 CPU1
> swap_inode_boot_loader()
> …
> -- ext4_mark_inode_dirty() [fs/ext4/ioctl.c:207]
> [context switch]
> swap_inode_boot_loader()
> -- ext4_iget()
> ---- ext4_isize()
> [context switch]
How do you end up in this state? CPU0 has already ext4_iget()'d a
reference to the bootloader inode, right? Which means that I_NEW is no
longer set on the incore inode, right, because we clear that flag when
we unlock the inode.i_lock at the end of the iget function. So
shouldn't CPU1's call to ext4_iget to get the same bootloader inode end
up with the same incore inode? And won't I_NEW be clear by then?
--D
> …
> -- ext4_mark_inode_dirty() [fs/ext4/ioctl.c:223]
> ---- ext4_mark_iloc_dirty()
> ------ ext4_do_update_inode()
> for (block = 0; block < EXT4_N_BLOCKS; block++) [fs/ext4/inode.c:5337]
> raw_inode->i_block[block] = ei->i_data[block];
> …
> [syscall finishes]
> [context switch]
> …
> for (block = 0; block < EXT4_N_BLOCKS; block++) [fs/ext4/inode.c:5002]
> ei->i_data[block] = raw_inode->i_block[block];
> …
> ---- ext4_ext_check_inode(inode)
> [EXT4-fs error]
>
>
> Thanks,
> Sishuai
>
prev parent reply other threads:[~2020-09-09 2:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 0:28 PROBLEM: another potential concurrency bug in swap_inode_boot_loader() Gong, Sishuai
2020-09-09 2:44 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200909024450.GA7948@magnolia \
--to=darrick.wong@oracle.com \
--cc=adilger.kernel@dilger.ca \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=sishuai@purdue.edu \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).