linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs: fork arc4 and add a private copy in fs/cifs
@ 2021-08-19  3:20 Ronnie Sahlberg
  2021-08-20  1:59 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2021-08-19  3:20 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

SMB supports two authentication modes, a modified krb5 mode which contains
ActiveDirectory extensions and accound information for the tickets and
NTLMSSP.

For NTLMSSP in SMB1/2/3 authentication uses a combination of all three of
md4/md5/arc4.

Fork/copy the ARC4 implementation from the crypto library into fs/cifs
so that we have a private version for NTLMSSP once ARC4 is removed from the
kernel crypto libraries.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/Kconfig       |  1 -
 fs/cifs/Makefile      |  2 +-
 fs/cifs/arc4.c        | 69 +++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/arc4.h        | 23 +++++++++++++++
 fs/cifs/cifsencrypt.c |  2 +-
 5 files changed, 94 insertions(+), 3 deletions(-)
 create mode 100644 fs/cifs/arc4.c
 create mode 100644 fs/cifs/arc4.h

diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index c01464476ba9..76ccb72e5aa6 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -10,7 +10,6 @@ config CIFS
 	select CRYPTO_SHA512
 	select CRYPTO_CMAC
 	select CRYPTO_HMAC
-	select CRYPTO_LIB_ARC4
 	select CRYPTO_AEAD2
 	select CRYPTO_CCM
 	select CRYPTO_GCM
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index 96739082718d..a8cb5bedc7dc 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -7,7 +7,7 @@ obj-$(CONFIG_CIFS) += cifs.o
 
 cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
 	  inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \
-	  cifs_unicode.o nterr.o cifsencrypt.o \
+	  arc4.o cifs_unicode.o nterr.o cifsencrypt.o \
 	  readdir.o ioctl.o sess.o export.o unc.o winucase.o \
 	  smb2ops.o smb2maperror.o smb2transport.o \
 	  smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \
diff --git a/fs/cifs/arc4.c b/fs/cifs/arc4.c
new file mode 100644
index 000000000000..996bba153967
--- /dev/null
+++ b/fs/cifs/arc4.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Cryptographic API
+ *
+ * ARC4 Cipher Algorithm
+ *
+ * Jon Oberheide <jon@oberheide.org>
+ */
+
+#include "arc4.h"
+
+int arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len)
+{
+	int i, j = 0, k = 0;
+
+	ctx->x = 1;
+	ctx->y = 0;
+
+	for (i = 0; i < 256; i++)
+		ctx->S[i] = i;
+
+	for (i = 0; i < 256; i++) {
+		u32 a = ctx->S[i];
+
+		j = (j + in_key[k] + a) & 0xff;
+		ctx->S[i] = ctx->S[j];
+		ctx->S[j] = a;
+		if (++k >= key_len)
+			k = 0;
+	}
+
+	return 0;
+}
+
+void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len)
+{
+	u32 *const S = ctx->S;
+	u32 x, y, a, b;
+	u32 ty, ta, tb;
+
+	if (len == 0)
+		return;
+
+	x = ctx->x;
+	y = ctx->y;
+
+	a = S[x];
+	y = (y + a) & 0xff;
+	b = S[y];
+
+	do {
+		S[y] = a;
+		a = (a + b) & 0xff;
+		S[x] = b;
+		x = (x + 1) & 0xff;
+		ta = S[x];
+		ty = (y + ta) & 0xff;
+		tb = S[ty];
+		*out++ = *in++ ^ S[a];
+		if (--len == 0)
+			break;
+		y = ty;
+		a = ta;
+		b = tb;
+	} while (true);
+
+	ctx->x = x;
+	ctx->y = y;
+}
diff --git a/fs/cifs/arc4.h b/fs/cifs/arc4.h
new file mode 100644
index 000000000000..f3c22fe01704
--- /dev/null
+++ b/fs/cifs/arc4.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Common values for ARC4 Cipher Algorithm
+ */
+
+#ifndef _CRYPTO_ARC4_H
+#define _CRYPTO_ARC4_H
+
+#include <linux/types.h>
+
+#define ARC4_MIN_KEY_SIZE	1
+#define ARC4_MAX_KEY_SIZE	256
+#define ARC4_BLOCK_SIZE		1
+
+struct arc4_ctx {
+	u32 S[256];
+	u32 x, y;
+};
+
+int arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len);
+void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len);
+
+#endif /* _CRYPTO_ARC4_H */
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 7680e0a9bea3..3b47093ceb74 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -22,7 +22,7 @@
 #include <linux/random.h>
 #include <linux/highmem.h>
 #include <linux/fips.h>
