diff options
author | Shirish Pargaonkar <shirishpargaonkar@gmail.com> | 2013-08-29 09:35:09 -0400 |
---|---|---|
committer | Steve French <smfrench@gmail.com> | 2013-09-08 15:47:47 -0400 |
commit | d4e63bd6e40da30e965e8947b98ba75c6b973c62 (patch) | |
tree | 4f17bdbe75843ac578a9a9e1ee491192dd280d73 /fs/cifs | |
parent | 31f92e9a87553d9d3044fe97b5fe0247e4314773 (diff) |
cifs: Process post session setup code in respective dialect functions.
Move the post (successful) session setup code to respective dialect routines.
For smb1, session key is per smb connection.
For smb2/smb3, session key is per smb session.
If client and server do not require signing, free session key for smb1/2/3.
If client and server require signing
smb1 - Copy (kmemdup) session key for the first session to connection.
Free session key of that and subsequent sessions on this connection.
smb2 - For every session, keep the session key and free it when the
session is being shutdown.
smb3 - For every session, generate the smb3 signing key using the session key
and then free the session key.
There are two unrelated line formatting changes as well.
Reviewed-by: Jeff Layton <jlayton@samba.org>
Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs/cifs')
-rw-r--r-- | fs/cifs/connect.c | 27 | ||||
-rw-r--r-- | fs/cifs/misc.c | 1 | ||||
-rw-r--r-- | fs/cifs/sess.c | 40 | ||||
-rw-r--r-- | fs/cifs/smb2pdu.c | 31 |
4 files changed, 70 insertions, 29 deletions
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index b1bab99be83b..688f48ec9abc 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -3828,33 +3828,8 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, | |||
3828 | if (server->ops->sess_setup) | 3828 | if (server->ops->sess_setup) |
3829 | rc = server->ops->sess_setup(xid, ses, nls_info); | 3829 | rc = server->ops->sess_setup(xid, ses, nls_info); |
3830 | 3830 | ||
3831 | if (rc) { | 3831 | if (rc) |
3832 | cifs_dbg(VFS, "Send error in SessSetup = %d\n", rc); | 3832 | cifs_dbg(VFS, "Send error in SessSetup = %d\n", rc); |
3833 | } else { | ||
3834 | mutex_lock(&server->srv_mutex); | ||
3835 | if (!server->session_estab) { | ||
3836 | server->session_key.response = ses->auth_key.response; | ||
3837 | server->session_key.len = ses->auth_key.len; | ||
3838 | server->sequence_number = 0x2; | ||
3839 | server->session_estab = true; | ||
3840 | ses->auth_key.response = NULL; | ||
3841 | if (server->ops->generate_signingkey) | ||
3842 | server->ops->generate_signingkey(server); | ||
3843 | } | ||
3844 | mutex_unlock(&server->srv_mutex); | ||
3845 | |||
3846 | cifs_dbg(FYI, "CIFS Session Established successfully\n"); | ||
3847 | spin_lock(&GlobalMid_Lock); | ||
3848 | ses->status = CifsGood; | ||
3849 | ses->need_reconnect = false; | ||
3850 | spin_unlock(&GlobalMid_Lock); | ||
3851 | } | ||
3852 | |||
3853 | kfree(ses->auth_key.response); | ||
3854 | ses->auth_key.response = NULL; | ||
3855 | ses->auth_key.len = 0; | ||
3856 | kfree(ses->ntlmssp); | ||
3857 | ses->ntlmssp = NULL; | ||
3858 | 3833 | ||
3859 | return rc; | 3834 | return rc; |
3860 | } | 3835 | } |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index f7d4b2285efe..82a2b9fb528a 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -105,6 +105,7 @@ sesInfoFree(struct cifs_ses *buf_to_free) | |||
105 | } | 105 | } |
106 | kfree(buf_to_free->user_name); | 106 | kfree(buf_to_free->user_name); |
107 | kfree(buf_to_free->domainName); | 107 | kfree(buf_to_free->domainName); |
108 | kfree(buf_to_free->auth_key.response); | ||
108 | kfree(buf_to_free); | 109 | kfree(buf_to_free); |
109 | } | 110 | } |
110 | 111 | ||
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index a0a62db0f575..acea6c4ded47 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -629,7 +629,8 @@ CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, | |||
629 | type = select_sectype(ses->server, ses->sectype); | 629 | type = select_sectype(ses->server, ses->sectype); |
630 | cifs_dbg(FYI, "sess setup type %d\n", type); | 630 | cifs_dbg(FYI, "sess setup type %d\n", type); |
631 | if (type == Unspecified) { | 631 | if (type == Unspecified) { |
632 | cifs_dbg(VFS, "Unable to select appropriate authentication method!"); | 632 | cifs_dbg(VFS, |
633 | "Unable to select appropriate authentication method!"); | ||
633 | return -EINVAL; | 634 | return -EINVAL; |
634 | } | 635 | } |
635 | 636 | ||
@@ -815,8 +816,9 @@ ssetup_ntlmssp_authenticate: | |||
815 | ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, | 816 | ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, |
816 | GFP_KERNEL); | 817 | GFP_KERNEL); |
817 | if (!ses->auth_key.response) { | 818 | if (!ses->auth_key.response) { |
818 | cifs_dbg(VFS, "Kerberos can't allocate (%u bytes) memory", | 819 | cifs_dbg(VFS, |
819 | msg->sesskey_len); | 820 | "Kerberos can't allocate (%u bytes) memory", |
821 | msg->sesskey_len); | ||
820 | rc = -ENOMEM; | 822 | rc = -ENOMEM; |
821 | goto ssetup_exit; | 823 | goto ssetup_exit; |
822 | } | 824 | } |
@@ -1005,5 +1007,37 @@ ssetup_exit: | |||
1005 | if ((phase == NtLmChallenge) && (rc == 0)) | 1007 | if ((phase == NtLmChallenge) && (rc == 0)) |
1006 | goto ssetup_ntlmssp_authenticate; | 1008 | goto ssetup_ntlmssp_authenticate; |
1007 | 1009 | ||
1010 | if (!rc) { | ||
1011 | mutex_lock(&ses->server->srv_mutex); | ||
1012 | if (!ses->server->session_estab) { | ||
1013 | if (ses->server->sign) { | ||
1014 | ses->server->session_key.response = | ||
1015 | kmemdup(ses->auth_key.response, | ||
1016 | ses->auth_key.len, GFP_KERNEL); | ||
1017 | if (!ses->server->session_key.response) { | ||
1018 | rc = -ENOMEM; | ||
1019 | mutex_unlock(&ses->server->srv_mutex); | ||
1020 | goto keycp_exit; | ||
1021 | } | ||
1022 | ses->server->session_key.len = | ||
1023 | ses->auth_key.len; | ||
1024 | } | ||
1025 | ses->server->sequence_number = 0x2; | ||
1026 | ses->server->session_estab = true; | ||
1027 | } | ||
1028 | mutex_unlock(&ses->server->srv_mutex); | ||
1029 | |||
1030 | cifs_dbg(FYI, "CIFS session established successfully\n"); | ||
1031 | spin_lock(&GlobalMid_Lock); | ||
1032 | ses->status = CifsGood; | ||
1033 | ses->need_reconnect = false; | ||
1034 | spin_unlock(&GlobalMid_Lock); | ||
1035 | } | ||
1036 | |||
1037 | keycp_exit: | ||
1038 | kfree(ses->auth_key.response); | ||
1039 | ses->auth_key.response = NULL; | ||
1040 | kfree(ses->ntlmssp); | ||
1041 | |||
1008 | return rc; | 1042 | return rc; |
1009 | } | 1043 | } |
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 7d56a5ca2abb..f56cf99e027a 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c | |||
@@ -478,6 +478,13 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses, | |||
478 | } | 478 | } |
479 | 479 | ||
480 | /* | 480 | /* |
481 | * If we are here due to reconnect, free per-smb session key | ||
482 | * in case signing was required. | ||
483 | */ | ||
484 | kfree(ses->auth_key.response); | ||
485 | ses->auth_key.response = NULL; | ||
486 | |||
487 | /* | ||
481 | * If memory allocation is successful, caller of this function | 488 | * If memory allocation is successful, caller of this function |
482 | * frees it. | 489 | * frees it. |
483 | */ | 490 | */ |
@@ -628,6 +635,30 @@ ssetup_exit: | |||
628 | /* if ntlmssp, and negotiate succeeded, proceed to authenticate phase */ | 635 | /* if ntlmssp, and negotiate succeeded, proceed to authenticate phase */ |
629 | if ((phase == NtLmChallenge) && (rc == 0)) | 636 | if ((phase == NtLmChallenge) && (rc == 0)) |
630 | goto ssetup_ntlmssp_authenticate; | 637 | goto ssetup_ntlmssp_authenticate; |
638 | |||
639 | if (!rc) { | ||
640 | mutex_lock(&server->srv_mutex); | ||
641 | if (!server->session_estab) { | ||
642 | server->sequence_number = 0x2; | ||
643 | server->session_estab = true; | ||
644 | if (server->ops->generate_signingkey) | ||
645 | server->ops->generate_signingkey(server); | ||
646 | } | ||
647 | mutex_unlock(&server->srv_mutex); | ||
648 | |||
649 | cifs_dbg(FYI, "SMB2/3 session established successfully\n"); | ||
650 | spin_lock(&GlobalMid_Lock); | ||
651 | ses->status = CifsGood; | ||
652 | ses->need_reconnect = false; | ||
653 | spin_unlock(&GlobalMid_Lock); | ||
654 | } | ||
655 | |||
656 | if (!server->sign) { | ||
657 | kfree(ses->auth_key.response); | ||
658 | ses->auth_key.response = NULL; | ||
659 | } | ||
660 | kfree(ses->ntlmssp); | ||
661 | |||
631 | return rc; | 662 | return rc; |
632 | } | 663 | } |
633 | 664 | ||