Skip to content

Commit aa22ebc

Browse files
committed
smb3.1.1: allow dumping GCM256 keys to improve debugging of encrypted shares
Previously we were only able to dump CCM or GCM-128 keys (see "smbinfo keys" e.g.) to allow network debugging (e.g. wireshark) of mounts to SMB3.1.1 encrypted shares. But with the addition of GCM-256 support, we have to be able to dump 32 byte instead of 16 byte keys which requires adding an additional ioctl for that. Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 087f757 commit aa22ebc

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

fs/cifs/cifs_ioctl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ struct smb_query_info {
5757
/* char buffer[]; */
5858
} __packed;
5959

60+
/*
61+
* Dumping the commonly used 16 byte (e.g. CCM and GCM128) keys still supported
62+
* for backlevel compatibility, but is not sufficient for dumping the less
63+
* frequently used GCM256 (32 byte) keys (see the newer "CIFS_DUMP_FULL_KEY"
64+
* ioctl for dumping decryption info for GCM256 mounts)
65+
*/
6066
struct smb3_key_debug_info {
6167
__u64 Suid;
6268
__u16 cipher_type;
@@ -65,6 +71,18 @@ struct smb3_key_debug_info {
6571
__u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE];
6672
} __packed;
6773

74+
/*
75+
* Dump full key (32 byte encrypt/decrypt keys instead of 16 bytes)
76+
* is needed if GCM256 (stronger encryption) negotiated
77+
*/
78+
struct smb3_full_key_debug_info {
79+
__u64 Suid;
80+
__u16 cipher_type;
81+
__u8 auth_key[16]; /* SMB2_NTLMV2_SESSKEY_SIZE */
82+
__u8 smb3encryptionkey[32]; /* SMB3_ENC_DEC_KEY_SIZE */
83+
__u8 smb3decryptionkey[32]; /* SMB3_ENC_DEC_KEY_SIZE */
84+
} __packed;
85+
6886
struct smb3_notify {
6987
__u32 completion_filter;
7088
bool watch_tree;
@@ -78,6 +96,7 @@ struct smb3_notify {
7896
#define CIFS_QUERY_INFO _IOWR(CIFS_IOCTL_MAGIC, 7, struct smb_query_info)
7997
#define CIFS_DUMP_KEY _IOWR(CIFS_IOCTL_MAGIC, 8, struct smb3_key_debug_info)
8098
#define CIFS_IOC_NOTIFY _IOW(CIFS_IOCTL_MAGIC, 9, struct smb3_notify)
99+
#define CIFS_DUMP_FULL_KEY _IOWR(CIFS_IOCTL_MAGIC, 10, struct smb3_full_key_debug_info)
81100
#define CIFS_IOC_SHUTDOWN _IOR ('X', 125, __u32)
82101

83102
/*

fs/cifs/ioctl.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
218218
{
219219
struct inode *inode = file_inode(filep);
220220
struct smb3_key_debug_info pkey_inf;
221+
struct smb3_full_key_debug_info pfull_key_inf;
221222
int rc = -ENOTTY; /* strange error - but the precedent */
222223
unsigned int xid;
223224
struct cifsFileInfo *pSMBFile = filep->private_data;
@@ -354,6 +355,38 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
354355
else
355356
rc = 0;
356357
break;
358+
/*
359+
* Dump full key (32 bytes instead of 16 bytes) is
360+
* needed if GCM256 (stronger encryption) negotiated
361+
*/
362+
case CIFS_DUMP_FULL_KEY:
363+
if (pSMBFile == NULL)
364+
break;
365+
if (!capable(CAP_SYS_ADMIN)) {
366+
rc = -EACCES;
367+
break;
368+
}
369+
370+
tcon = tlink_tcon(pSMBFile->tlink);
371+
if (!smb3_encryption_required(tcon)) {
372+
rc = -EOPNOTSUPP;
373+
break;
374+
}
375+
pfull_key_inf.cipher_type =
376+
le16_to_cpu(tcon->ses->server->cipher_type);
377+
pfull_key_inf.Suid = tcon->ses->Suid;
378+
memcpy(pfull_key_inf.auth_key, tcon->ses->auth_key.response,
379+
16 /* SMB2_NTLMV2_SESSKEY_SIZE */);
380+
memcpy(pfull_key_inf.smb3decryptionkey,
381+
tcon->ses->smb3decryptionkey, 32 /* SMB3_ENC_DEC_KEY_SIZE */);
382+
memcpy(pfull_key_inf.smb3encryptionkey,
383+
tcon->ses->smb3encryptionkey, 32 /* SMB3_ENC_DEC_KEY_SIZE */);
384+
if (copy_to_user((void __user *)arg, &pfull_key_inf,
385+
sizeof(struct smb3_full_key_debug_info)))
386+
rc = -EFAULT;
387+
else
388+
rc = 0;
389+
break;
357390
case CIFS_IOC_NOTIFY:
358391
if (!S_ISDIR(inode->i_mode)) {
359392
/* Notify can only be done on directories */

0 commit comments

Comments
 (0)