30 Oct, 2011

1 commit

  • Re-posting a patch originally posted by Oskar Liljeblad after
    rebasing on 3.2.

    Modify cifs to assume that the supplied password is encoded according
    to iocharset. Before this patch passwords would be treated as
    raw 8-bit data, which made authentication with Unicode passwords impossible
    (at least passwords with characters > 0xFF).

    The previous code would as a side effect accept passwords encoded with
    ISO 8859-1, since Unicode < 0x100 basically is ISO 8859-1. Software which
    relies on that will no longer support password chars > 0x7F unless it also
    uses iocharset=iso8859-1. (mount.cifs does not care about the encoding so
    it will work as expected.)

    Signed-off-by: Oskar Liljeblad
    Signed-off-by: Shirish Pargaonkar
    Reviewed-by: Pavel Shilovsky
    Tested-by: A
    Signed-off-by: Steve French

    Shirish Pargaonkar
     

13 Oct, 2011

2 commits


20 Sep, 2011

1 commit

  • Fix sec=ntlmv2/i authentication option during mount of Samba shares.

    cifs client was coding ntlmv2 response incorrectly.
    All that is needed in temp as specified in MS-NLMP seciton 3.3.2

    "Define ComputeResponse(NegFlg, ResponseKeyNT, ResponseKeyLM,
    CHALLENGE_MESSAGE.ServerChallenge, ClientChallenge, Time, ServerName)

    as
    Set temp to ConcatenationOf(Responserversion, HiResponserversion,
    Z(6), Time, ClientChallenge, Z(4), ServerName, Z(4)"

    is MsvAvNbDomainName.

    For sec=ntlmsspi, build_av_pair is not used, a blob is plucked from
    type 2 response sent by the server to use in authentication.

    I tested sec=ntlmv2/i and sec=ntlmssp/i mount options against
    Samba (3.6) and Windows - XP, 2003 Server and 7.
    They all worked.

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

    Shirish Pargaonkar
     

01 Aug, 2011

1 commit

  • Sniffing traffic on the wire shows that windows clients send a zeroed
    out signature field in a NEGOTIATE request, and send "BSRSPYL" in the
    signature field during SESSION_SETUP. Make the cifs client behave the
    same way.

    It doesn't seem to make much difference in any server that I've tested
    against, but it's probably best to follow windows behavior as closely as
    possible here.

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

    Jeff Layton
     

26 Jul, 2011

1 commit


07 Jun, 2011

1 commit

  • When signing is enabled, the first session that's established on a
    socket will cause a printk like this to pop:

    CIFS VFS: Unexpected SMB signature

    This is because the key exchange hasn't happened yet, so the signature
    field is bogus. Don't try to check the signature on the socket until the
    first session has been established. Also, eliminate the specific check
    for SMB_COM_NEGOTIATE since this check covers that case too.

    Cc: stable@kernel.org
    Cc: Shirish Pargaonkar
    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French

    Jeff Layton
     

27 May, 2011

1 commit


19 May, 2011

2 commits

  • 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
     
  • local cifs functions (repost)

    Using kernel crypto APIs for DES encryption during LM and NT hash generation
    instead of local functions within cifs.
    Source file smbdes.c is deleted sans four functions, one of which
    uses ecb des functionality provided by kernel crypto APIs.

    Remove function SMBOWFencrypt.

    Add return codes to various functions such as calc_lanman_hash,
    SMBencrypt, and SMBNTencrypt. Includes fix noticed by Dan Carpenter.

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

    Steve French
     

12 Apr, 2011

2 commits

  • While testing my patchset to fix asynchronous writes, I hit a bunch
    of signature problems when testing with signing on. The problem seems
    to be that signature checks on receive can be running at the same
    time as a process that is sending, or even that multiple receives can
    be checking signatures at the same time, clobbering the same data
    structures.

    While we're at it, clean up the comments over cifs_calculate_signature
    and add a note that the srv_mutex should be held when calling this
    function.

    This patch seems to fix the problems for me, but I'm not clear on
    whether it's the best approach. If it is, then this should probably
    go to stable too.

    Cc: stable@kernel.org
    Cc: Shirish Pargaonkar
    Signed-off-by: Jeff Layton
    Signed-off-by: Steve French

    Jeff Layton
     
  • We artificially limited the user name to 32 bytes, but modern servers handle
    larger. Set the maximum length to a reasonable 256, and make the user name
    string dynamically allocated rather than a fixed size in session structure.
    Also clean up old checkpatch warning.

    Signed-off-by: Steve French

    Steve French
     

01 Feb, 2011

1 commit


28 Jan, 2011

1 commit

  • Replaced md4 hashing function local to cifs module with kernel crypto APIs.
    As a result, md4 hashing function and its supporting functions in
    file md4.c are not needed anymore.

    Cleaned up function declarations, removed forward function declarations,
    and removed a header file that is being deleted from being included.

    Verified that sec=ntlm/i, sec=ntlmv2/i, and sec=ntlmssp/i work correctly.

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

    Shirish Pargaonkar
     

26 Jan, 2011

1 commit


10 Jan, 2011

1 commit


29 Oct, 2010

2 commits

  • Removed following fields from smb session structure
    cryptkey, ntlmv2_hash, tilen, tiblob
    and ntlmssp_auth structure is allocated dynamically only if the auth mech
    in NTLMSSP.

    response field within a session_key structure is used to initially store the
    target info (either plucked from type 2 challenge packet in case of NTLMSSP
    or fabricated in case of NTLMv2 without extended security) and then to store
    Message Authentication Key (mak) (session key + client response).

    Server challenge or cryptkey needed during a NTLMSSP authentication
    is now part of ntlmssp_auth structure which gets allocated and freed
    once authenticaiton process is done.

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

    Shirish Pargaonkar
     
  • Need to have cryptkey or server challenge in smb connection
    (struct TCP_Server_Info) for ntlm and ntlmv2 auth types for which
    cryptkey (Encryption Key) is supplied just once in Negotiate Protocol
    response during an smb connection setup for all the smb sessions over
    that smb connection.

    For ntlmssp, cryptkey or server challenge is provided for every
    smb session in type 2 packet of ntlmssp negotiation, the cryptkey
    provided during Negotiation Protocol response before smb connection
    does not count.

    Rename cryptKey to cryptkey and related changes.

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

    Shirish Pargaonkar
     

27 Oct, 2010

4 commits

  • Minor cleanup - Fix spelling mistake, make meaningful (goto) label

    In function setup_ntlmv2_rsp(), do not return 0 and leak memory,
    let the tiblob get freed.

    For function find_domain_name(), pass already available nls table pointer
    instead of loading and unloading the table again in this function.

    For ntlmv2, the case sensitive password length is the length of the
    response, so subtract session key length (16 bytes) from the .len.

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

    Shirish Pargaonkar
     
  • Use kernel crypto sync hash apis insetead of cifs crypto functions.
    The calls typically corrospond one to one except that insead of
    key init, setkey is used.

    Use crypto apis to generate smb signagtures also.
    Use hmac-md5 to genereate ntlmv2 hash, ntlmv2 response, and HMAC (CR1 of
    ntlmv2 auth blob.
    User crypto apis to genereate signature and to verify signature.
    md5 hash is used to calculate signature.
    Use secondary key to calculate signature in case of ntlmssp.

    For ntlmv2 within ntlmssp, during signature calculation, only 16 bytes key
    (a nonce) stored within session key is used. during smb signature calculation.
    For ntlm and ntlmv2 without extended security, 16 bytes key
    as well as entire response (24 bytes in case of ntlm and variable length
    in case of ntlmv2) is used for smb signature calculation.
    For kerberos, there is no distinction between key and response.

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

    Shirish Pargaonkar
     
  • 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
     

15 Oct, 2010

1 commit

  • Start calculation 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 copies/makes its
    session key, session key of smb connection. This key stays with
    the smb connection throughout its life.

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

    Shirish Pargaonkar
     

12 Oct, 2010

1 commit


08 Oct, 2010

1 commit


30 Sep, 2010

2 commits

  • 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
     
  • Change name of variable mac_key to session key.
    The reason mac_key was changed to session key is, this structure does not
    hold message authentication code, it holds the session key (for ntlmv2,
    ntlmv1 etc.). mac is generated as a signature in cifs_calc* functions.

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

    Shirish Pargaonkar
     

09 Sep, 2010

4 commits


25 Aug, 2010

1 commit

  • Eliminiate sparse warning during usage of crypto_shash_* APIs
    error: bad constant expression

    Allocate memory for shash descriptors once, so that we do not kmalloc/kfree it
    for every signature generation (shash descriptor for md5 hash).

    From ed7538619817777decc44b5660b52268077b74f3 Mon Sep 17 00:00:00 2001
    From: Shirish Pargaonkar
    Date: Tue, 24 Aug 2010 11:47:43 -0500
    Subject: [PATCH] eliminate sparse warnings during crypto_shash_* APis usage

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

    shirishpargaonkar@gmail.com
     

24 Aug, 2010

1 commit


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
     

27 Apr, 2010

1 commit


21 Apr, 2010

1 commit

  • Neaten cERROR and cFYI macros, reduce text space
    ~2.5K

    Convert '__FILE__ ": " fmt' to '"%s: " fmt', __FILE__' to save text space
    Surround macros with do {} while
    Add parentheses to macros
    Make statement expression macro from macro with assign
    Remove now unnecessary parentheses from cFYI and cERROR uses

    defconfig with CIFS support old
    $ size fs/cifs/built-in.o
    text data bss dec hex filename
    156012 1760 148 157920 268e0 fs/cifs/built-in.o

    defconfig with CIFS support old
    $ size fs/cifs/built-in.o
    text data bss dec hex filename
    153508 1760 148 155416 25f18 fs/cifs/built-in.o

    allyesconfig old:
    $ size fs/cifs/built-in.o
    text data bss dec hex filename
    309138 3864 74824 387826 5eaf2 fs/cifs/built-in.o

    allyesconfig new
    $ size fs/cifs/built-in.o
    text data bss dec hex filename
    305655 3864 74824 384343 5dd57 fs/cifs/built-in.o

    Signed-off-by: Joe Perches
    Signed-off-by: Steve French

    Joe Perches
     

30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

02 Sep, 2009

1 commit

  • in function calc_ntlmv2_hash memory is not released.
    1. If in the line 333 we successfully allocate memory and assign it to
    pctxt variable:
    pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL);
    then we go to line 376 and exit wihout releasing memory pointed to by pctxt
    variable.

    Add a memory releasing for pctxt variable before exit from function
    calc_ntlmv2_hash.

    Signed-off-by: Alexander Strakh
    Signed-off-by: Steve French

    Alexander Strakh
     

29 Jan, 2009

1 commit

  • When rt modules were added they (each) included their own md5
    with names which collided with the existing names of cifs's md5 functions.

    Renaming cifs's md5 modules so we don't collide with them.

    > Stephen Rothwell wrote:
    > When CIFS is built-in (=y) and staging/rt28[67]0 =y, there are multiple
    > definitions of:
    >
    > build-r8250.out:(.text+0x1d8ad0): multiple definition of `MD5Init'
    > build-r8250.out:(.text+0x1dbb30): multiple definition of `MD5Update'
    > build-r8250.out:(.text+0x1db9b0): multiple definition of `MD5Final'
    >
    > all of which need to have more unique identifiers for their global
    > symbols (e.g., rt28_md5_init, cifs_md5_init, foo, blah, bar).
    >

    CC: Greg K-H
    Signed-off-by: Steve French

    Steve French
     

26 Dec, 2008

1 commit

  • cifs: have calc_lanman_hash take more granular args

    We need to use this routine to encrypt passwords associated with the
    tcon too. Don't assume that the password will be attached to the
    smb_session.

    Also, make some of the values in the lower encryption functions
    const since they aren't changed.

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

    Jeff Layton