1. 23 4月, 2020 1 次提交
  2. 30 3月, 2020 1 次提交
  3. 23 3月, 2020 3 次提交
  4. 18 3月, 2020 2 次提交
    • M
      CIFS: fiemap: do not return EINVAL if get nothing · 979a2665
      Murphy Zhou 提交于
      If we call fiemap on a truncated file with none blocks allocated,
      it makes sense we get nothing from this call. No output means
      no blocks have been counted, but the call succeeded. It's a valid
      response.
      
      Simple example reproducer:
      xfs_io -f 'truncate 2M' -c 'fiemap -v' /cifssch/testfile
      xfs_io: ioctl(FS_IOC_FIEMAP) ["/cifssch/testfile"]: Invalid argument
      Signed-off-by: NMurphy Zhou <jencce.kernel@gmail.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      979a2665
    • S
      CIFS: Increment num_remote_opens stats counter even in case of smb2_query_dir_first · 1be1fa42
      Shyam Prasad N 提交于
      The num_remote_opens counter keeps track of the number of open files which must be
      maintained by the server at any point. This is a per-tree-connect counter, and the value
      of this counter gets displayed in the /proc/fs/cifs/Stats output as a following...
      
      Open files: 0 total (local), 1 open on server
                                   ^^^^^^^^^^^^^^^^
      As a thumb-rule, we want to increment this counter for each open/create that we
      successfully execute on the server. Similarly, we should decrement the counter when
      we successfully execute a close.
      
      In this case, an increment was being missed in case of smb2_query_dir_first,
      in case of successful open. As a result, we would underflow the counter and we
      could even see the counter go to negative after sufficient smb2_query_dir_first calls.
      
      I tested the stats counter for a bunch of filesystem operations with the fix.
      And it looks like the counter looks correct to me.
      
      I also check if we missed the increments and decrements elsewhere. It does not
      seem so. Few other cases where an open is done and we don't increment the counter are
      the compound calls where the corresponding close is also sent in the request.
      Signed-off-by: NShyam Prasad N <nspmangalore@gmail.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      1be1fa42
  5. 25 2月, 2020 1 次提交
    • A
      cifs: fix rename() by ensuring source handle opened with DELETE bit · 86f740f2
      Aurelien Aptel 提交于
      To rename a file in SMB2 we open it with the DELETE access and do a
      special SetInfo on it. If the handle is missing the DELETE bit the
      server will fail the SetInfo with STATUS_ACCESS_DENIED.
      
      We currently try to reuse any existing opened handle we have with
      cifs_get_writable_path(). That function looks for handles with WRITE
      access but doesn't check for DELETE, making rename() fail if it finds
      a handle to reuse. Simple reproducer below.
      
      To select handles with the DELETE bit, this patch adds a flag argument
      to cifs_get_writable_path() and find_writable_file() and the existing
      'bool fsuid_only' argument is converted to a flag.
      
      The cifsFileInfo struct only stores the UNIX open mode but not the
      original SMB access flags. Since the DELETE bit is not mapped in that
      mode, this patch stores the access mask in cifs_fid on file open,
      which is accessible from cifsFileInfo.
      
      Simple reproducer:
      
      	#include <stdio.h>
      	#include <stdlib.h>
      	#include <sys/types.h>
      	#include <sys/stat.h>
      	#include <fcntl.h>
      	#include <unistd.h>
      	#define E(s) perror(s), exit(1)
      
      	int main(int argc, char *argv[])
      	{
      		int fd, ret;
      		if (argc != 3) {
      			fprintf(stderr, "Usage: %s A B\n"
      			"create&open A in write mode, "
      			"rename A to B, close A\n", argv[0]);
      			return 0;
      		}
      
      		fd = openat(AT_FDCWD, argv[1], O_WRONLY|O_CREAT|O_SYNC, 0666);
      		if (fd == -1) E("openat()");
      
      		ret = rename(argv[1], argv[2]);
      		if (ret) E("rename()");
      
      		ret = close(fd);
      		if (ret) E("close()");
      
      		return ret;
      	}
      
      $ gcc -o bugrename bugrename.c
      $ ./bugrename /mnt/a /mnt/b
      rename(): Permission denied
      
      Fixes: 8de9e86c ("cifs: create a helper to find a writeable handle by path name")
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      Reviewed-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      86f740f2
  6. 15 2月, 2020 2 次提交
  7. 06 2月, 2020 1 次提交
    • S
      cifs: add SMB3 change notification support · d26c2ddd
      Steve French 提交于
      A commonly used SMB3 feature is change notification, allowing an
      app to be notified about changes to a directory. The SMB3
      Notify request blocks until the server detects a change to that
      directory or its contents that matches the completion flags
      that were passed in and the "watch_tree" flag (which indicates
      whether subdirectories under this directory should be also
      included).  See MS-SMB2 2.2.35 for additional detail.
      
      To use this simply pass in the following structure to ioctl:
      
       struct __attribute__((__packed__)) smb3_notify {
              uint32_t completion_filter;
              bool    watch_tree;
       } __packed;
      
       using CIFS_IOC_NOTIFY  0x4005cf09
       or equivalently _IOW(CIFS_IOCTL_MAGIC, 9, struct smb3_notify)
      
      SMB3 change notification is supported by all major servers.
      The ioctl will block until the server detects a change to that
      directory or its subdirectories (if watch_tree is set).
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Acked-by: NPaulo Alcantara (SUSE) <pc@cjr.nz>
      d26c2ddd
  8. 05 2月, 2020 1 次提交
  9. 04 2月, 2020 1 次提交
  10. 27 1月, 2020 4 次提交
  11. 13 12月, 2019 1 次提交
  12. 04 12月, 2019 1 次提交
    • S
      smb3: query attributes on file close · 43f8a6a7
      Steve French 提交于
      Since timestamps on files on most servers can be updated at
      close, and since timestamps on our dentries default to one
      second we can have stale timestamps in some common cases
      (e.g. open, write, close, stat, wait one second, stat - will
      show different mtime for the first and second stat).
      
      The SMB2/SMB3 protocol allows querying timestamps at close
      so add the code to request timestamp and attr information
      (which is cheap for the server to provide) to be returned
      when a file is closed (it is not needed for the many
      paths that call SMB2_close that are from compounded
      query infos and close nor is it needed for some of
      the cases where a directory close immediately follows a
      directory open.
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Acked-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: NAurelien Aptel <aaptel@suse.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      43f8a6a7
  13. 25 11月, 2019 7 次提交
    • P
      CIFS: Properly process SMB3 lease breaks · 9bd45408
      Pavel Shilovsky 提交于
      Currenly we doesn't assume that a server may break a lease
      from RWH to RW which causes us setting a wrong lease state
      on a file and thus mistakenly flushing data and byte-range
      locks and purging cached data on the client. This leads to
      performance degradation because subsequent IOs go directly
      to the server.
      
      Fix this by propagating new lease state and epoch values
      to the oplock break handler through cifsFileInfo structure
      and removing the use of cifsInodeInfo flags for that. It
      allows to avoid some races of several lease/oplock breaks
      using those flags in parallel.
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      9bd45408
    • 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: sort interface list by speed · 35adffed
      Aurelien Aptel 提交于
      New channels are going to be opened by walking the list sequentially,
      so by sorting it we will connect to the fastest interfaces first.
      Signed-off-by: NAurelien Aptel <aaptel@suse.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      35adffed
    • 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
    • M
      CIFS: Use common error handling code in smb2_ioctl_query_info() · 2b1116bb
      Markus Elfring 提交于
      Move the same error code assignments so that such exception handling
      can be better reused at the end of this function.
      
      This issue was detected by using the Coccinelle software.
      Signed-off-by: NMarkus Elfring <elfring@users.sourceforge.net>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      2b1116bb
    • M
      CIFS: Use memdup_user() rather than duplicating its implementation · cfaa1181
      Markus Elfring 提交于
      Reuse existing functionality from memdup_user() instead of keeping
      duplicate source code.
      
      Generated by: scripts/coccinelle/api/memdup_user.cocci
      
      Fixes: f5b05d62 ("cifs: add IOCTL for QUERY_INFO passthrough to userspace")
      Signed-off-by: NMarkus Elfring <elfring@users.sourceforge.net>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      cfaa1181
  14. 28 10月, 2019 1 次提交
  15. 27 9月, 2019 1 次提交
    • P
      CIFS: Fix oplock handling for SMB 2.1+ protocols · a016e279
      Pavel Shilovsky 提交于
      There may be situations when a server negotiates SMB 2.1
      protocol version or higher but responds to a CREATE request
      with an oplock rather than a lease.
      
      Currently the client doesn't handle such a case correctly:
      when another CREATE comes in the server sends an oplock
      break to the initial CREATE and the client doesn't send
      an ack back due to a wrong caching level being set (READ
      instead of RWH). Missing an oplock break ack makes the
      server wait until the break times out which dramatically
      increases the latency of the second CREATE.
      
      Fix this by properly detecting oplocks when using SMB 2.1
      protocol version and higher.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      a016e279
  16. 24 9月, 2019 1 次提交
  17. 17 9月, 2019 10 次提交
  18. 06 8月, 2019 1 次提交