1. 01 6月, 2020 6 次提交
    • J
      cifs: Standardize logging output · a0a3036b
      Joe Perches 提交于
      Use pr_fmt to standardize all logging for fs/cifs.
      
      Some logging output had no CIFS: specific prefix.
      
      Now all output has one of three prefixes:
      
      o CIFS:
      o CIFS: VFS:
      o Root-CIFS:
      
      Miscellanea:
      
      o Convert printks to pr_<level>
      o Neaten macro definitions
      o Remove embedded CIFS: prefixes from formats
      o Convert "illegal" to "invalid"
      o Coalesce formats
      o Add missing '\n' format terminations
      o Consolidate multiple cifs_dbg continuations into single calls
      o More consistent use of upper case first word output logging
      o Multiline statement argument alignment and wrapping
      Signed-off-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      a0a3036b
    • S
      smb3: Add new parm "nodelete" · 82e9367c
      Steve French 提交于
      In order to handle workloads where it is important to make sure that
      a buggy app did not delete content on the drive, the new mount option
      "nodelete" allows standard permission checks on the server to work,
      but prevents on the client any attempts to unlink a file or delete
      a directory on that mount point.  This can be helpful when running
      a little understood app on a network mount that contains important
      content that should not be deleted.
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      82e9367c
    • P
      cifs: get rid of unused parameter in reconn_setup_dfs_targets() · baf3f08e
      Paulo Alcantara 提交于
      The target iterator parameter "it" is not used in
      reconn_setup_dfs_targets(), so just remove it.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      baf3f08e
    • P
      cifs: handle hostnames that resolve to same ip in failover · e4af35fa
      Paulo Alcantara 提交于
      In order to support reconnect to hostnames that resolve to same ip
      address, besides relying on the currently set hostname to match DFS
      targets, attempt to resolve the targets and then match their addresses
      with the reconnected server ip address.
      
      For instance, if we have two hostnames "FOO" and "BAR", and both
      resolve to the same ip address, we would be able to handle failover in
      DFS paths like
      
          \\FOO\dfs\link1 -> [ \BAZ\share2 (*), \BAR\share1 ]
          \\FOO\dfs\link2 -> [ \BAZ\share2 (*), \FOO\share1 ]
      
      so when "BAZ" is no longer accessible, link1 and link2 would get
      reconnected despite having different target hostnames.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      e4af35fa
    • P
      cifs: set up next DFS target before generic_ip_connect() · aaa3aef3
      Paulo Alcantara 提交于
      If we mount a very specific DFS link
      
          \\FS0.FOO.COM\dfs\link -> \FS0\share1, \FS1\share2
      
      where its target list contains NB names ("FS0" & "FS1") rather than
      FQDN ones ("FS0.FOO.COM" & "FS1.FOO.COM"), we end up connecting to
      \FOO\share1 but server->hostname will have "FOO.COM".  The reason is
      because both "FS0" and "FS0.FOO.COM" resolve to same IP address and
      they share same TCP server connection, but "FS0.FOO.COM" was the first
      hostname set -- which is OK.
      
      However, if the echo thread timeouts and we still have a good
      connection to "FS0", in cifs_reconnect()
      
          rc = generic_ip_connect(server) -> success
          if (rc) {
                  ...
                  reconn_inval_dfs_target(server, cifs_sb, &tgt_list,
      	                            &tgt_it);
                  ...
           }
           ...
      
      it successfully reconnects to "FS0" server but does not set up next
      DFS target - which should be the same target server "\FS0\share1" -
      and server->hostname remains set to "FS0.FOO.COM" rather than "FS0",
      as reconn_inval_dfs_target() would have it set to "FS0" if called
      earlier.
      
      Finally, in __smb2_reconnect(), the reconnect of tcons would fail
      because tcon->ses->server->hostname (FS0.FOO.COM) does not match DFS
      target's hostname (FS0).
      
      Fix that by calling reconn_inval_dfs_target() before
      generic_ip_connect() so server->hostname will get updated correctly
      prior to reconnecting its tcons in __smb2_reconnect().
      
      With "cifs: handle hostnames that resolve to same ip in failover"
      patch
      
          - The above problem would not occur.
          - We could save an DNS query to find out that they both resolve to
            the same ip address.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      aaa3aef3
    • K
      cifs: handle "nolease" option for vers=1.0 · 8fd6e1d6
      Kenneth D'souza 提交于
      The "nolease" mount option is only supported for SMB2+ mounts.
      Fail with appropriate error message if vers=1.0 option is passed.
      Signed-off-by: NKenneth D'souza <kdsouza@redhat.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      8fd6e1d6
  2. 23 4月, 2020 1 次提交
    • P
      cifs: do not share tcons with DFS · 65303de8
      Paulo Alcantara 提交于
      This disables tcon re-use for DFS shares.
      
      tcon->dfs_path stores the path that the tcon should connect to when
      doing failing over.
      
      If that tcon is used multiple times e.g. 2 mounts using it with
      different prefixpath, each will need a different dfs_path but there is
      only one tcon. The other solution would be to split the tcon in 2
      tcons during failover but that is much harder.
      
      tcons could not be shared with DFS in cifs.ko because in a
      DFS namespace like:
      
                //domain/dfsroot -> /serverA/dfsroot, /serverB/dfsroot
      
                //serverA/dfsroot/link -> /serverA/target1/aa/bb
      
                //serverA/dfsroot/link2 -> /serverA/target1/cc/dd
      
      you can see that link and link2 are two DFS links that both resolve to
      the same target share (/serverA/target1), so cifs.ko will only contain a
      single tcon for both link and link2.
      
      The problem with that is, if we (auto)mount "link" and "link2", cifs.ko
      will only contain a single tcon for both DFS links so we couldn't
      perform failover or refresh the DFS cache for both links because
      tcon->dfs_path was set to either "link" or "link2", but not both --
      which is wrong.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      65303de8
  3. 21 4月, 2020 1 次提交
  4. 23 3月, 2020 5 次提交
  5. 13 2月, 2020 1 次提交
  6. 04 2月, 2020 1 次提交
  7. 27 1月, 2020 1 次提交
  8. 05 12月, 2019 1 次提交
  9. 25 11月, 2019 7 次提交
    • P
      cifs: Fix retrieval of DFS referrals in cifs_mount() · 5bb30a4d
      Paulo Alcantara (SUSE) 提交于
      Make sure that DFS referrals are sent to newly resolved root targets
      as in a multi tier DFS setup.
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Link: https://lkml.kernel.org/r/05aa2995-e85e-0ff4-d003-5bb08bd17a22@canonical.com
      Cc: stable@vger.kernel.org
      Tested-by: NMatthew Ruffell <matthew.ruffell@canonical.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      5bb30a4d
    • P
      cifs: Fix use-after-free bug in cifs_reconnect() · 8354d88e
      Paulo Alcantara (SUSE) 提交于
      Ensure we grab an active reference in cifs superblock while doing
      failover to prevent automounts (DFS links) of expiring and then
      destroying the superblock pointer.
      
      This patch fixes the following KASAN report:
      
      [  464.301462] BUG: KASAN: use-after-free in
      cifs_reconnect+0x6ab/0x1350
      [  464.303052] Read of size 8 at addr ffff888155e580d0 by task
      cifsd/1107
      
      [  464.304682] CPU: 3 PID: 1107 Comm: cifsd Not tainted 5.4.0-rc4+ #13
      [  464.305552] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009),
      BIOS rel-1.12.1-0-ga5cab58-rebuilt.opensuse.org 04/01/2014
      [  464.307146] Call Trace:
      [  464.307875]  dump_stack+0x5b/0x90
      [  464.308631]  print_address_description.constprop.0+0x16/0x200
      [  464.309478]  ? cifs_reconnect+0x6ab/0x1350
      [  464.310253]  ? cifs_reconnect+0x6ab/0x1350
      [  464.311040]  __kasan_report.cold+0x1a/0x41
      [  464.311811]  ? cifs_reconnect+0x6ab/0x1350
      [  464.312563]  kasan_report+0xe/0x20
      [  464.313300]  cifs_reconnect+0x6ab/0x1350
      [  464.314062]  ? extract_hostname.part.0+0x90/0x90
      [  464.314829]  ? printk+0xad/0xde
      [  464.315525]  ? _raw_spin_lock+0x7c/0xd0
      [  464.316252]  ? _raw_read_lock_irq+0x40/0x40
      [  464.316961]  ? ___ratelimit+0xed/0x182
      [  464.317655]  cifs_readv_from_socket+0x289/0x3b0
      [  464.318386]  cifs_read_from_socket+0x98/0xd0
      [  464.319078]  ? cifs_readv_from_socket+0x3b0/0x3b0
      [  464.319782]  ? try_to_wake_up+0x43c/0xa90
      [  464.320463]  ? cifs_small_buf_get+0x4b/0x60
      [  464.321173]  ? allocate_buffers+0x98/0x1a0
      [  464.321856]  cifs_demultiplex_thread+0x218/0x14a0
      [  464.322558]  ? cifs_handle_standard+0x270/0x270
      [  464.323237]  ? __switch_to_asm+0x40/0x70
      [  464.323893]  ? __switch_to_asm+0x34/0x70
      [  464.324554]  ? __switch_to_asm+0x40/0x70
      [  464.325226]  ? __switch_to_asm+0x40/0x70
      [  464.325863]  ? __switch_to_asm+0x34/0x70
      [  464.326505]  ? __switch_to_asm+0x40/0x70
      [  464.327161]  ? __switch_to_asm+0x34/0x70
      [  464.327784]  ? finish_task_switch+0xa1/0x330
      [  464.328414]  ? __switch_to+0x363/0x640
      [  464.329044]  ? __schedule+0x575/0xaf0
      [  464.329655]  ? _raw_spin_lock_irqsave+0x82/0xe0
      [  464.330301]  kthread+0x1a3/0x1f0
      [  464.330884]  ? cifs_handle_standard+0x270/0x270
      [  464.331624]  ? kthread_create_on_node+0xd0/0xd0
      [  464.332347]  ret_from_fork+0x35/0x40
      
      [  464.333577] Allocated by task 1110:
      [  464.334381]  save_stack+0x1b/0x80
      [  464.335123]  __kasan_kmalloc.constprop.0+0xc2/0xd0
      [  464.335848]  cifs_smb3_do_mount+0xd4/0xb00
      [  464.336619]  legacy_get_tree+0x6b/0xa0
      [  464.337235]  vfs_get_tree+0x41/0x110
      [  464.337975]  fc_mount+0xa/0x40
      [  464.338557]  vfs_kern_mount.part.0+0x6c/0x80
      [  464.339227]  cifs_dfs_d_automount+0x336/0xd29
      [  464.339846]  follow_managed+0x1b1/0x450
      [  464.340449]  lookup_fast+0x231/0x4a0
      [  464.341039]  path_openat+0x240/0x1fd0
      [  464.341634]  do_filp_open+0x126/0x1c0
      [  464.342277]  do_sys_open+0x1eb/0x2c0
      [  464.342957]  do_syscall_64+0x5e/0x190
      [  464.343555]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      [  464.344772] Freed by task 0:
      [  464.345347]  save_stack+0x1b/0x80
      [  464.345966]  __kasan_slab_free+0x12c/0x170
      [  464.346576]  kfree+0xa6/0x270
      [  464.347211]  rcu_core+0x39c/0xc80
      [  464.347800]  __do_softirq+0x10d/0x3da
      
      [  464.348919] The buggy address belongs to the object at
      ffff888155e58000
                      which belongs to the cache kmalloc-256 of size 256
      [  464.350222] The buggy address is located 208 bytes inside of
                      256-byte region [ffff888155e58000, ffff888155e58100)
      [  464.351575] The buggy address belongs to the page:
      [  464.352333] page:ffffea0005579600 refcount:1 mapcount:0
      mapping:ffff88815a803400 index:0x0 compound_mapcount: 0
      [  464.353583] flags: 0x200000000010200(slab|head)
      [  464.354209] raw: 0200000000010200 ffffea0005576200 0000000400000004
      ffff88815a803400
      [  464.355353] raw: 0000000000000000 0000000080100010 00000001ffffffff
      0000000000000000
      [  464.356458] page dumped because: kasan: bad access detected
      
      [  464.367005] Memory state around the buggy address:
      [  464.367787]  ffff888155e57f80: fc fc fc fc fc fc fc fc fc fc fc fc
      fc fc fc fc
      [  464.368877]  ffff888155e58000: fb fb fb fb fb fb fb fb fb fb fb fb
      fb fb fb fb
      [  464.369967] >ffff888155e58080: fb fb fb fb fb fb fb fb fb fb fb fb
      fb fb fb fb
      [  464.371111]                                                  ^
      [  464.371775]  ffff888155e58100: fc fc fc fc fc fc fc fc fc fc fc fc
      fc fc fc fc
      [  464.372893]  ffff888155e58180: fc fc fc fc fc fc fc fc fc fc fc fc
      fc fc fc fc
      [  464.373983] ==================================================================
      Signed-off-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      8354d88e
    • A
      cifs: try opening channels after mounting · d70e9fa5
      Aurelien Aptel 提交于
      After doing mount() successfully we call cifs_try_adding_channels()
      which will open as many channels as it can.
      
      Channels are closed when the master session is closed.
      
      The master connection becomes the first channel.
      
      ,-------------> global cifs_tcp_ses_list <-------------------------.
      |                                                                  |
      '- TCP_Server_Info  <-->  TCP_Server_Info  <-->  TCP_Server_Info <-'
            (master con)           (chan#1 con)         (chan#2 con)
            |      ^                    ^                    ^
            v      '--------------------|--------------------'
         cifs_ses                       |
         - chan_count = 3               |
         - chans[] ---------------------'
         - smb3signingkey[]
            (master signing key)
      
      Note how channel connections don't have sessions. That's because
      cifs_ses can only be part of one linked list (list_head are internal
      to the elements).
      
      For signing keys, each channel has its own signing key which must be
      used only after the channel has been bound. While it's binding it must
      use the master session signing key.
      
      For encryption keys, since channel connections do not have sessions
      attached we must now find matching session by looping over all sessions
      in smb2_get_enc_key().
      
      Each channel is opened like a regular server connection but at the
      session setup request step it must set the
      SMB2_SESSION_REQ_FLAG_BINDING flag and use the session id to bind to.
      
      Finally, while sending in compound_send_recv() for requests that
      aren't negprot, ses-setup or binding related, use a channel by cycling
      through the available ones (round-robin).
      Signed-off-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      d70e9fa5
    • A
      cifs: switch servers depending on binding state · f6a6bf7c
      Aurelien Aptel 提交于
      Currently a lot of the code to initialize a connection & session uses
      the cifs_ses as input. But depending on if we are opening a new session
      or a new channel we need to use different server pointers.
      
      Add a "binding" flag in cifs_ses and a helper function that returns
      the server ptr a session should use (only in the sess establishment
      code path).
      Signed-off-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      f6a6bf7c
    • A
      cifs: add multichannel mount options and data structs · bcc88801
      Aurelien Aptel 提交于
      adds:
      - [no]multichannel to enable/disable multichannel
      - max_channels=N to control how many channels to create
      
      these options are then stored in the volume struct.
      
      - store channels and max_channels in cifs_ses
      Signed-off-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      bcc88801
    • P
      CIFS: Do not miss cancelled OPEN responses · 7b71843f
      Pavel Shilovsky 提交于
      When an OPEN command is cancelled we mark a mid as
      cancelled and let the demultiplex thread process it
      by closing an open handle. The problem is there is
      a race between a system call thread and the demultiplex
      thread and there may be a situation when the mid has
      been already processed before it is set as cancelled.
      
      Fix this by processing cancelled requests when mids
      are being destroyed which means that there is only
      one thread referencing a particular mid. Also set
      mids as cancelled unconditionally on their state.
      
      Cc: Stable <stable@vger.kernel.org>
      Tested-by: NFrank Sorenson <sorenson@redhat.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      7b71843f
    • P
      CIFS: Fix NULL pointer dereference in mid callback · 86a7964b
      Pavel Shilovsky 提交于
      There is a race between a system call processing thread
      and the demultiplex thread when mid->resp_buf becomes NULL
      and later is being accessed to get credits. It happens when
      the 1st thread wakes up before a mid callback is called in
      the 2nd one but the mid state has already been set to
      MID_RESPONSE_RECEIVED. This causes NULL pointer dereference
      in mid callback.
      
      Fix this by saving credits from the response before we
      update the mid state and then use this value in the mid
      callback rather then accessing a response buffer.
      
      Cc: Stable <stable@vger.kernel.org>
      Fixes: ee258d79 ("CIFS: Move credit processing to mid callbacks for SMB3")
      Tested-by: NFrank Sorenson <sorenson@redhat.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      86a7964b
  10. 25 10月, 2019 1 次提交
    • P
      CIFS: Fix retry mid list corruption on reconnects · abe57073
      Pavel Shilovsky 提交于
      When the client hits reconnect it iterates over the mid
      pending queue marking entries for retry and moving them
      to a temporary list to issue callbacks later without holding
      GlobalMid_Lock. In the same time there is no guarantee that
      mids can't be removed from the temporary list or even
      freed completely by another thread. It may cause a temporary
      list corruption:
      
      [  430.454897] list_del corruption. prev->next should be ffff98d3a8f316c0, but was 2e885cb266355469
      [  430.464668] ------------[ cut here ]------------
      [  430.466569] kernel BUG at lib/list_debug.c:51!
      [  430.468476] invalid opcode: 0000 [#1] SMP PTI
      [  430.470286] CPU: 0 PID: 13267 Comm: cifsd Kdump: loaded Not tainted 5.4.0-rc3+ #19
      [  430.473472] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
      [  430.475872] RIP: 0010:__list_del_entry_valid.cold+0x31/0x55
      ...
      [  430.510426] Call Trace:
      [  430.511500]  cifs_reconnect+0x25e/0x610 [cifs]
      [  430.513350]  cifs_readv_from_socket+0x220/0x250 [cifs]
      [  430.515464]  cifs_read_from_socket+0x4a/0x70 [cifs]
      [  430.517452]  ? try_to_wake_up+0x212/0x650
      [  430.519122]  ? cifs_small_buf_get+0x16/0x30 [cifs]
      [  430.521086]  ? allocate_buffers+0x66/0x120 [cifs]
      [  430.523019]  cifs_demultiplex_thread+0xdc/0xc30 [cifs]
      [  430.525116]  kthread+0xfb/0x130
      [  430.526421]  ? cifs_handle_standard+0x190/0x190 [cifs]
      [  430.528514]  ? kthread_park+0x90/0x90
      [  430.530019]  ret_from_fork+0x35/0x40
      
      Fix this by obtaining extra references for mids being retried
      and marking them as MID_DELETED which indicates that such a mid
      has been dequeued from the pending list.
      
      Also move mid cleanup logic from DeleteMidQEntry to
      _cifs_mid_q_entry_release which is called when the last reference
      to a particular mid is put. This allows to avoid any use-after-free
      of response buffers.
      
      The patch needs to be backported to stable kernels. A stable tag
      is not mentioned below because the patch doesn't apply cleanly
      to any actively maintained stable kernel.
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-and-tested-by: NDavid Wysochanski <dwysocha@redhat.com>
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      abe57073
  11. 21 10月, 2019 1 次提交
  12. 09 10月, 2019 1 次提交
  13. 07 10月, 2019 1 次提交
  14. 17 9月, 2019 11 次提交
  15. 28 8月, 2019 1 次提交