1. 19 12月, 2022 5 次提交
    • P
      cifs: share dfs connections and supers · a1c0d005
      Paulo Alcantara 提交于
      When matching DFS superblocks we can't rely on either the server's
      address or tcon's UNC name from mount(2) as the existing servers and
      tcons might be connected to somewhere else.  Instead, check if
      superblock is dfs, and if so, match its original source pathname with
      the new mount's source pathname.
      
      For DFS connections, instead of checking server's address, match its
      referral path as it could be connected to different targets.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      a1c0d005
    • P
      cifs: split out ses and tcon retrieval from mount_get_conns() · a73a26d9
      Paulo Alcantara 提交于
      Introduce and export two helpers for getting session and tcon during
      mount(2).  Those will be used by dfs when retrieving sessions and
      tcons separately while chasing referrals.  Besides, export
      cifs_mount_ctx structure as it will be used by dfs code as well.
      
      No functional changes.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      a73a26d9
    • P
      cifs: set resolved ip in sockaddr · 6d740164
      Paulo Alcantara 提交于
      All callers from dns_resolve_server_name_to_ip() used to convert the
      ip addr string back to sockaddr, so do that inside
      dns_resolve_server_name_to_ip() and avoid duplicating code.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      6d740164
    • P
      cifs: get rid of mount options string parsing · abdb1742
      Paulo Alcantara 提交于
      After switching to filesystem context support, we no longer need to
      handle mount options string when chasing dfs referrals.  Now, we set
      the new values directly into smb3_fs_context.
      
      Start working on a separate source file to handle most dfs related
      mount functions as connect.c has already became too big.  The
      remaining functions will be moved gradually in follow-up patches.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      abdb1742
    • P
      cifs: reduce roundtrips on create/qinfo requests · c877ce47
      Paulo Alcantara 提交于
      To work around some Window servers that return
      STATUS_OBJECT_NAME_INVALID on query infos under DFS namespaces that
      contain non-ASCII characters, we started checking for -ENOENT on every
      file open, and if so, then send additional requests to figure out
      whether it is a DFS link or not.  It means that all those requests
      will be sent to every non-existing file.
      
      So, in order to reduce the number of roundtrips, check earlier whether
      status code is STATUS_OBJECT_NAME_INVALID and tcon supports dfs, and
      if so, then map -ENOENT to -EREMOTE so mount or automount will take
      care of chasing the DFS link -- if it isn't an DFS link, then -ENOENT
      will be returned appropriately.
      
      Before patch
      
        SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request...
        SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;...
        SMB2 228 Ioctl Request FSCTL_DFS_GET_REFERRALS, File: \ada.test\dfs\foo
        SMB2 143 Ioctl Response, Error: STATUS_OBJECT_PATH_NOT_FOUND
        SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request...
        SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;...
        SMB2 228 Ioctl Request FSCTL_DFS_GET_REFERRALS, File: \ada.test\dfs\foo
        SMB2 143 Ioctl Response, Error: STATUS_OBJECT_PATH_NOT_FOUND
      
      After patch
      
        SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request...
        SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;...
        SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request...
        SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;...
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      c877ce47
  2. 17 12月, 2022 1 次提交
  3. 16 12月, 2022 1 次提交
  4. 26 11月, 2022 1 次提交
    • A
      use less confusing names for iov_iter direction initializers · de4eda9d
      Al Viro 提交于
      READ/WRITE proved to be actively confusing - the meanings are
      "data destination, as used with read(2)" and "data source, as
      used with write(2)", but people keep interpreting those as
      "we read data from it" and "we write data to it", i.e. exactly
      the wrong way.
      
      Call them ITER_DEST and ITER_SOURCE - at least that is harder
      to misinterpret...
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      de4eda9d
  5. 12 11月, 2022 1 次提交
  6. 28 10月, 2022 1 次提交
    • Z
      cifs: fix use-after-free caused by invalid pointer `hostname` · 153695d3
      Zeng Heng 提交于
      `hostname` needs to be set as null-pointer after free in
      `cifs_put_tcp_session` function, or when `cifsd` thread attempts
      to resolve hostname and reconnect the host, the thread would deref
      the invalid pointer.
      
      Here is one of practical backtrace examples as reference:
      
      Task 477
      ---------------------------
       do_mount
        path_mount
         do_new_mount
          vfs_get_tree
           smb3_get_tree
            smb3_get_tree_common
             cifs_smb3_do_mount
              cifs_mount
               mount_put_conns
                cifs_put_tcp_session
                --> kfree(server->hostname)
      
      cifsd
      ---------------------------
       kthread
        cifs_demultiplex_thread
         cifs_reconnect
          reconn_set_ipaddr_from_hostname
          --> if (!server->hostname)
          --> if (server->hostname[0] == '\0')  // !! UAF fault here
      
      CIFS: VFS: cifs_mount failed w/return code = -112
      mount error(112): Host is down
      BUG: KASAN: use-after-free in reconn_set_ipaddr_from_hostname+0x2ba/0x310
      Read of size 1 at addr ffff888108f35380 by task cifsd/480
      CPU: 2 PID: 480 Comm: cifsd Not tainted 6.1.0-rc2-00106-gf705792f89dd-dirty #25
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x68/0x85
       print_report+0x16c/0x4a3
       kasan_report+0x95/0x190
       reconn_set_ipaddr_from_hostname+0x2ba/0x310
       __cifs_reconnect.part.0+0x241/0x800
       cifs_reconnect+0x65f/0xb60
       cifs_demultiplex_thread+0x1570/0x2570
       kthread+0x2c5/0x380
       ret_from_fork+0x22/0x30
       </TASK>
      Allocated by task 477:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       __kasan_kmalloc+0x7e/0x90
       __kmalloc_node_track_caller+0x52/0x1b0
       kstrdup+0x3b/0x70
       cifs_get_tcp_session+0xbc/0x19b0
       mount_get_conns+0xa9/0x10c0
       cifs_mount+0xdf/0x1970
       cifs_smb3_do_mount+0x295/0x1660
       smb3_get_tree+0x352/0x5e0
       vfs_get_tree+0x8e/0x2e0
       path_mount+0xf8c/0x1990
       do_mount+0xee/0x110
       __x64_sys_mount+0x14b/0x1f0
       do_syscall_64+0x3b/0x90
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      Freed by task 477:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       kasan_save_free_info+0x2a/0x50
       __kasan_slab_free+0x10a/0x190
       __kmem_cache_free+0xca/0x3f0
       cifs_put_tcp_session+0x30c/0x450
       cifs_mount+0xf95/0x1970
       cifs_smb3_do_mount+0x295/0x1660
       smb3_get_tree+0x352/0x5e0
       vfs_get_tree+0x8e/0x2e0
       path_mount+0xf8c/0x1990
       do_mount+0xee/0x110
       __x64_sys_mount+0x14b/0x1f0
       do_syscall_64+0x3b/0x90
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      The buggy address belongs to the object at ffff888108f35380
       which belongs to the cache kmalloc-16 of size 16
      The buggy address is located 0 bytes inside of
       16-byte region [ffff888108f35380, ffff888108f35390)
      The buggy address belongs to the physical page:
      page:00000000333f8e58 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888108f350e0 pfn:0x108f35
      flags: 0x200000000000200(slab|node=0|zone=2)
      raw: 0200000000000200 0000000000000000 dead000000000122 ffff8881000423c0
      raw: ffff888108f350e0 000000008080007a 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      Memory state around the buggy address:
       ffff888108f35280: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
       ffff888108f35300: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
      >ffff888108f35380: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
                         ^
       ffff888108f35400: fa fb fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       ffff888108f35480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      
      Fixes: 7be3248f ("cifs: To match file servers, make sure the server hostname matches")
      Signed-off-by: NZeng Heng <zengheng4@huawei.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      153695d3
  7. 13 10月, 2022 2 次提交
  8. 08 10月, 2022 1 次提交
  9. 06 10月, 2022 1 次提交
  10. 05 10月, 2022 1 次提交
  11. 14 9月, 2022 2 次提交
  12. 25 8月, 2022 3 次提交
  13. 20 8月, 2022 1 次提交
  14. 12 8月, 2022 1 次提交
  15. 06 8月, 2022 2 次提交
    • E
      cifs: remove useless DeleteMidQEntry() · 70f08f91
      Enzo Matsumiya 提交于
      DeleteMidQEntry() was just a proxy for cifs_mid_q_entry_release().
      
      - remove DeleteMidQEntry()
      - rename cifs_mid_q_entry_release() to release_mid()
      - rename kref_put() callback _cifs_mid_q_entry_release to __release_mid
      - rename AllocMidQEntry() to alloc_mid()
      - rename cifs_delete_mid() to delete_mid()
      
      Update callers to use new names.
      Signed-off-by: NEnzo Matsumiya <ematsumiya@suse.de>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      70f08f91
    • S
      cifs: when insecure legacy is disabled shrink amount of SMB1 code · fb157ed2
      Steve French 提交于
      Currently much of the smb1 code is built even when
      CONFIG_CIFS_ALLOW_INSECURE_LEGACY is disabled.
      
      Move cifssmb.c to only be compiled when insecure legacy is disabled,
      and move various SMB1/CIFS helper functions to that ifdef.  Some
      functions that were not SMB1/CIFS specific needed to be moved out of
      cifssmb.c
      
      This shrinks cifs.ko by more than 10% which is good - but also will
      help with the eventual movement of the legacy code to a distinct
      module.  Follow on patches can shrink the number of ifdefs by
      code restructuring where smb1 code is wedged in functions that
      should be calling dialect specific helper functions instead,
      and also by moving some functions from file.c/dir.c/inode.c into
      smb1 specific c files.
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      fb157ed2
  16. 01 8月, 2022 6 次提交
  17. 12 7月, 2022 1 次提交
  18. 25 6月, 2022 1 次提交
  19. 24 6月, 2022 1 次提交
    • S
      cifs: avoid deadlocks while updating iface · 8da33fd1
      Shyam Prasad N 提交于
      We use cifs_tcp_ses_lock to protect a lot of things.
      Not only does it protect the lists of connections, sessions,
      tree connects, open file lists, etc., we also use it to
      protect some fields in each of it's entries.
      
      In this case, cifs_mark_ses_for_reconnect takes the
      cifs_tcp_ses_lock to traverse the lists, and then calls
      cifs_update_iface. However, that can end up calling
      cifs_put_tcp_session, which picks up the same lock again.
      
      Avoid this by taking a ref for the session, drop the lock,
      and then call update iface.
      
      Also, in cifs_update_iface, avoid nested locking of iface_lock
      and chan_lock, as much as possible. When unavoidable, we need
      to pick iface_lock first.
      Signed-off-by: NShyam Prasad N <sprasad@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      8da33fd1
  20. 23 6月, 2022 3 次提交
  21. 11 6月, 2022 1 次提交
  22. 01 6月, 2022 2 次提交
    • V
      cifs: fix potential deadlock in direct reclaim · cc391b69
      Vincent Whitchurch 提交于
      The srv_mutex is used during writeback so cifs should ensure that
      allocations done when that mutex is held are done with GFP_NOFS, to
      avoid having direct reclaim ending up waiting for the same mutex and
      causing a deadlock.  This is detected by lockdep with the splat below:
      
       ======================================================
       WARNING: possible circular locking dependency detected
       5.18.0 #70 Not tainted
       ------------------------------------------------------
       kswapd0/49 is trying to acquire lock:
       ffff8880195782e0 (&tcp_ses->srv_mutex){+.+.}-{3:3}, at: compound_send_recv
      
       but task is already holding lock:
       ffffffffa98e66c0 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat
      
       which lock already depends on the new lock.
      
       the existing dependency chain (in reverse order) is:
      
       -> #1 (fs_reclaim){+.+.}-{0:0}:
              fs_reclaim_acquire
              kmem_cache_alloc_trace
              __request_module
              crypto_alg_mod_lookup
              crypto_alloc_tfm_node
              crypto_alloc_shash
              cifs_alloc_hash
              smb311_crypto_shash_allocate
              smb311_update_preauth_hash
              compound_send_recv
              cifs_send_recv
              SMB2_negotiate
              smb2_negotiate
              cifs_negotiate_protocol
              cifs_get_smb_ses
              cifs_mount
              cifs_smb3_do_mount
              smb3_get_tree
              vfs_get_tree
              path_mount
              __x64_sys_mount
              do_syscall_64
              entry_SYSCALL_64_after_hwframe
      
       -> #0 (&tcp_ses->srv_mutex){+.+.}-{3:3}:
              __lock_acquire
              lock_acquire
              __mutex_lock
              mutex_lock_nested
              compound_send_recv
              cifs_send_recv
              SMB2_write
              smb2_sync_write
              cifs_write
              cifs_writepage_locked
              cifs_writepage
              shrink_page_list
              shrink_lruvec
              shrink_node
              balance_pgdat
              kswapd
              kthread
              ret_from_fork
      
       other info that might help us debug this:
      
        Possible unsafe locking scenario:
      
              CPU0                    CPU1
              ----                    ----
         lock(fs_reclaim);
                                      lock(&tcp_ses->srv_mutex);
                                      lock(fs_reclaim);
         lock(&tcp_ses->srv_mutex);
      
        *** DEADLOCK ***
      
       1 lock held by kswapd0/49:
        #0: ffffffffa98e66c0 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat
      
       stack backtrace:
       CPU: 2 PID: 49 Comm: kswapd0 Not tainted 5.18.0 #70
       Call Trace:
        <TASK>
        dump_stack_lvl
        dump_stack
        print_circular_bug.cold
        check_noncircular
        __lock_acquire
        lock_acquire
        __mutex_lock
        mutex_lock_nested
        compound_send_recv
        cifs_send_recv
        SMB2_write
        smb2_sync_write
        cifs_write
        cifs_writepage_locked
        cifs_writepage
        shrink_page_list
        shrink_lruvec
        shrink_node
        balance_pgdat
        kswapd
        kthread
        ret_from_fork
        </TASK>
      
      Fix this by using the memalloc_nofs_save/restore APIs around the places
      where the srv_mutex is held.  Do this in a wrapper function for the
      lock/unlock of the srv_mutex, and rename the srv_mutex to avoid missing
      call sites in the conversion.
      
      Note that there is another lockdep warning involving internal crypto
      locks, which was masked by this problem and is visible after this fix,
      see the discussion in this thread:
      
       https://lore.kernel.org/all/20220523123755.GA13668@axis.com/
      
      Link: https://lore.kernel.org/r/CANT5p=rqcYfYMVHirqvdnnca4Mo+JQSw5Qu12v=kPfpk5yhhmg@mail.gmail.com/Reported-by: NShyam Prasad N <nspmangalore@gmail.com>
      Suggested-by: NLars Persson <larper@axis.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: NEnzo Matsumiya <ematsumiya@suse.de>
      Signed-off-by: NVincent Whitchurch <vincent.whitchurch@axis.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      cc391b69
    • E
      cifs: remove repeated debug message on cifs_put_smb_ses() · 0d5106a8
      Enzo Matsumiya 提交于
      Similar message is printed a few lines later in the same function
      Signed-off-by: NEnzo Matsumiya <ematsumiya@suse.de>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      0d5106a8
  23. 25 5月, 2022 1 次提交