1. 29 Sep, 2022 3 commits
    • Zhihao Cheng's avatar
      quota: Add more checking after reading from quota file · 191249f7
      Zhihao Cheng authored
      It would be better to do more sanity checking (eg. dqdh_entries,
      block no.) for the content read from quota file, which can prevent
      corrupting the quota file.
      
      Link: https://lore.kernel.org/r/20220923134555.2623931-4-chengzhihao1@huawei.comSigned-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      191249f7
    • Zhihao Cheng's avatar
      quota: Replace all block number checking with helper function · 3fc61e0e
      Zhihao Cheng authored
      Cleanup all block checking places, replace them with helper function
      do_check_range().
      
      Link: https://lore.kernel.org/r/20220923134555.2623931-3-chengzhihao1@huawei.comSigned-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      3fc61e0e
    • Zhihao Cheng's avatar
      quota: Check next/prev free block number after reading from quota file · 6c8ea8b8
      Zhihao Cheng authored
      Following process:
       Init: v2_read_file_info: <3> dqi_free_blk 0 dqi_free_entry 5 dqi_blks 6
      
       Step 1. chown bin f_a -> dquot_acquire -> v2_write_dquot:
        qtree_write_dquot
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            write_blk(info->dqi_blocks) // info->dqi_blocks = 6, failure. The
      	   content in physical block (corresponding to blk 6) is random.
      
       Step 2. chown root f_a -> dquot_transfer -> dqput_all -> dqput ->
               ext4_release_dquot -> v2_release_dquot -> qtree_delete_dquot:
        dquot_release
         remove_tree
          free_dqentry
           put_free_dqblk(6)
            info->dqi_free_blk = blk    // info->dqi_free_blk = 6
      
       Step 3. drop cache (buffer head for block 6 is released)
      
       Step 4. chown bin f_b -> dquot_acquire -> commit_dqblk -> v2_write_dquot:
        qtree_write_dquot
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            dh = (struct qt_disk_dqdbheader *)buf
            blk = info->dqi_free_blk     // 6
            ret = read_blk(info, blk, buf)  // The content of buf is random
            info->dqi_free_blk = le32_to_cpu(dh->dqdh_next_free)  // random blk
      
       Step 5. chown bin f_c -> notify_change -> ext4_setattr -> dquot_transfer:
        dquot = dqget -> acquire_dquot -> ext4_acquire_dquot -> dquot_acquire ->
                commit_dqblk -> v2_write_dquot -> dq_insert_tree:
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            blk = info->dqi_free_blk    // If blk < 0 and blk is not an error
      				     code, it will be returned as dquot
      
        transfer_to[USRQUOTA] = dquot  // A random negative value
        __dquot_transfer(transfer_to)
         dquot_add_inodes(transfer_to[cnt])
          spin_lock(&dquot->dq_dqb_lock)  // page fault
      
      , which will lead to kernel page fault:
       Quota error (device sda): qtree_write_dquot: Error -8000 occurred
       while creating quota
       BUG: unable to handle page fault for address: ffffffffffffe120
       #PF: supervisor write access in kernel mode
       #PF: error_code(0x0002) - not-present page
       Oops: 0002 [#1] PREEMPT SMP
       CPU: 0 PID: 5974 Comm: chown Not tainted 6.0.0-rc1-00004
       Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
       RIP: 0010:_raw_spin_lock+0x3a/0x90
       Call Trace:
        dquot_add_inodes+0x28/0x270
        __dquot_transfer+0x377/0x840
        dquot_transfer+0xde/0x540
        ext4_setattr+0x405/0x14d0
        notify_change+0x68e/0x9f0
        chown_common+0x300/0x430
        __x64_sys_fchownat+0x29/0x40
      
      In order to avoid accessing invalid quota memory address, this patch adds
      block number checking of next/prev free block read from quota file.
      
      Fetch a reproducer in [Link].
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216372
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      CC: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20220923134555.2623931-2-chengzhihao1@huawei.comSigned-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      6c8ea8b8
  2. 26 Sep, 2022 2 commits
    • Jan Kara's avatar
      ext2: Use kvmalloc() for group descriptor array · e7c7fbb9
      Jan Kara authored
      Array of group descriptor block buffers can get rather large. In theory
      in can reach 1MB for perfectly valid filesystem and even more for
      maliciously crafted ones. Use kvmalloc() to allocate the array to avoid
      straining memory allocator with large order allocations unnecessarily.
      
      Reported-by: syzbot+0f2f7e65a3007d39539f@syzkaller.appspotmail.com
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      e7c7fbb9
    • Jan Kara's avatar
      ext2: Add sanity checks for group and filesystem size · d766f2d1
      Jan Kara authored
      Add sanity check that filesystem size does not exceed the underlying
      device size and that group size is big enough so that metadata can fit
      into it. This avoid trying to mount some crafted filesystems with
      extremely large group counts.
      
      Reported-by: syzbot+0f2f7e65a3007d39539f@syzkaller.appspotmail.com
      Reported-by: kernel test robot <oliver.sang@intel.com> # Test fixup
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      d766f2d1
  3. 12 Sep, 2022 1 commit
  4. 19 Aug, 2022 5 commits
    • Minghao Chi's avatar
      isofs: delete unnecessary checks before brelse() · d4d361ad
      Minghao Chi authored
      The brelse() function tests whether its argument is NULL
      and then returns immediately.
      Thus remove the tests which are not needed around the shown calls.
      Reported-by: default avatarZeal Robot <zealci@zte.com.cn>
      Signed-off-by: default avatarMinghao Chi <chi.minghao@zte.com.cn>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20220819081420.96209-1-chi.minghao@zte.com.cn
      d4d361ad
    • Jiangshan Yi's avatar
      fs/reiserfs: replace ternary operator with min() and min_t() · e03d3b1b
      Jiangshan Yi authored
      Fix the following coccicheck warning:
      
      fs/reiserfs/prints.c:459: WARNING opportunity for min().
      fs/reiserfs/resize.c:100: WARNING opportunity for min().
      fs/reiserfs/super.c:2508: WARNING opportunity for min().
      fs/reiserfs/super.c:2557: WARNING opportunity for min().
      
      min() and min_t() macro is defined in include/linux/minmax.h.
      It avoids multiple evaluations of the arguments when non-constant and
      performs strict type-checking.
      Signed-off-by: default avatarJiangshan Yi <yijiangshan@kylinos.cn>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20220819075240.3199477-1-13667453960@163.com
      e03d3b1b
    • Linus Torvalds's avatar
      Merge tag 'net-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net · 4c2d0b03
      Linus Torvalds authored
      Pull networking fixes from Jakub Kicinski:
       "Including fixes from netfilter.
      
        Current release - regressions:
      
         - tcp: fix cleanup and leaks in tcp_read_skb() (the new way BPF
           socket maps get data out of the TCP stack)
      
         - tls: rx: react to strparser initialization errors
      
         - netfilter: nf_tables: fix scheduling-while-atomic splat
      
         - net: fix suspicious RCU usage in bpf_sk_reuseport_detach()
      
        Current release - new code bugs:
      
         - mlxsw: ptp: fix a couple of races, static checker warnings and
           error handling
      
        Previous releases - regressions:
      
         - netfilter:
            - nf_tables: fix possible module reference underflow in error path
            - make conntrack helpers deal with BIG TCP (skbs > 64kB)
            - nfnetlink: re-enable conntrack expectation events
      
         - net: fix potential refcount leak in ndisc_router_discovery()
      
        Previous releases - always broken:
      
         - sched: cls_route: disallow handle of 0
      
         - neigh: fix possible local DoS due to net iface start/stop loop
      
         - rtnetlink: fix module refcount leak in rtnetlink_rcv_msg
      
         - sched: fix adding qlen to qcpu->backlog in gnet_stats_add_queue_cpu
      
         - virtio_net: fix endian-ness for RSS
      
         - dsa: mv88e6060: prevent crash on an unused port
      
         - fec: fix timer capture timing in `fec_ptp_enable_pps()`
      
         - ocelot: stats: fix races, integer wrapping and reading incorrect
           registers (the change of register definitions here accounts for
           bulk of the changed LoC in this PR)"
      
      * tag 'net-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (77 commits)
        net: moxa: MAC address reading, generating, validity checking
        tcp: handle pure FIN case correctly
        tcp: refactor tcp_read_skb() a bit
        tcp: fix tcp_cleanup_rbuf() for tcp_read_skb()
        tcp: fix sock skb accounting in tcp_read_skb()
        igb: Add lock to avoid data race
        dt-bindings: Fix incorrect "the the" corrections
        net: genl: fix error path memory leak in policy dumping
        stmmac: intel: Add a missing clk_disable_unprepare() call in intel_eth_pci_remove()
        net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_xdp_run
        net/mlx5e: Allocate flow steering storage during uplink initialization
        net: mscc: ocelot: report ndo_get_stats64 from the wraparound-resistant ocelot->stats
        net: mscc: ocelot: keep ocelot_stat_layout by reg address, not offset
        net: mscc: ocelot: make struct ocelot_stat_layout array indexable
        net: mscc: ocelot: fix race between ndo_get_stats64 and ocelot_check_stats_work
        net: mscc: ocelot: turn stats_lock into a spinlock
        net: mscc: ocelot: fix address of SYS_COUNT_TX_AGING counter
        net: mscc: ocelot: fix incorrect ndo_get_stats64 packet counters
        net: dsa: felix: fix ethtool 256-511 and 512-1023 TX packet counters
        net: dsa: don't warn in dsa_port_set_state_now() when driver doesn't support it
        ...
      4c2d0b03
    • Linus Torvalds's avatar
      Merge tag 'linux-kselftest-next-6.0-rc2' of... · 90b6b686
      Linus Torvalds authored
      Merge tag 'linux-kselftest-next-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
      
      Pull Kselftest fix from Shuah Khan:
      
       - fix landlock test build regression
      
      * tag 'linux-kselftest-next-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
        selftests/landlock: fix broken include of linux/landlock.h
      90b6b686
    • Linus Torvalds's avatar
      Merge tag 'trace-rtla-v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace · 0de277d4
      Linus Torvalds authored
      Pull rtla tool fixes from Steven Rostedt:
       "Fixes for the Real-Time Linux Analysis tooling:
      
         - Fix tracer name in comments and prints
      
         - Fix setting up symlinks
      
         - Allow extra flags to be set in build
      
         - Consolidate and show all necessary libraries not found in build
           error"
      
      * tag 'trace-rtla-v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
        rtla: Consolidate and show all necessary libraries that failed for building
        tools/rtla: Build with EXTRA_{C,LD}FLAGS
        tools/rtla: Fix command symlinks
        rtla: Fix tracer name
      0de277d4
  5. 18 Aug, 2022 26 commits
  6. 17 Aug, 2022 3 commits
    • David Howells's avatar
      net: Fix suspicious RCU usage in bpf_sk_reuseport_detach() · fc4aaf9f
      David Howells authored
      bpf_sk_reuseport_detach() calls __rcu_dereference_sk_user_data_with_flags()
      to obtain the value of sk->sk_user_data, but that function is only usable
      if the RCU read lock is held, and neither that function nor any of its
      callers hold it.
      
      Fix this by adding a new helper, __locked_read_sk_user_data_with_flags()
      that checks to see if sk->sk_callback_lock() is held and use that here
      instead.
      
      Alternatively, making __rcu_dereference_sk_user_data_with_flags() use
      rcu_dereference_checked() might suffice.
      
      Without this, the following warning can be occasionally observed:
      
      =============================
      WARNING: suspicious RCU usage
      6.0.0-rc1-build2+ #563 Not tainted
      -----------------------------
      include/net/sock.h:592 suspicious rcu_dereference_check() usage!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      5 locks held by locktest/29873:
       #0: ffff88812734b550 (&sb->s_type->i_mutex_key#9){+.+.}-{3:3}, at: __sock_release+0x77/0x121
       #1: ffff88812f5621b0 (sk_lock-AF_INET){+.+.}-{0:0}, at: tcp_close+0x1c/0x70
       #2: ffff88810312f5c8 (&h->lhash2[i].lock){+.+.}-{2:2}, at: inet_unhash+0x76/0x1c0
       #3: ffffffff83768bb8 (reuseport_lock){+...}-{2:2}, at: reuseport_detach_sock+0x18/0xdd
       #4: ffff88812f562438 (clock-AF_INET){++..}-{2:2}, at: bpf_sk_reuseport_detach+0x24/0xa4
      
      stack backtrace:
      CPU: 1 PID: 29873 Comm: locktest Not tainted 6.0.0-rc1-build2+ #563
      Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x4c/0x5f
       bpf_sk_reuseport_detach+0x6d/0xa4
       reuseport_detach_sock+0x75/0xdd
       inet_unhash+0xa5/0x1c0
       tcp_set_state+0x169/0x20f
       ? lockdep_sock_is_held+0x3a/0x3a
       ? __lock_release.isra.0+0x13e/0x220
       ? reacquire_held_locks+0x1bb/0x1bb
       ? hlock_class+0x31/0x96
       ? mark_lock+0x9e/0x1af
       __tcp_close+0x50/0x4b6
       tcp_close+0x28/0x70
       inet_release+0x8e/0xa7
       __sock_release+0x95/0x121
       sock_close+0x14/0x17
       __fput+0x20f/0x36a
       task_work_run+0xa3/0xcc
       exit_to_user_mode_prepare+0x9c/0x14d
       syscall_exit_to_user_mode+0x18/0x44
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Fixes: cf8c1e96 ("net: refactor bpf_sk_reuseport_detach()")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Hawkins Jiawei <yin31149@gmail.com>
      Link: https://lore.kernel.org/r/166064248071.3502205.10036394558814861778.stgit@warthog.procyon.org.ukSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      fc4aaf9f
    • Linus Torvalds's avatar
      Merge tag 'ntfs3_for_6.0' of https://github.com/Paragon-Software-Group/linux-ntfs3 · 3b06a275
      Linus Torvalds authored
      Pull ntfs3 updates from Konstantin Komarov:
      
       - implement FALLOC_FL_INSERT_RANGE
      
       - fix some logic errors
      
       - fixed xfstests (tested on x86_64): generic/064 generic/213
         generic/300 generic/361 generic/449 generic/485
      
       - some dead code removed or refactored
      
      * tag 'ntfs3_for_6.0' of https://github.com/Paragon-Software-Group/linux-ntfs3: (39 commits)
        fs/ntfs3: uninitialized variable in ntfs_set_acl_ex()
        fs/ntfs3: Remove unused function wnd_bits
        fs/ntfs3: Make ni_ins_new_attr return error
        fs/ntfs3: Create MFT zone only if length is large enough
        fs/ntfs3: Refactoring attr_insert_range to restore after errors
        fs/ntfs3: Refactoring attr_punch_hole to restore after errors
        fs/ntfs3: Refactoring attr_set_size to restore after errors
        fs/ntfs3: New function ntfs_bad_inode
        fs/ntfs3: Make MFT zone less fragmented
        fs/ntfs3: Check possible errors in run_pack in advance
        fs/ntfs3: Added comments to frecord functions
        fs/ntfs3: Fill duplicate info in ni_add_name
        fs/ntfs3: Make static function attr_load_runs
        fs/ntfs3: Add new argument is_mft to ntfs_mark_rec_free
        fs/ntfs3: Remove unused mi_mark_free
        fs/ntfs3: Fix very fragmented case in attr_punch_hole
        fs/ntfs3: Fix work with fragmented xattr
        fs/ntfs3: Make ntfs_fallocate return -ENOSPC instead of -EFBIG
        fs/ntfs3: extend ni_insert_nonresident to return inserted ATTR_LIST_ENTRY
        fs/ntfs3: Check reserved size for maximum allowed
        ...
      3b06a275
    • Linus Torvalds's avatar
      dcache: move the DCACHE_OP_COMPARE case out of the __d_lookup_rcu loop · ae2a8236
      Linus Torvalds authored
      __d_lookup_rcu() is one of the hottest functions in the kernel on
      certain loads, and it is complicated by filesystems that might want to
      have their own name compare function.
      
      We can improve code generation by moving the test of DCACHE_OP_COMPARE
      outside the loop, which makes the loop itself much simpler, at the cost
      of some code duplication.  But both cases end up being simpler, and the
      "native" direct case-sensitive compare particularly so.
      
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ae2a8236