android_kernel_samsung_a7y1.../fs/btrfs
Josef Bacik fd63d8905b btrfs: set trans->drity in btrfs_commit_transaction
commit d62b23c94952e78211a383b7d90ef0afbd9a3717 upstream.

If we abort a transaction we have the following sequence

if (!trans->dirty && list_empty(&trans->new_bgs))
	return;
WRITE_ONCE(trans->transaction->aborted, err);

The idea being if we didn't modify anything with our trans handle then
we don't really need to abort the whole transaction, maybe the other
trans handles are fine and we can carry on.

However in the case of create_snapshot we add a pending_snapshot object
to our transaction and then commit the transaction.  We don't actually
modify anything.  sync() behaves the same way, attach to an existing
transaction and commit it.  This means that if we have an IO error in
the right places we could abort the committing transaction with our
trans->dirty being not set and thus not set transaction->aborted.

This is a problem because in the create_snapshot() case we depend on
pending->error being set to something, or btrfs_commit_transaction
returning an error.

If we are not the trans handle that gets to commit the transaction, and
we're waiting on the commit to happen we get our return value from
cur_trans->aborted.  If this was not set to anything because sync() hit
an error in the transaction commit before it could modify anything then
cur_trans->aborted would be 0.  Thus we'd return 0 from
btrfs_commit_transaction() in create_snapshot.

This is a problem because we then try to do things with
pending_snapshot->snap, which will be NULL because we didn't create the
snapshot, and then we'll get a NULL pointer dereference like the
following

"BUG: kernel NULL pointer dereference, address: 00000000000001f0"
RIP: 0010:btrfs_orphan_cleanup+0x2d/0x330
Call Trace:
 ? btrfs_mksubvol.isra.31+0x3f2/0x510
 btrfs_mksubvol.isra.31+0x4bc/0x510
 ? __sb_start_write+0xfa/0x200
 ? mnt_want_write_file+0x24/0x50
 btrfs_ioctl_snap_create_transid+0x16c/0x1a0
 btrfs_ioctl_snap_create_v2+0x11e/0x1a0
 btrfs_ioctl+0x1534/0x2c10
 ? free_debug_processing+0x262/0x2a3
 do_vfs_ioctl+0xa6/0x6b0
 ? do_sys_open+0x188/0x220
 ? syscall_trace_enter+0x1f8/0x330
 ksys_ioctl+0x60/0x90
 __x64_sys_ioctl+0x16/0x20
 do_syscall_64+0x4a/0x1b0

In order to fix this we need to make sure anybody who calls
commit_transaction has trans->dirty set so that they properly set the
trans->transaction->aborted value properly so any waiters know bad
things happened.

This was found while I was running generic/475 with my modified
fsstress, it reproduced within a few runs.  I ran with this patch all
night and didn't see the problem again.

CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-07 13:50:10 +02:00
..
tests btrfs: return error pointer from alloc_test_extent_buffer 2020-04-07 13:22:00 +02:00
acl.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
async-thread.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
async-thread.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
backref.c Btrfs: do not start a transaction at iterate_extent_inodes() 2020-04-06 18:12:40 +02:00
backref.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
btrfs_inode.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
check-integrity.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
check-integrity.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
compression.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
compression.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ctree.c Btrfs: fix removal logic of the tree mod log that leads to use-after-free issues 2020-04-07 13:22:03 +02:00
ctree.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
delayed-inode.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
delayed-inode.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
delayed-ref.c btrfs: only track ref_heads in delayed_ref_updates 2020-04-07 12:41:41 +02:00
delayed-ref.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
dev-replace.c btrfs: Ensure replaced device doesn't have pending chunk allocation 2020-04-06 19:21:08 +02:00
dev-replace.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
dir-item.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
disk-io.c btrfs: don't prematurely free work in end_workqueue_fn() 2020-04-07 13:21:41 +02:00
disk-io.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
export.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
export.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
extent_io.c btrfs: return error pointer from alloc_test_extent_buffer 2020-04-07 13:22:00 +02:00
extent_io.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
extent_map.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
extent_map.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
extent-tree.c btrfs: block-group: Fix a memory leak due to missing btrfs_put_block_group() 2020-04-07 09:27:00 +02:00
extent-tree.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
file-item.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
file.c Btrfs: fix negative subv_writers counter and data space leak after buffered write 2020-04-07 13:07:47 +02:00
free-space-cache.c btrfs: check page->mapping when loading free space cache 2020-04-07 13:06:51 +02:00
free-space-cache.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
hash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
hash.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
inode-item.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
inode-map.c Btrfs: fix hang when loading existing inode cache off disk 2020-04-07 13:43:17 +02:00
inode-map.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
inode.c btrfs: do not call synchronize_srcu() in inode_tree_del 2020-04-07 13:21:58 +02:00
ioctl.c btrfs: abort transaction after failed inode updates in create_subvol 2020-04-07 13:22:02 +02:00
Kconfig A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
locking.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
locking.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lzo.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Makefile A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
math.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ordered-data.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ordered-data.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
orphan.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
print-tree.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
print-tree.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
props.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
props.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
qgroup.c Btrfs: fix race setting up and completing qgroup rescan workers 2020-04-07 07:41:26 +02:00
qgroup.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
raid56.c btrfs: raid56: properly unmap parity page in finish_parity_scrub() 2020-04-06 12:57:22 +02:00
raid56.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rcu-string.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
reada.c btrfs: start readahead also in seed devices 2020-04-06 19:16:44 +02:00
relocation.c btrfs: do not leak reloc root if we fail to read the fs root 2020-04-07 13:19:14 +02:00
root-tree.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
scrub.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
send.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
send.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
struct-funcs.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
super.c btrfs: do not zero f_bavail if we have available space 2020-04-07 13:49:09 +02:00
sysfs.c btrfs: sysfs: don't leak memory when failing add fsid 2020-04-06 18:15:08 +02:00
sysfs.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
transaction.c btrfs: set trans->drity in btrfs_commit_transaction 2020-04-07 13:50:10 +02:00
transaction.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tree-checker.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tree-checker.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tree-defrag.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tree-log.c Btrfs: fix assertion failure during fsync and use of stale transaction 2020-04-06 21:35:33 +02:00
tree-log.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ulist.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ulist.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
uuid-tree.c btrfs: handle ENOENT in btrfs_uuid_tree_iterate 2020-04-07 13:19:56 +02:00
volumes.c btrfs: fix minimum number of chunk errors for DUP 2020-04-06 20:26:57 +02:00
volumes.h btrfs: Remove btrfs_bio::flags member 2020-04-07 13:06:53 +02:00
xattr.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
xattr.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
zlib.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30