Skip to contentSkip to conversation

smb: client: fix broken multichannel with krb5+signing

PATCH In review Paulo Alcantara 3 participants 3 messages Feb 26

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 smb: client: fix broken multichannel with krb5+signing

When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.

Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in SMB2_auth_kerberos().

Repro:

$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i
$ sleep 5
$ umount /mnt
$ dmesg
  ...
  CIFS: VFS: sign fail cmd 0x5 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
  CIFS: VFS: sign fail cmd 0x5 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
  CIFS: VFS: sign fail cmd 0x4 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
---
 fs/smb/client/smb2pdu.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
fs/smb/client/smb2pdu.c +10 -12
index a2a96d817717..04e361ed2356 100644
@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
 	is_binding = (ses->ses_status == SES_GOOD);
 	spin_unlock(&ses->ses_lock);
 
-	/* keep session key if binding */
-	if (!is_binding) {
-		kfree_sensitive(ses->auth_key.response);
-		ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
-						 GFP_KERNEL);
-		if (!ses->auth_key.response) {
-			cifs_dbg(VFS, "Kerberos can't allocate (%u bytes) memory\n",
-				 msg->sesskey_len);
-			rc = -ENOMEM;
-			goto out_put_spnego_key;
-		}
-		ses->auth_key.len = msg->sesskey_len;
+	kfree_sensitive(ses->auth_key.response);
+	ses->auth_key.response = kmemdup(msg->data,
+					 msg->sesskey_len,
+					 GFP_KERNEL);
+	if (!ses->auth_key.response) {
+		cifs_dbg(VFS, "%s: can't allocate (%u bytes) memory\n",
+			 __func__, msg->sesskey_len);
+		rc = -ENOMEM;
+		goto out_put_spnego_key;
 	}
+	ses->auth_key.len = msg->sesskey_len;
 
 	sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
 	sess_data->iov[1].iov_len = msg->secblob_len;
Signature · 1 line
2.53.0
#1 lore raw

added Cc:stable and tentatively merged into cifs-2.6.git pending more review and testing

Quoted 69 lines · Paulo Alcantara

When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.

Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in SMB2_auth_kerberos().

Repro:

$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i
$ sleep 5
$ umount /mnt
$ dmesg
  ...
  CIFS: VFS: sign fail cmd 0x5 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
  CIFS: VFS: sign fail cmd 0x5 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
  CIFS: VFS: sign fail cmd 0x4 message id 0x2
  CIFS: VFS: \\srv SMB signature verification returned error = -13
---
 fs/smb/client/smb2pdu.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
fs/smb/client/smb2pdu.c +10 -13
index a2a96d817717..04e361ed2356 100644
@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
        is_binding = (ses->ses_status == SES_GOOD);
        spin_unlock(&ses->ses_lock);
 
-       /* keep session key if binding */
-       if (!is_binding) {
-               kfree_sensitive(ses->auth_key.response);
-               ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
-                                                GFP_KERNEL);
-               if (!ses->auth_key.response) {
-                       cifs_dbg(VFS, "Kerberos can't allocate (%u bytes) memory\n",
-                                msg->sesskey_len);
-                       rc = -ENOMEM;
-                       goto out_put_spnego_key;
-               }
-               ses->auth_key.len = msg->sesskey_len;
+       kfree_sensitive(ses->auth_key.response);
+       ses->auth_key.response = kmemdup(msg->data,
+                                        msg->sesskey_len,
+                                        GFP_KERNEL);
+       if (!ses->auth_key.response) {
+               cifs_dbg(VFS, "%s: can't allocate (%u bytes) memory\n",
+                        __func__, msg->sesskey_len);
+               rc = -ENOMEM;
+               goto out_put_spnego_key;
        }
+       ses->auth_key.len = msg->sesskey_len;
 
        sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
        sess_data->iov[1].iov_len = msg->secblob_len;
--

2.53.0

Signature · 3 lines
Thanks,

Steve
Reviewed-by on v1 1/1
#2 lore raw
In reply to Paulo Alcantara
Quoted 55 lines · Paulo Alcantara

When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.

Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in SMB2_auth_kerberos().

Repro:

$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i
$ sleep 5
$ umount /mnt
$ dmesg
 ...
 CIFS: VFS: sign fail cmd 0x5 message id 0x2
 CIFS: VFS: \\srv SMB signature verification returned error = -13
 CIFS: VFS: sign fail cmd 0x5 message id 0x2
 CIFS: VFS: \\srv SMB signature verification returned error = -13
 CIFS: VFS: sign fail cmd 0x4 message id 0x2
 CIFS: VFS: \\srv SMB signature verification returned error = -13

---
fs/smb/client/smb2pdu.c | 22 ++++++++++------------

1 file changed, 10 insertions(+), 12 deletions(-)
fs/smb/client/smb2pdu.c +4 -12
index a2a96d817717..04e361ed2356 100644
@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
 	is_binding = (ses->ses_status == SES_GOOD);
 	spin_unlock(&ses->ses_lock);
 
-	/* keep session key if binding */
-	if (!is_binding) {
-		kfree_sensitive(ses->auth_key.response);
-		ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
-						 GFP_KERNEL);
-		if (!ses->auth_key.response) {
-			cifs_dbg(VFS, "Kerberos can't allocate (%u bytes) memory\n",
-				 msg->sesskey_len);
-			rc = -ENOMEM;
-			goto out_put_spnego_key;
-		}
-		ses->auth_key.len = msg->sesskey_len;
+	kfree_sensitive(ses->auth_key.response);
+	ses->auth_key.response = kmemdup(msg->data,
+					 msg->sesskey_len,
+					 GFP_KERNEL);

fs/smb/client/smb2pdu.c SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) · line 1730

Quoted 10 lines
fs/smb/client/smb2pdu.c +6 -0
+	if (!ses->auth_key.response) {
+		cifs_dbg(VFS, "%s: can't allocate (%u bytes) memory\n",
+			 __func__, msg->sesskey_len);
+		rc = -ENOMEM;
+		goto out_put_spnego_key;
 	}
+	ses->auth_key.len = msg->sesskey_len;
 
 	sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
 	sess_data->iov[1].iov_len = msg->secblob_len;

You can drop the same check for SessionId/Flags right below, as the server is expected to return the same values for those for multichannel.

(which then means 'is_binding' can be dropped altogether).

Either way,