Re: Add support for GCM256 encryption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Redid patch 5 (includes Aurelien's suggestion, fixes a typo and fixes
a problem with vers=3.0 mounts) - attached.

On Thu, Oct 15, 2020 at 12:41 PM Steve French <smfrench@xxxxxxxxx> wrote:
>
> found another typo in patch 5 ccm instead of gcm - fixing it now
>
> On Thu, Oct 15, 2020 at 11:33 AM Steve French <smfrench@xxxxxxxxx> wrote:
> >
> > Good point.  Updated patches attached.  Also added a one line comment
> > to smb2pdu.h mentioning why we don't request AES_256_CCM
> >
> >
> > On Thu, Oct 15, 2020 at 3:49 AM Aurélien Aptel <aaptel@xxxxxxxx> wrote:
> > >
> > > Hi Steve,
> > >
> > > Patch 2:
> > >
> > > > From 3897b440fd14dfc7b2ad2b0a922302ea7705b5d9 Mon Sep 17 00:00:00 2001
> > > > From: Steve French <stfrench@xxxxxxxxxxxxx>
> > > > Date: Wed, 14 Oct 2020 20:24:09 -0500
> > > > Subject: [PATCH 2/5] smb3.1.1: add new module load parm enable_gcm_256
> > > > --- a/fs/cifs/smb2pdu.h
> > > > +++ b/fs/cifs/smb2pdu.h
> > > > @@ -361,8 +361,9 @@ struct smb2_encryption_neg_context {
> > > >       __le16  ContextType; /* 2 */
> > > >       __le16  DataLength;
> > > >       __le32  Reserved;
> > > > -     __le16  CipherCount; /* AES-128-GCM and AES-128-CCM */
> > > > -     __le16  Ciphers[2];
> > > > +     /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
> > > > +     __le16  CipherCount; /* AES128-GCM and AES128-CCM by defalt */
> > >
> > > Typo defalt => default
> > >
> > > > +     __le16  Ciphers[3];
> > > >  } __packed;
> > > >
> > > >  /* See MS-SMB2 2.2.3.1.3 */
> > > > --
> > > > 2.25.1
> > > >
> > >
> > > Patch 5:
> > >
> > > > From 314d7476e404c37acb77c3f9ecc142122e7afbfd Mon Sep 17 00:00:00 2001
> > > > From: Steve French <stfrench@xxxxxxxxxxxxx>
> > > > Date: Fri, 11 Sep 2020 16:47:09 -0500
> > > > Subject: [PATCH 5/5] smb3.1.1: set gcm256 when requested
> > > >
> > > > update code to set 32 byte key length and to set gcm256 when requested
> > > > on mount.
> > > >
> > > > Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
> > > > ---
> > > >  fs/cifs/smb2glob.h      |  1 +
> > > >  fs/cifs/smb2ops.c       | 20 ++++++++++++--------
> > > >  fs/cifs/smb2transport.c | 16 ++++++++--------
> > > >  3 files changed, 21 insertions(+), 16 deletions(-)
> > > >
> > > > diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> > > > index dd1edabec328..d8e74954d101 100644
> > > > --- a/fs/cifs/smb2ops.c
> > > > +++ b/fs/cifs/smb2ops.c
> > > > @@ -3954,7 +3954,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
> > > >
> > > >       tfm = enc ? server->secmech.ccmaesencrypt :
> > > >                                               server->secmech.ccmaesdecrypt;
> > > > -     rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
> > > > +
> > > > +     if (require_gcm_256)
> > > > +             rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
> > >
> > > Shouldn't the check be on server->cipher_type?
> > >
> > > > +     else
> > > > +             rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
> > > > +
> > > >       if (rc) {
> > > >               cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
> > > >               return rc;
> > >
> > > --
> > > Aurélien Aptel / SUSE Labs Samba Team
> > > GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
> > > SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
> > > GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
> >
> >
> >
> > --
> > Thanks,
> >
> > Steve
>
>
>
> --
> Thanks,
>
> Steve



-- 
Thanks,

Steve
From 33459a620d7b3ee2c707ef9d2f14118bef814b31 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@xxxxxxxxxxxxx>
Date: Thu, 15 Oct 2020 23:41:40 -0500
Subject: [PATCH 5/5] smb3.1.1: set gcm256 when requested

update smb encryption code to set 32 byte key length and to
set gcm256 when requested on mount.

Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
---
 fs/cifs/smb2glob.h      |  1 +
 fs/cifs/smb2ops.c       | 13 ++++++++++---
 fs/cifs/smb2pdu.h       |  1 +
 fs/cifs/smb2transport.c |  8 +++++---
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h
index cf20f0b5d836..99a1951a01ec 100644
--- a/fs/cifs/smb2glob.h
+++ b/fs/cifs/smb2glob.h
@@ -58,6 +58,7 @@
 #define SMB2_HMACSHA256_SIZE (32)
 #define SMB2_CMACAES_SIZE (16)
 #define SMB3_SIGNKEY_SIZE (16)
+#define SMB3_GCM256_CRYPTKEY_SIZE (32)
 
 /* Maximum buffer size value we can send with 1 credit */
 #define SMB2_MAX_BUFFER_SIZE 65536
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index dd1edabec328..48657ddbd75e 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3820,7 +3820,8 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
 	tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
 	tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
 	tr_hdr->Flags = cpu_to_le16(0x01);
-	if (cipher_type == SMB2_ENCRYPTION_AES128_GCM)
+	if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
+	    (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
 		get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
 	else
 		get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
@@ -3954,7 +3955,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
 
 	tfm = enc ? server->secmech.ccmaesencrypt :
 						server->secmech.ccmaesdecrypt;
-	rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
+
+	if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
+		rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
+	else
+		rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
+
 	if (rc) {
 		cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
 		return rc;
@@ -3992,7 +3998,8 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
 		goto free_sg;
 	}
 
-	if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
+	if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
+	    (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
 		memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
 	else {
 		iv[0] = 3;
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index 05b010e5a061..851c6cd4742a 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -352,6 +352,7 @@ struct smb2_preauth_neg_context {
 /* Encryption Algorithms Ciphers */
 #define SMB2_ENCRYPTION_AES128_CCM	cpu_to_le16(0x0001)
 #define SMB2_ENCRYPTION_AES128_GCM	cpu_to_le16(0x0002)
+/* we currently do not request AES256_CCM since presumably GCM faster */
 #define SMB2_ENCRYPTION_AES256_CCM      cpu_to_le16(0x0003)
 #define SMB2_ENCRYPTION_AES256_GCM      cpu_to_le16(0x0004)
 
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index c0348e3b1695..ebccd71cc60a 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -849,12 +849,13 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
 	struct crypto_aead *tfm;
 
 	if (!server->secmech.ccmaesencrypt) {
-		if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
+		if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
+		    (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
 			tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
 		else
 			tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
 		if (IS_ERR(tfm)) {
-			cifs_server_dbg(VFS, "%s: Failed to alloc encrypt aead\n",
+			cifs_server_dbg(VFS, "%s: Failed alloc encrypt aead\n",
 				 __func__);
 			return PTR_ERR(tfm);
 		}
@@ -862,7 +863,8 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
 	}
 
 	if (!server->secmech.ccmaesdecrypt) {
-		if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
+		if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
+		    (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
 			tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
 		else
 			tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
-- 
2.25.1


[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux