Skip to content
Snippets Groups Projects
  1. Jul 19, 2021
  2. Jul 18, 2021
  3. Jul 16, 2021
  4. Jul 14, 2021
    • Theodore Ts'o's avatar
      ext4: fix possible UAF when remounting r/o a mmp-protected file system · 7d7d26aa
      Theodore Ts'o authored
      mainline inclusion
      from mainline-5.14
      commit	61bb4a1c417e5b95d9edb4f887f131de32e419cb
      category: bugfix
      bugzilla: 173880
      CVE: NA
      
      -------------------------------------------------
      
      After commit 618f003199c6 ("ext4: fix memory leak in
      ext4_fill_super"), after the file system is remounted read-only, there
      is a race where the kmmpd thread can exit, causing sbi->s_mmp_tsk to
      point at freed memory, which the call to ext4_stop_mmpd() can trip
      over.
      
      Fix this by only allowing kmmpd() to exit when it is stopped via
      ext4_stop_mmpd().
      
      Link: https://lore.kernel.org/r/20210707002433.3719773-1-tytso@mit.edu
      
      
      Reported-by: default avatarYe Bin <yebin10@huawei.com>
      Bug-Report-Link: <20210629143603.2166962-1-yebin10@huawei.com>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      
      Conflicts:
      	fs/ext4/super.c
      
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      7d7d26aa
    • Luo Meng's avatar
      locks: Fix UBSAN undefined behaviour in flock64_to_posix_lock · 1b84bd6f
      Luo Meng authored
      mainline inclusion
      from mainline-v5.11-rc1
      commit 16238415eb9886328a89fe7a3cb0b88c7335fe16
      category: bugfix
      bugzilla: 38689
      CVE: NA
      
      -----------------------------------------------
      
      When the sum of fl->fl_start and l->l_len overflows,
      UBSAN shows the following warning:
      
      UBSAN: Undefined behaviour in fs/locks.c:482:29
      signed integer overflow: 2 + 9223372036854775806
      cannot be represented in type 'long long int'
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0xe4/0x14e lib/dump_stack.c:118
       ubsan_epilogue+0xe/0x81 lib/ubsan.c:161
       handle_overflow+0x193/0x1e2 lib/ubsan.c:192
       flock64_to_posix_lock fs/locks.c:482 [inline]
       flock_to_posix_lock+0x595/0x690 fs/locks.c:515
       fcntl_setlk+0xf3/0xa90 fs/locks.c:2262
       do_fcntl+0x456/0xf60 fs/fcntl.c:387
       __do_sys_fcntl fs/fcntl.c:483 [inline]
       __se_sys_fcntl fs/fcntl.c:468 [inline]
       __x64_sys_fcntl+0x12d/0x180 fs/fcntl.c:468
       do_syscall_64+0xc8/0x5a0 arch/x86/entry/common.c:293
       entry_SY...
      1b84bd6f
    • Matthew Wilcox (Oracle)'s avatar
      iomap: Mark read blocks uptodate in write_begin · a259beb0
      Matthew Wilcox (Oracle) authored
      
      mainline inclusion
      from mainline-v5.10
      commit 14284fed
      category: bugfix
      bugzilla: 43547
      CVE: NA
      
      -----------------------------------------------
      
      When bringing (portions of) a page uptodate, we were marking blocks that
      were zeroed as being uptodate, but not blocks that were read from storage.
      
      Like the previous commit, this problem was found with generic/127 and
      a kernel which failed readahead I/Os.  This bug causes writes to be
      silently lost when working with flaky storage.
      
      Fixes: 9dc55f13 ("iomap: add support for sub-pagesize buffered I/O without buffer heads")
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      
      conflicts:
      fs/iomap.c
      
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      a259beb0
    • Matthew Wilcox (Oracle)'s avatar
      iomap: Clear page error before beginning a write · b3a0aab5
      Matthew Wilcox (Oracle) authored
      
      mainline inclusion
      from mainline-v5.10-rc1
      commit e6e7ca92
      category: bugfix
      bugzilla: 43551
      CVE: NA
      
      -----------------------------------------------
      
      If we find a page in write_begin which is !Uptodate, we need
      to clear any error on the page before starting to read data
      into it.  This matches how filemap_fault(), do_read_cache_page()
      and generic_file_buffered_read() handle PageError on !Uptodate pages.
      When calling iomap_set_range_uptodate() in __iomap_write_begin(), blocks
      were not being marked as uptodate.
      
      This was found with generic/127 and a specially modified kernel which
      would fail (some) readahead I/Os.  The test read some bytes in a prior
      page which caused readahead to extend into page 0x34.  There was
      a subsequent write to page 0x34, followed by a read to page 0x34.
      Because the blocks were still marked as !Uptodate, the read caused all
      blocks to be re-read, overwriting the write.  With this change, and the
      next one, the bytes which were written are marked as being Uptodate, so
      even though the page is still marked as !Uptodate, the blocks containing
      the written data are not re-read from storage.
      
      Fixes: 9dc55f13 ("iomap: add support for sub-pagesize buffered I/O without buffer heads")
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      
      conflicts:
      fs/iomap.c
      
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      b3a0aab5
    • Christoph Hellwig's avatar
      iomap: move the zeroing case out of iomap_read_page_sync · 9fdbab15
      Christoph Hellwig authored
      
      mainline inclusion
      from mainline-v5.5-rc1
      commit d3b40439
      category: bugfix
      bugzilla: 43551
      CVE: NA
      
      -----------------------------------------------
      
      That keeps the function a little easier to understand, and easier to
      modify for pending enhancements.
      
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      
      conflicts:
      fs/iomap.c
      
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      9fdbab15
    • Josef Bacik's avatar
      nbd: handle device refs for DESTROY_ON_DISCONNECT properly · c72b1648
      Josef Bacik authored
      
      mainline inclusion
      from mainline-5.12-rc1
      commit c9a2f90f4d6b
      category: bugfix
      bugzilla: 50455
      CVE: NA
      
      -------------------------------------------------
      
      There exists a race where we can be attempting to create a new nbd
      configuration while a previous configuration is going down, both
      configured with DESTROY_ON_DISCONNECT.  Normally devices all have a
      reference of 1, as they won't be cleaned up until the module is torn
      down.  However with DESTROY_ON_DISCONNECT we'll make sure that there is
      only 1 reference (generally) on the device for the config itself, and
      then once the config is dropped, the device is torn down.
      
      The race that exists looks like this
      
      TASK1					TASK2
      nbd_genl_connect()
        idr_find()
          refcount_inc_not_zero(nbd)
            * count is 2 here ^^
      					nbd_config_put()
      					  nbd_put(nbd) (count is 1)
          setup new config
            check DESTROY_ON_DISCONNECT
      	put_dev = true
          if (put_dev) nbd_put(nbd)
      	* free'd here ^^
      
      In nbd_genl_connect() we assume that the nbd ref count will be 2,
      however clearly that won't be true if the nbd device had been setup as
      DESTROY_ON_DISCONNECT with its prior configuration.  Fix this by getting
      rid of the runtime flag to check if we need to mess with the nbd device
      refcount, and use the device NBD_DESTROY_ON_DISCONNECT flag to check if
      we need to adjust the ref counts.  This was reported by syzkaller with
      the following kasan dump
      
      BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrumented.h:71 [inline]
      BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
      BUG: KASAN: use-after-free in refcount_dec_not_one+0x71/0x1e0 lib/refcount.c:76
      Read of size 4 at addr ffff888143bf71a0 by task systemd-udevd/8451
      
      CPU: 0 PID: 8451 Comm: systemd-udevd Not tainted 5.11.0-rc7-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       __dump_stack lib/dump_stack.c:79 [inline]
       dump_stack+0x107/0x163 lib/dump_stack.c:120
       print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:230
       __kasan_report mm/kasan/report.c:396 [inline]
       kasan_report.cold+0x79/0xd5 mm/kasan/report.c:413
       check_memory_region_inline mm/kasan/generic.c:179 [inline]
       check_memory_region+0x13d/0x180 mm/kasan/generic.c:185
       instrument_atomic_read include/linux/instrumented.h:71 [inline]
       atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
       refcount_dec_not_one+0x71/0x1e0 lib/refcount.c:76
       refcount_dec_and_mutex_lock+0x19/0x140 lib/refcount.c:115
       nbd_put drivers/block/nbd.c:248 [inline]
       nbd_release+0x116/0x190 drivers/block/nbd.c:1508
       __blkdev_put+0x548/0x800 fs/block_dev.c:1579
       blkdev_put+0x92/0x570 fs/block_dev.c:1632
       blkdev_close+0x8c/0xb0 fs/block_dev.c:1640
       __fput+0x283/0x920 fs/file_table.c:280
       task_work_run+0xdd/0x190 kernel/task_work.c:140
       tracehook_notify_resume include/linux/tracehook.h:189 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
       exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:201
       __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
       syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x7fc1e92b5270
      Code: 73 01 c3 48 8b 0d 38 7d 20 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 59 c1 20 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 ee fb ff ff 48 89 04 24
      RSP: 002b:00007ffe8beb2d18 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
      RAX: 0000000000000000 RBX: 0000000000000007 RCX: 00007fc1e92b5270
      RDX: 000000000aba9500 RSI: 0000000000000000 RDI: 0000000000000007
      RBP: 00007fc1ea16f710 R08: 000000000000004a R09: 0000000000000008
      R10: 0000562f8cb0b2a8 R11: 0000000000000246 R12: 0000000000000000
      R13: 0000562f8cb0afd0 R14: 0000000000000003 R15: 000000000000000e
      
      Allocated by task 1:
       kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
       kasan_set_track mm/kasan/common.c:46 [inline]
       set_alloc_info mm/kasan/common.c:401 [inline]
       ____kasan_kmalloc.constprop.0+0x82/0xa0 mm/kasan/common.c:429
       kmalloc include/linux/slab.h:552 [inline]
       kzalloc include/linux/slab.h:682 [inline]
       nbd_dev_add+0x44/0x8e0 drivers/block/nbd.c:1673
       nbd_init+0x250/0x271 drivers/block/nbd.c:2394
       do_one_initcall+0x103/0x650 init/main.c:1223
       do_initcall_level init/main.c:1296 [inline]
       do_initcalls init/main.c:1312 [inline]
       do_basic_setup init/main.c:1332 [inline]
       kernel_init_freeable+0x605/0x689 init/main.c:1533
       kernel_init+0xd/0x1b8 init/main.c:1421
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
      
      Freed by task 8451:
       kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
       kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
       kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:356
       ____kasan_slab_free+0xe1/0x110 mm/kasan/common.c:362
       kasan_slab_free include/linux/kasan.h:192 [inline]
       slab_free_hook mm/slub.c:1547 [inline]
       slab_free_freelist_hook+0x5d/0x150 mm/slub.c:1580
       slab_free mm/slub.c:3143 [inline]
       kfree+0xdb/0x3b0 mm/slub.c:4139
       nbd_dev_remove drivers/block/nbd.c:243 [inline]
       nbd_put.part.0+0x180/0x1d0 drivers/block/nbd.c:251
       nbd_put drivers/block/nbd.c:295 [inline]
       nbd_config_put+0x6dd/0x8c0 drivers/block/nbd.c:1242
       nbd_release+0x103/0x190 drivers/block/nbd.c:1507
       __blkdev_put+0x548/0x800 fs/block_dev.c:1579
       blkdev_put+0x92/0x570 fs/block_dev.c:1632
       blkdev_close+0x8c/0xb0 fs/block_dev.c:1640
       __fput+0x283/0x920 fs/file_table.c:280
       task_work_run+0xdd/0x190 kernel/task_work.c:140
       tracehook_notify_resume include/linux/tracehook.h:189 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
       exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:201
       __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
       syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      The buggy address belongs to the object at ffff888143bf7000
       which belongs to the cache kmalloc-1k of size 1024
      The buggy address is located 416 bytes inside of
       1024-byte region [ffff888143bf7000, ffff888143bf7400)
      The buggy address belongs to the page:
      page:000000005238f4ce refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x143bf0
      head:000000005238f4ce order:3 compound_mapcount:0 compound_pincount:0
      flags: 0x57ff00000010200(slab|head)
      raw: 057ff00000010200 ffffea00004b1400 0000000300000003 ffff888010c41140
      raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff888143bf7080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff888143bf7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      >ffff888143bf7180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
       ffff888143bf7200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      Reported-and-tested-by: default avatar <syzbot+429d3f82d757c211bff3@syzkaller.appspotmail.com>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarLuo Meng <luomeng12@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      c72b1648
    • Paul Aurich's avatar
      cifs: Fix leak when handling lease break for cached root fid · 25ebc65f
      Paul Aurich authored
      mainline inclusion
      from mainline-5.9-rc1
      commit baf57b56
      category: bugfix
      bugzilla: 40791
      CVE: NA
      
      ---------------------------
      
      Handling a lease break for the cached root didn't free the
      smb2_lease_break_work allocation, resulting in a leak:
      
          unreferenced object 0xffff98383a5af480 (size 128):
            comm "cifsd", pid 684, jiffies 4294936606 (age 534.868s)
            hex dump (first 32 bytes):
              c0 ff ff ff 1f 00 00 00 88 f4 5a 3a 38 98 ff ff  ..........Z:8...
              88 f4 5a 3a 38 98 ff ff 80 88 d6 8a ff ff ff ff  ..Z:8...........
            backtrace:
              [<0000000068957336>] smb2_is_valid_oplock_break+0x1fa/0x8c0
              [<0000000073b70b9e>] cifs_demultiplex_thread+0x73d/0xcc0
              [<00000000905fa372>] kthread+0x11c/0x150
              [<0000000079378e4e>] ret_from_fork+0x22/0x30
      
      Avoid this leak by only allocating when necessary.
      
      Fixes: a93864d9 ("cifs: add lease tracking to the cached root fid")
      Signed-o...
      25ebc65f
  5. Jul 12, 2021