-#include <crypto/arc4.h>
+#include "arc4.h"
 #include <crypto/aead.h>
 
 int __cifs_calc_signature(struct smb_rqst *rqst,
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cifs: fork arc4 and add a private copy in fs/cifs
  2021-08-19  3:20 [PATCH] cifs: fork arc4 and add a private copy in fs/cifs Ronnie Sahlberg
@ 2021-08-20  1:59 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-08-20  1:59 UTC (permalink / raw)
  To: Ronnie Sahlberg, linux-cifs; +Cc: kbuild-all, Steve French

[-- Attachment #1: Type: text/plain, Size: 5495 bytes --]

Hi Ronnie,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on cifs/for-next]
[also build test ERROR on next-20210819]
[cannot apply to v5.14-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ronnie-Sahlberg/cifs-fork-arc4-and-add-a-private-copy-in-fs-cifs/20210819-112323
base:   git://git.samba.org/sfrench/cifs-2.6.git for-next
config: x86_64-randconfig-a001-20210818 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/370a85a8919b6e79ab8f83007d030b157981b7cf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ronnie-Sahlberg/cifs-fork-arc4-and-add-a-private-copy-in-fs-cifs/20210819-112323
        git checkout 370a85a8919b6e79ab8f83007d030b157981b7cf
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: lib/crypto/arc4.o: in function `arc4_setkey':
>> lib/crypto/arc4.c:14: multiple definition of `arc4_setkey'; fs/cifs/arc4.o:fs/cifs/arc4.c:13: first defined here
   ld: lib/crypto/arc4.o: in function `arc4_crypt':
>> lib/crypto/arc4.c:43: multiple definition of `arc4_crypt'; fs/cifs/arc4.o:fs/cifs/arc4.c:41: first defined here


vim +14 lib/crypto/arc4.c

dc51f25752bfcb Ard Biesheuvel 2019-06-12  12  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  13  int arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len)
dc51f25752bfcb Ard Biesheuvel 2019-06-12 @14  {
dc51f25752bfcb Ard Biesheuvel 2019-06-12  15  	int i, j = 0, k = 0;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  16  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  17  	ctx->x = 1;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  18  	ctx->y = 0;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  19  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  20  	for (i = 0; i < 256; i++)
dc51f25752bfcb Ard Biesheuvel 2019-06-12  21  		ctx->S[i] = i;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  22  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  23  	for (i = 0; i < 256; i++) {
dc51f25752bfcb Ard Biesheuvel 2019-06-12  24  		u32 a = ctx->S[i];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  25  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  26  		j = (j + in_key[k] + a) & 0xff;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  27  		ctx->S[i] = ctx->S[j];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  28  		ctx->S[j] = a;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  29  		if (++k >= key_len)
dc51f25752bfcb Ard Biesheuvel 2019-06-12  30  			k = 0;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  31  	}
dc51f25752bfcb Ard Biesheuvel 2019-06-12  32  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  33  	return 0;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  34  }
dc51f25752bfcb Ard Biesheuvel 2019-06-12  35  EXPORT_SYMBOL(arc4_setkey);
dc51f25752bfcb Ard Biesheuvel 2019-06-12  36  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  37  void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len)
dc51f25752bfcb Ard Biesheuvel 2019-06-12  38  {
dc51f25752bfcb Ard Biesheuvel 2019-06-12  39  	u32 *const S = ctx->S;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  40  	u32 x, y, a, b;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  41  	u32 ty, ta, tb;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  42  
dc51f25752bfcb Ard Biesheuvel 2019-06-12 @43  	if (len == 0)
dc51f25752bfcb Ard Biesheuvel 2019-06-12  44  		return;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  45  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  46  	x = ctx->x;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  47  	y = ctx->y;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  48  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  49  	a = S[x];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  50  	y = (y + a) & 0xff;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  51  	b = S[y];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  52  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  53  	do {
dc51f25752bfcb Ard Biesheuvel 2019-06-12  54  		S[y] = a;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  55  		a = (a + b) & 0xff;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  56  		S[x] = b;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  57  		x = (x + 1) & 0xff;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  58  		ta = S[x];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  59  		ty = (y + ta) & 0xff;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  60  		tb = S[ty];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  61  		*out++ = *in++ ^ S[a];
dc51f25752bfcb Ard Biesheuvel 2019-06-12  62  		if (--len == 0)
dc51f25752bfcb Ard Biesheuvel 2019-06-12  63  			break;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  64  		y = ty;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  65  		a = ta;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  66  		b = tb;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  67  	} while (true);
dc51f25752bfcb Ard Biesheuvel 2019-06-12  68  
dc51f25752bfcb Ard Biesheuvel 2019-06-12  69  	ctx->x = x;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  70  	ctx->y = y;
dc51f25752bfcb Ard Biesheuvel 2019-06-12  71  }
dc51f25752bfcb Ard Biesheuvel 2019-06-12  72  EXPORT_SYMBOL(arc4_crypt);
dc51f25752bfcb Ard Biesheuvel 2019-06-12  73  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 42021 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-20  1:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19  3:20 [PATCH] cifs: fork arc4 and add a private copy in fs/cifs Ronnie Sahlberg
2021-08-20  1:59 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).