TencentOS-kernel/fs
Filipe Manana f06de9b75c btrfs: fix warning when creating a directory with smack enabled
commit fd57a98d6f0c98fa295813087f13afb26c224e73 upstream.

When we have smack enabled, during the creation of a directory smack may
attempt to add a "smack transmute" xattr on the inode, which results in
the following warning and trace:

  WARNING: CPU: 3 PID: 2548 at fs/btrfs/transaction.c:537 start_transaction+0x489/0x4f0
  Modules linked in: nft_objref nf_conntrack_netbios_ns (...)
  CPU: 3 PID: 2548 Comm: mkdir Not tainted 5.9.0-rc2smack+ #81
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
  RIP: 0010:start_transaction+0x489/0x4f0
  Code: e9 be fc ff ff (...)
  RSP: 0018:ffffc90001887d10 EFLAGS: 00010202
  RAX: ffff88816f1e0000 RBX: 0000000000000201 RCX: 0000000000000003
  RDX: 0000000000000201 RSI: 0000000000000002 RDI: ffff888177849000
  RBP: ffff888177849000 R08: 0000000000000001 R09: 0000000000000004
  R10: ffffffff825e8f7a R11: 0000000000000003 R12: ffffffffffffffe2
  R13: 0000000000000000 R14: ffff88803d884270 R15: ffff8881680d8000
  FS:  00007f67317b8440(0000) GS:ffff88817bcc0000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 00007f67247a22a8 CR3: 000000004bfbc002 CR4: 0000000000370ee0
  DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
  Call Trace:
   ? slab_free_freelist_hook+0xea/0x1b0
   ? trace_hardirqs_on+0x1c/0xe0
   btrfs_setxattr_trans+0x3c/0xf0
   __vfs_setxattr+0x63/0x80
   smack_d_instantiate+0x2d3/0x360
   security_d_instantiate+0x29/0x40
   d_instantiate_new+0x38/0x90
   btrfs_mkdir+0x1cf/0x1e0
   vfs_mkdir+0x14f/0x200
   do_mkdirat+0x6d/0x110
   do_syscall_64+0x2d/0x40
   entry_SYSCALL_64_after_hwframe+0x44/0xa9
  RIP: 0033:0x7f673196ae6b
  Code: 8b 05 11 (...)
  RSP: 002b:00007ffc3c679b18 EFLAGS: 00000246 ORIG_RAX: 0000000000000053
  RAX: ffffffffffffffda RBX: 00000000000001ff RCX: 00007f673196ae6b
  RDX: 0000000000000000 RSI: 00000000000001ff RDI: 00007ffc3c67a30d
  RBP: 00007ffc3c67a30d R08: 00000000000001ff R09: 0000000000000000
  R10: 000055d3e39fe930 R11: 0000000000000246 R12: 0000000000000000
  R13: 00007ffc3c679cd8 R14: 00007ffc3c67a30d R15: 00007ffc3c679ce0
  irq event stamp: 11029
  hardirqs last  enabled at (11037): [<ffffffff81153fe6>] console_unlock+0x486/0x670
  hardirqs last disabled at (11044): [<ffffffff81153c01>] console_unlock+0xa1/0x670
  softirqs last  enabled at (8864): [<ffffffff81e0102f>] asm_call_on_stack+0xf/0x20
  softirqs last disabled at (8851): [<ffffffff81e0102f>] asm_call_on_stack+0xf/0x20

This happens because at btrfs_mkdir() we call d_instantiate_new() while
holding a transaction handle, which results in the following call chain:

  btrfs_mkdir()
     trans = btrfs_start_transaction(root, 5);

     d_instantiate_new()
        smack_d_instantiate()
            __vfs_setxattr()
                btrfs_setxattr_trans()
                   btrfs_start_transaction()
                      start_transaction()
                         WARN_ON()
                           --> a tansaction start has TRANS_EXTWRITERS
                               set in its type
                         h->orig_rsv = h->block_rsv
                         h->block_rsv = NULL

     btrfs_end_transaction(trans)

Besides the warning triggered at start_transaction, we set the handle's
block_rsv to NULL which may cause some surprises later on.

So fix this by making btrfs_setxattr_trans() not start a transaction when
we already have a handle on one, stored in current->journal_info, and use
that handle. We are good to use the handle because at btrfs_mkdir() we did
reserve space for the xattr and the inode item.

