23 Mar, 2020

2 commits

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Steve French

    Gustavo A. R. Silva
     
  • * add new info level and structs for SMB2 posix extension
    * add functions to parse and validate it

    Signed-off-by: Aurelien Aptel
    Signed-off-by: Steve French

    Aurelien Aptel
     

03 Nov, 2018

1 commit


02 Mar, 2017

1 commit

  • since the DFS payload is not tied to the SMB version we can:
    * isolate the DFS payload in its own struct, and include that struct in
    packet structs
    * move the function that parses the response to misc.c and make it work
    on the new DFS payload struct (add payload size and utf16 flag as a
    result).

    Signed-off-by: Aurelien Aptel
    Acked-by: Pavel Shilovsky
    Signed-off-by: Steve French

    Aurelien Aptel
     

20 Aug, 2015

1 commit

  • The server exports information about the share and underlying
    device under an SMB3 export, including its attributes and
    capabilities, which is stored by cifs.ko when first connecting
    to the share.

    Add ioctl to cifs.ko to allow user space smb3 helper utilities
    (in cifs-utils) to display this (e.g. via smb3util).

    This information is also useful for debugging and for
    resolving configuration errors.

    Signed-off-by: Steve French

    Steve French
     

29 Jun, 2015

1 commit

  • Getting fantastic copy performance with cp --reflink over SMB3.11
    using the new FSCTL_DUPLICATE_EXTENTS.

    This FSCTL was added in the SMB3.11 dialect (testing was
    against REFS file system) so have put it as a 3.11 protocol
    specific operation ("vers=3.1.1" on the mount). Tested at
    the SMB3 plugfest in Redmond.

    It depends on the new FS Attribute (BLOCK_REFCOUNTING) which
    is used to advertise support for the ability to do this ioctl
    (if you can support multiple files pointing to the same block
    than this refcounting ability or equivalent is needed to
    support the new reflink-like duplicate extent SMB3 ioctl.

    Signed-off-by: Steve French

    Steve French
     

28 Jun, 2015

1 commit


13 Aug, 2014

1 commit


12 Nov, 2013

1 commit

  • A bit of cleanup plus some gratuitous variable renaming. I think using
    structures instead of numeric offsets makes this code much more
    understandable.

    Also added a comment about current time range expected by
    the server.

    Acked-by: Jeff Layton
    Reviewed-by: Shirish Pargaonkar
    Signed-off-by: Tim Gardner
    Signed-off-by: Steve French

    Tim Gardner
     

03 Nov, 2013

2 commits

  • An earlier patch allowed setting the per-file compression flag

    "chattr +c filename"

    on an smb2 or smb3 mount, and also allowed lsattr to return
    whether a file on a cifs, or smb2/smb3 mount was compressed.

    This patch extends the ability to set the per-file
    compression flag to the cifs protocol, which uses a somewhat
    different IOCTL mechanism than SMB2, although the payload
    (the flags stored in the compression_state) are the same.

    Reviewed-by: Jeff Layton
    Signed-off-by: Steve French

    Steve French
     
  • The multiplex identifier (MID) in the SMB header is only
    ever used by the client, in conjunction with PID, to match responses
    from the server. As such, the endianess of the MID is not important.
    However, When tracing packet sequences on the wire, protocol analyzers
    such as wireshark display MID as little endian. It is much more informative
    for the on-the-wire MID sequences to match debug information emitted by the
    CIFS driver. Therefore, one should write and read MID in the SMB header
    assuming it is always little endian.

    Observed from wireshark during the protocol negotiation
    and session setup:

    Multiplex ID: 256
    Multiplex ID: 256
    Multiplex ID: 512
    Multiplex ID: 512
    Multiplex ID: 768
    Multiplex ID: 768

    After this patch on-the-wire MID values begin at 1 and increase monotonically.

    Introduce get_next_mid64() for the internal consumers that use the full 64 bit
    multiplex identifier.

    Introduce the helpers get_mid() and compare_mid() to make the endian
    translation clear.

    Reviewed-by: Jeff Layton
    Signed-off-by: Tim Gardner
    Signed-off-by: Steve French

    Tim Gardner
     

28 Oct, 2013

1 commit


06 Oct, 2013

1 commit

  • Windows 8 and later can create NFS symlinks (within reparse points)
    which we were assuming were normal NTFS symlinks and thus reporting
    corrupt paths for. Add check for reparse points to make sure that
    they really are normal symlinks before we try to parse the pathname.

    We also should not be parsing other types of reparse points (DFS
    junctions etc) as if they were a symlink so return EOPNOTSUPP
    on those. Also fix endian errors (we were not parsing symlink
    lengths as little endian).

    This fixes commit d244bf2dfbebfded05f494ffd53659fa7b1e32c1
    which implemented follow link for non-Unix CIFS mounts

    CC: Stable
    Reviewed-by: Andrew Bartlett
    Signed-off-by: Steve French

    Steve French
     

26 Sep, 2013

1 commit


09 Sep, 2013

1 commit


27 Jun, 2013

1 commit

  • SMB3 uses a much faster method of signing (which is also better in other ways),
    AES-CMAC. With the kernel now supporting AES-CMAC since last release, we
    are overdue to allow SMB3 signing (today only CIFS and SMB2 and SMB2.1,
    but not SMB3 and SMB3.1 can sign) - and we need this also for checking
    secure negotation and also per-share encryption (two other new SMB3 features
    which we need to implement).

    This patch needs some work in a few areas - for example we need to
    move signing for SMB2/SMB3 from per-socket to per-user (we may be able to
    use the "nosharesock" mount option in the interim for the multiuser case),
    and Shirish found a bug in the earlier authentication overhaul
    (setting signing flags properly) - but those can be done in followon
    patches.

    Signed-off-by: Shirish Pargaonkar
    Signed-off-by: Steve French

    Steve French
     

24 Jun, 2013

2 commits


13 Feb, 2013

1 commit

  • Update id_mode_to_cifs_acl to take a kuid_t and a kgid_t.

    Replace NO_CHANGE_32 with INVALID_UID and INVALID_GID, and tests for
    NO_CHANGE_32 with uid_valid and gid_valid.

    Carefully unpack the value returned from request_key. memcpy the
    value into the expected type. The convert the uid/gid into a
    kuid/kgid. And then only if the result is a valid kuid or kgid update
    fuid/fgid.

    Cc: Steve French
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

25 Sep, 2012

1 commit


28 Oct, 2011

1 commit

  • Samba supports a setfs info level to negotiate encrypted
    shares. This patch adds the defines so we recognize
    this info level. Later patches will add the enablement
    for it.

    Acked-by: Jeremy Allison
    Signed-off-by: Steve French

    Steve French
     

20 Oct, 2011

1 commit


19 May, 2011

3 commits

  • It's a bad idea to have macro functions that reference variables more
    than once, as the arguments could have side effects. Turn BCC() into
    a static inlined function instead.

    While we're at it, make it return a void * to discourage anyone from
    dereferencing it as-is.

    Reported-and-acked-by: David Howells
    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French
    Signed-off-by: Pavel Shilovsky
    Signed-off-by: Steve French

    Jeff Layton
     
  • This is the same patch as originally posted, just with some merge
    conflicts fixed up...

    Currently, the ByteCount is usually converted to host-endian on receive.
    This is confusing however, as we need to keep two sets of routines for
    accessing it, and keep track of when to use each routine. Munging
    received packets like this also limits when the signature can be
    calulated.

    Simplify the code by keeping the received ByteCount in little-endian
    format. This allows us to eliminate a set of routines for accessing it
    and we can now drop the *_le suffixes from the accessor functions since
    that's now implied.

    While we're at it, switch all of the places that read the ByteCount
    directly to use the get_bcc inline which should also clean up some
    unaligned accesses.

    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French

    Jeff Layton
     
  • There is one big endian field in the cifs protocol, the RFC1001
    length, which cifs code (unlike in the smb2 code) had been handling as
    u32 until the last possible moment, when it was converted to be32 (its
    native form) before sending on the wire. To remove the last sparse
    endian warning, and to make this consistent with the smb2
    implementation (which always treats the fields in their
    native size and endianness), convert all uses of smb_buf_length to
    be32.

    This version incorporates Christoph's comment about
    using be32_add_cpu, and fixes a typo in the second
    version of the patch.

    Signed-off-by: Steve French
    Signed-off-by: Pavel Shilovsky
    Signed-off-by: Steve French

    Steve French
     

21 Jan, 2011

2 commits

  • It's possible that when we access the ByteCount that the alignment
    will be off. Most CPUs deal with that transparently, but there's
    usually some performance impact. Some CPUs raise an exception on
    unaligned accesses.

    Fix this by accessing the byte count using the get_unaligned and
    put_unaligned inlined functions. While we're at it, fix the types
    of some of the variables that end up getting returns from these
    functions.

    Acked-by: Pavel Shilovsky
    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French

    Jeff Layton
     
  • Reviewed-by: Suresh Jayaraman
    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French

    Jeff Layton
     

27 Oct, 2010

2 commits

  • Mark dependency on crypto modules in Kconfig.

    Defining per structures sdesc and cifs_secmech which are used to store
    crypto hash functions and contexts. They are stored per smb connection
    and used for all auth mechs to genereate hash values and signatures.

    Allocate crypto hashing functions, security descriptiors, and respective
    contexts when a smb/tcp connection is established.
    Release them when a tcp/smb connection is taken down.

    md5 and hmac-md5 are two crypto hashing functions that are used
    throught the life of an smb/tcp connection by various functions that
    calcualte signagure and ntlmv2 hash, HMAC etc.

    structure ntlmssp_auth is defined as per smb connection.

    ntlmssp_auth holds ciphertext which is genereated by rc4/arc4 encryption of
    secondary key, a nonce using ntlmv2 session key and sent in the session key
    field of the type 3 message sent by the client during ntlmssp
    negotiation/exchange

    A key is exchanged with the server if client indicates so in flags in
    type 1 messsage and server agrees in flag in type 2 message of ntlmssp
    negotiation. If both client and agree, a key sent by client in
    type 3 message of ntlmssp negotiation in the session key field.
    The key is a ciphertext generated off of secondary key, a nonce, using
    ntlmv2 hash via rc4/arc4.

    Signing works for ntlmssp in this patch. The sequence number within
    the server structure needs to be zero until session is established
    i.e. till type 3 packet of ntlmssp exchange of a to be very first
    smb session on that smb connection is sent.

    Acked-by: Jeff Layton
    Signed-off-by: Shirish Pargaonkar
    Signed-off-by: Steve French

    Shirish Pargaonkar
     
  • Start calculating auth response within a session. Move/Add pertinet
    data structures like session key, server challenge and ntlmv2_hash in
    a session structure. We should do the calculations within a session
    before copying session key and response over to server data
    structures because a session setup can fail.

    Only after a very first smb session succeeds, it copy/make its
    session key, session key of smb connection. This key stays with
    the smb connection throughout its life.
    sequence_number within server is set to 0x2.

    The authentication Message Authentication Key (mak) which consists
    of session key followed by client response within structure session_key
    is now dynamic. Every authentication type allocates the key + response
    sized memory within its session structure and later either assigns or
    frees it once the client response is sent and if session's session key
    becomes connetion's session key.

    ntlm/ntlmi authentication functions are rearranged. A function
    named setup_ntlm_resp(), similar to setup_ntlmv2_resp(), replaces
    function cifs_calculate_session_key().

    size of CIFS_SESS_KEY_SIZE is changed to 16, to reflect the byte size
    of the key it holds.

    Reviewed-by: Jeff Layton
    Signed-off-by: Shirish Pargaonkar
    Signed-off-by: Steve French

    Shirish Pargaonkar
     

30 Sep, 2010

1 commit

  • Attribue Value (AV) pairs or Target Info (TI) pairs are part of
    ntlmv2 authentication.
    Structure ntlmv2_resp had only definition for two av pairs.
    So removed it, and now allocation of av pairs is dynamic.
    For servers like Windows 7/2008, av pairs sent by server in
    challege packet (type 2 in the ntlmssp exchange/negotiation) can
    vary.

    Server sends them during ntlmssp negotiation. So when ntlmssp is used
    as an authentication mechanism, type 2 challenge packet from server
    has this information. Pluck it and use the entire blob for
    authenticaiton purpose. If user has not specified, extract
    (netbios) domain name from the av pairs which is used to calculate
    ntlmv2 hash. Servers like Windows 7 are particular about the AV pair
    blob.

    Servers like Windows 2003, are not very strict about the contents
    of av pair blob used during ntlmv2 authentication.
    So when security mechanism such as ntlmv2 is used (not ntlmv2 in ntlmssp),
    there is no negotiation and so genereate a minimal blob that gets
    used in ntlmv2 authentication as well as gets sent.

    Fields tilen and tilbob are session specific. AV pair values are defined.

    To calculate ntlmv2 response we need ti/av pair blob.

    For sec mech like ntlmssp, the blob is plucked from type 2 response from
    the server. From this blob, netbios name of the domain is retrieved,
    if user has not already provided, to be included in the Target String
    as part of ntlmv2 hash calculations.

    For sec mech like ntlmv2, create a minimal, two av pair blob.

    The allocated blob is freed in case of error. In case there is no error,
    this blob is used in calculating ntlmv2 response (in CalcNTLMv2_response)
    and is also copied on the response to the server, and then freed.

    The type 3 ntlmssp response is prepared on a buffer,
    5 * sizeof of struct _AUTHENTICATE_MESSAGE, an empirical value large
    enough to hold _AUTHENTICATE_MESSAGE plus a blob with max possible
    10 values as part of ntlmv2 response and lmv2 keys and domain, user,
    workstation names etc.

    Also, kerberos gets selected as a default mechanism if server supports it,
    over the other security mechanisms.

    Signed-off-by: Shirish Pargaonkar
    Signed-off-by: Steve French

    Shirish Pargaonkar
     

09 Sep, 2010

1 commit

  • This reverts commit 9fbc590860e75785bdaf8b83e48fabfe4d4f7d58.

    The change to kernel crypto and fixes to ntlvm2 and ntlmssp
    series, introduced a regression. Deferring this patch series
    to 2.6.37 after Shirish fixes it.

    Signed-off-by: Steve French
    Acked-by: Jeff Layton
    CC: Shirish Pargaonkar

    Steve French
     

21 Aug, 2010

1 commit

  • Make ntlmv2 as an authentication mechanism within ntlmssp
    instead of ntlmv1.
    Parse type 2 response in ntlmssp negotiation to pluck
    AV pairs and use them to calculate ntlmv2 response token.
    Also, assign domain name from the sever response in type 2
    packet of ntlmssp and use that (netbios) domain name in
    calculation of response.

    Enable cifs/smb signing using rc4 and md5.

    Changed name of the structure mac_key to session_key to reflect
    the type of key it holds.

    Use kernel crypto_shash_* APIs instead of the equivalent cifs functions.

    Signed-off-by: Shirish Pargaonkar
    Acked-by: Herbert Xu
    Signed-off-by: Steve French

    Steve French
     

24 Feb, 2010

1 commit


05 Dec, 2009

1 commit


02 Jul, 2009

1 commit

  • cifs: add new cifs_iget function and convert unix codepath to use it

    In order to unify some codepaths, introduce a common cifs_fattr struct
    for storing inode attributes. The different codepaths (unix, legacy,
    normal, etc...) can fill out this struct with inode info. It can then be
    passed as an arg to a common set of routines to get and update inodes.

    Add a new cifs_iget function that uses iget5_locked to identify inodes.
    This will compare inodes based on the uniqueid value in a cifs_fattr
    struct.

    Rather than filling out an already-created inode, have
    cifs_get_inode_info_unix instead fill out cifs_fattr and hand that off
    to cifs_iget. cifs_iget can then properly look for hardlinked inodes.

    On the readdir side, add a new cifs_readdir_lookup function that spawns
    populated dentries. Redefine FILE_UNIX_INFO so that it's basically a
    FILE_UNIX_BASIC_INFO that has a few fields wrapped around it. This
    allows us to more easily use the same function for filling out the fattr
    as the non-readdir codepath.

    With this, we should then have proper hardlink detection and can
    eventually get rid of some nasty CIFS-specific hacks for handing them.

    Signed-off-by: Jeff Layton
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Steve French

    Jeff Layton
     

17 Apr, 2009

1 commit

  • Jeff made a good point that we should endian convert the UniqueId when we use
    it to set i_ino Even though this value is opaque to the client, when comparing
    the inode numbers of the same server file from two different clients (one
    big endian, one little endian) or when we compare a big endian client's view
    of i_ino with what the server thinks - we should get the same value

    Signed-off-by: Steve French

    Steve French
     

12 Mar, 2009

3 commits

  • There are about 60 fsctl calls which Windows claims would be able
    to be sent remotely and handled by the server. This adds the #defines
    for them. A few of them look immediately useful, but need to also
    add the structure definitions for them so they can be sent as SMBs.

    Signed-off-by: Steve French

    Steve French
     
  • Also updates some DFS flag definitions

    Signed-off-by: Steve French

    Steve French
     
  • In contrast to the now-obsolete smbfs, cifs does not send SMB_COM_FLUSH
    in response to an explicit fsync(2) to guarantee that all volatile data
    is written to stable storage on the server side, provided the server
    honors the request (which, to my knowledge, is true for Windows and
    Samba with 'strict sync' enabled).
    This patch modifies the cifs_fsync implementation to restore the
    fsync-behavior of smbfs by triggering SMB_COM_FLUSH after sending
    outstanding data on the client side to the server.

    Signed-off-by: Horst Reiterer
    Acked-by: Jeff Layton
    Signed-off-by: Steve French

    Steve French
     

26 Dec, 2008

1 commit