Reported-by: Casey Schaufler <casey@schaufler-ca.com>
CC: stable@vger.kernel.org # 5.4+
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Tested-by: Casey Schaufler <casey@schaufler-ca.com>
Link: https://lore.kernel.org/linux-btrfs/434d856f-bd7b-4889-a6ec-e81aaebfa735@schaufler-ca.com/
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-12 12:52:51 +08:00
..
9p 9P: Cast to loff_t before multiplying 2021-03-16 16:40:11 +08:00
adfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
affs fs/affs: release old buffer head on error path 2021-04-12 12:52:38 +08:00
afs rxrpc: Fix deadlock around release of dst cached on udp tunnel 2021-04-12 12:51:53 +08:00
autofs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
befs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
bfs bfs: don't use WARNING: string when it's just info. 2021-03-16 16:43:53 +08:00
btrfs btrfs: fix warning when creating a directory with smack enabled 2021-04-12 12:52:51 +08:00
cachefiles cachefiles: Handle readpage error correctly 2021-03-16 16:40:14 +08:00
ceph ceph: fix race in concurrent __ceph_remove_cap invocations 2021-03-16 16:43:35 +08:00
cifs cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath. 2021-04-12 12:52:09 +08:00
coda Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
configfs configfs: fix config_item refcnt leak in configfs_rmdir() 2021-03-16 16:28:09 +08:00
cramfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
crypto fscrypt: remove kernel-internal constants from UAPI header 2021-03-16 16:43:49 +08:00
debugfs debugfs: do not attempt to create a new file before the filesystem is initalized 2021-04-12 12:52:10 +08:00
devpts Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
dlm fs: dlm: fix configfs memory leak 2021-03-16 16:39:15 +08:00
ecryptfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
efivarfs efivarfs: revert "fix memory leak in efivarfs_create()" 2021-03-16 16:41:45 +08:00
efs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
erofs erofs: fix shift-out-of-bounds of blkszbits 2021-04-12 12:52:44 +08:00
exportfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
ext2 ext2: don't update mtime on COW faults 2021-03-16 16:35:36 +08:00
ext4 ext4: fix potential htree index checksum corruption 2021-04-12 12:52:30 +08:00
f2fs f2fs: fix to set/clear I_LINKABLE under i_lock 2021-04-12 12:52:48 +08:00
fat fat: don't allow to mount if the FAT length == 0 2021-03-16 16:29:12 +08:00
freevxfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fscache Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fuse fuse: fix bad inode 2021-04-12 12:51:05 +08:00
gfs2 gfs2: Recursive gfs2_quota_hold in gfs2_iomap_end 2021-04-12 12:52:40 +08:00
hfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
hfsplus hfsplus: fix crash and filesystem corruption when deleting files 2021-03-16 16:26:16 +08:00
hostfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
hpfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
hugetlbfs mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page 2021-04-12 12:51:56 +08:00
iomap iomap: fix WARN_ON_ONCE() from unprivileged users 2021-03-16 16:39:20 +08:00
isofs isofs: release buffer head before return 2021-04-12 12:52:25 +08:00
jbd2 jbd2: fix up sparse warnings in checkpoint code 2021-03-16 16:40:54 +08:00
jffs2 jffs2: fix use after free in jffs2_sum_write_data() 2021-04-12 12:52:22 +08:00
jfs JFS: more checks for invalid superblock 2021-04-12 12:52:43 +08:00
kernfs kernfs: do not call fsnotify() with name without a parent 2021-03-16 16:33:35 +08:00
lockd lockd: don't use interval-based rebinding over TCP 2021-03-16 16:42:59 +08:00
minix fs/minix: remove expected error message in block_to_path() 2021-03-16 16:34:21 +08:00
nfs pNFS/NFSv4: Try to return invalid layout in pnfs_layout_process() 2021-04-12 12:51:59 +08:00
nfs_common nfs_common: need lock during iterate through the list 2021-03-16 16:43:09 +08:00
nfsd nfsd: register pernet ops last, unregister first 2021-04-12 12:52:28 +08:00
nilfs2 nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() 2021-03-16 16:29:04 +08:00
nls Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
notify fanotify: fix ignore mask logic for events on child and on dir 2021-03-16 16:28:58 +08:00
ntfs ntfs: check for valid standard information attribute 2021-04-12 12:52:08 +08:00
ocfs2 ocfs2: fix a use after free on error 2021-04-12 12:52:31 +08:00
omfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
openpromfs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
orangefs orangefs: get rid of knob code... 2021-03-16 16:34:10 +08:00
overlayfs ovl: expand warning in ovl_d_real() 2021-04-12 12:52:06 +08:00
proc proc: fix lookup in /proc/net subdirectories after setns(2) 2021-04-12 12:51:06 +08:00
pstore pstore: Fix typo in compression option name 2021-04-12 12:52:36 +08:00
qnx4 Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
qnx6 Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
quota quota: Fix memory leak when handling corrupted quota file 2021-04-12 12:52:22 +08:00
ramfs ramfs: fix nommu mmap with gaps in the page cache 2021-03-16 16:38:58 +08:00
reiserfs reiserfs: add check for an invalid ih_entry_count 2021-03-16 16:43:52 +08:00
romfs romfs: fix uninitialized memory leak in romfs_dev_read() 2021-03-16 16:34:28 +08:00
squashfs squashfs: add more sanity checks in xattr id lookup 2021-04-12 12:52:00 +08:00
sysfs sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output 2021-04-12 12:52:49 +08:00
sysv Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
tracefs Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
ubifs ubifs: Fix error return code in alloc_wbufs() 2021-04-12 12:52:22 +08:00
udf udf: fix the problem that the disc content is not displayed 2021-04-12 12:51:51 +08:00
ufs fs/ufs: avoid potential u32 multiplication overflow 2021-03-16 16:34:21 +08:00
unicode Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
verity Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
xfs xfs: Fix assert failure in xfs_setattr_size() 2021-04-12 12:52:44 +08:00
Kconfig Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Kconfig.binfmt Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Makefile Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
aio.c aio: fix async fsync creds 2021-03-16 16:28:58 +08:00
anon_inodes.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
attr.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
bad_inode.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
binfmt_aout.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
binfmt_elf.c fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() 2021-03-16 16:28:37 +08:00
binfmt_elf_fdpic.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
binfmt_em86.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
binfmt_flat.c binfmt_flat: revert "binfmt_flat: don't offset the data start" 2021-03-16 16:34:43 +08:00
binfmt_misc.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
binfmt_script.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
block_dev.c bdev: Reduce time holding bd_mutex in sync in blkdev_close() 2021-03-16 16:37:13 +08:00
buffer.c fs: Don't invalidate page buffers in block_write_full_page() 2021-03-16 16:39:56 +08:00
char_dev.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
compat.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
compat_binfmt_elf.c BACKPORT: Split the old READ_IMPLIES_EXEC workaround from executable 2021-03-16 16:43:59 +08:00
compat_ioctl.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
coredump.c coredump: fix core_pattern parse error 2021-03-16 16:42:04 +08:00
d_path.c fs: fix NULL dereference due to data race in prepend_path() 2021-03-16 16:38:47 +08:00
dax.c mm: provide a saner PTE walking API for modules 2021-04-12 12:52:09 +08:00
dcache.c fix dget_parent() fastpath race 2021-03-16 16:36:39 +08:00
dcookies.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
direct-io.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
drop_caches.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
eventfd.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
eventpoll.c ep_create_wakeup_source(): dentry name can change under you... 2021-03-16 16:37:52 +08:00
exec.c exec: Transform exec_update_mutex into a rw_semaphore 2021-04-12 12:51:05 +08:00
fcntl.c fcntl: Fix potential deadlock in send_sig{io, urg}() 2021-03-16 16:43:54 +08:00
fhandle.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
file.c fix multiplication overflow in copy_fdtable() 2021-03-16 16:28:07 +08:00
file_table.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
filesystems.c fs/filesystems.c: downgrade user-reachable WARN_ONCE() to pr_warn_once() 2021-03-16 16:26:14 +08:00
fs-writeback.c fs: fix lazytime expiration handling in __writeback_single_inode() 2021-04-12 12:51:42 +08:00
fs_context.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fs_parser.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fs_pin.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fs_struct.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fs_types.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
fsopen.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
inode.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
internal.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
io_uring.c io_uring: Fix current->fs handling in io_sq_wq_submit_work() 2021-04-12 12:51:41 +08:00
ioctl.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
libfs.c libfs: fix error cast of negative value in simple_attr_write() 2021-03-16 16:41:24 +08:00
locks.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
mbcache.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
mount.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
mpage.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
namei.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
namespace.c fs/namespace.c: WARN if mnt_count has become negative 2021-03-16 16:43:56 +08:00
no-block.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
nsfs.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
open.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
pipe.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
pnode.c propagate_one(): mnt_set_mountpoint() needs mount_lock 2021-03-16 16:27:06 +08:00
pnode.h fs/namespace.c: WARN if mnt_count has become negative 2021-03-16 16:43:56 +08:00
posix_acl.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
proc_namespace.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
read_write.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
readdir.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
select.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
seq_file.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
signalfd.c fs/signalfd.c: fix inconsistent return codes for signalfd4 2021-03-16 16:34:34 +08:00
splice.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
stack.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
stat.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
statfs.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
super.c vfs: remove lockdep bogosity in __sb_start_write 2021-03-16 16:41:11 +08:00
sync.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
timerfd.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
userfaultfd.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
utimes.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
xattr.c xattr: break delegations in {set,remove}xattr 2021-03-16 16:33:08 +08:00