cifs: only compile with DES when building with SMB1 support
Subsystems (2)
Steve, list
These three patches moves smb1 and all functions that depend on DES into smb1ops.c and will optionally compile smb1ops.c iff SMB1 support is enabled (CONFIG_CIFS_ALLOW_INSECURE_LEGACY)
Additionally, make CONFIG_CIFS_ALLOW_INSECURE_LEGACY depend on CONFIG_LIB_DES so that if the kernel is built without DES support we automatically disable the smb1 protocol.
This allows to build a cifs module on a kernel where DES has been disabled.
PATCH 1/3 cifs: only compile in smb1ops.c if we configure CIFS_ALLOW_INSECURE_LEGACY
--- fs/cifs/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/Makefile +3 -1
@@ -8,7 +8,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 \ - readdir.o ioctl.o sess.o export.o smb1ops.o unc.o winucase.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 \ dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o
@@ -17,6 +17,8 @@ $(obj)/asn1.o: $(obj)/cifs_spnego_negtokeninit.asn1.h $(obj)/cifs_spnego_negtokeninit.asn1.o: $(obj)/cifs_spnego_negtokeninit.asn1.c $(obj)/cifs_spnego_negtokeninit.asn1.h +cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o + cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
Signature · 1 line
2.30.2
PATCH 2/3 cifs: move calc_lanman_hash to smb1ops.c
In reply to Ronnie SahlbergThis is only used by SMB1 so lets move it to smb1ops which is conditionally compiled in depending on CIFS_ALLOW_INSECURE_LEGACY
--- fs/cifs/cifsencrypt.c | 42 ------------------------------------------ fs/cifs/smb1ops.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 42 deletions(-)
fs/cifs/cifsencrypt.c +0 -42
@@ -289,48 +289,6 @@ int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp)return rc; } -#ifdef CONFIG_CIFS_WEAK_PW_HASH -int calc_lanman_hash (const char *password,const char *cryptkey,bool encrypt, -char *lnm_session_key) -{ -int i, len; -int rc; -char password_with_pad[CIFS_ENCPWD_SIZE ] = {0 }; - -if (password) { -for (len =0 ; len <CIFS_ENCPWD_SIZE ; len++) -if (!password[len]) -break ; - -memcpy (password_with_pad, password, len); - } - -if (!encrypt && global_secflags &CIFSSEC_MAY_PLNTXT ) { -memcpy (lnm_session_key, password_with_pad, -CIFS_ENCPWD_SIZE ); -return 0 ; - } - -/* calculate old style session key */ -/* calling toupper is less broken than repeatedly -calling nls_toupper would be since that will never -work for UTF8, but neither handles multibyte code pages -but the only alternative would be converting to UCS-16 (Unicode) -(using a routine something like UniStrupr) then -uppercasing and then converting back from Unicode - which -would only worth doing it if we knew it were utf8. Basically -utf8 and other multibyte codepages each need their own strupper -function since a byte at a time will ont work. */ - -for (i =0 ; i <CIFS_ENCPWD_SIZE ; i++) - password_with_pad[i] =toupper (password_with_pad[i]); - - rc =SMBencrypt (password_with_pad, cryptkey, lnm_session_key); - -return rc; -} -#endif /* CIFS_WEAK_PW_HASH */ -/* Build a proper attribute value/target info pairs blob. * Fill in netbios and dns domain name and workstation name * and client time (total five av pairs and + one end of fields indicator.
fs/cifs/smb1ops.c +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH 2/3] cifs: move calc_lanman_hash to smb1ops.c
Thank you for the patch! Yet something to improve:
Hi Ronnie,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v5.14-rc5 next-20210813]
[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-only-compile-in-smb1ops-c-if-we-configure-CIFS_ALLOW_INSECURE_LEGACY/20210814-045731 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: hexagon-randconfig-r041-20210814 (attached as .config) compiler: clang version 12.0.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2a89ec2d759f8c3c9035498c5ef1bf66a8f8b07b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ronnie-Sahlberg/cifs-only-compile-in-smb1ops-c-if-we-configure-CIFS_ALLOW_INSECURE_LEGACY/20210814-045731 git checkout 2a89ec2d759f8c3c9035498c5ef1bf66a8f8b07b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=hexagon
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> fs/cifs/smb1ops.c:51:26: error: implicitly declaring library function 'toupper' with type 'int (int)' [-Werror,-Wimplicit-function-declaration]
password_with_pad[i] = toupper(password_with_pad[i]);
^ fs/cifs/smb1ops.c:51:26: note: include the header <ctype.h> or explicitly provide a declaration for 'toupper' 1 error generated.
vim +51 fs/cifs/smb1ops.c
16
17 #ifdef CONFIG_CIFS_WEAK_PW_HASH
18 int calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
19 char *lnm_session_key)
20 {
21 int i, len;
22 int rc;
23 char password_with_pad[CIFS_ENCPWD_SIZE] = {0};
24
25 if (password) {
26 for (len = 0; len < CIFS_ENCPWD_SIZE; len++)
27 if (!password[len])
28 break;
29
30 memcpy(password_with_pad, password, len);
31 }
32
33 if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
34 memcpy(lnm_session_key, password_with_pad,
35 CIFS_ENCPWD_SIZE);
36 return 0;
37 }
38
39 /* calculate old style session key */
40 /* calling toupper is less broken than repeatedly
41 calling nls_toupper would be since that will never
42 work for UTF8, but neither handles multibyte code pages
43 but the only alternative would be converting to UCS-16 (Unicode)
44 (using a routine something like UniStrupr) then
45 uppercasing and then converting back from Unicode - which
46 would only worth doing it if we knew it were utf8. Basically
47 utf8 and other multibyte codepages each need their own strupper
48 function since a byte@a time will ont work. */
49
50 for (i = 0; i < CIFS_ENCPWD_SIZE; i++)
> 51 password_with_pad[i] = toupper(password_with_pad[i]);
52
53 rc = SMBencrypt(password_with_pad, cryptkey, lnm_session_key);
54
55 return rc;
56 }
57 #endif /* CIFS_WEAK_PW_HASH */
58 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 2/3] cifs: move calc_lanman_hash to smb1ops.c
In reply to Ronnie SahlbergThank you for the patch! Yet something to improve:
Hi Ronnie,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v5.14-rc5 next-20210813]
[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-only-compile-in-smb1ops-c-if-we-configure-CIFS_ALLOW_INSECURE_LEGACY/20210814-045731 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: sh-allmodconfig (attached as .config) compiler: sh4-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2a89ec2d759f8c3c9035498c5ef1bf66a8f8b07b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ronnie-Sahlberg/cifs-only-compile-in-smb1ops-c-if-we-configure-CIFS_ALLOW_INSECURE_LEGACY/20210814-045731 git checkout 2a89ec2d759f8c3c9035498c5ef1bf66a8f8b07b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=sh
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
fs/cifs/smb1ops.c: In function 'calc_lanman_hash':
>> fs/cifs/smb1ops.c:51:40: error: implicit declaration of function 'toupper'; did you mean 'UniToupper'? [-Werror=implicit-function-declaration]
51 | password_with_pad[i] = toupper(password_with_pad[i]);
| ^~~~~~~
| UniTouppercc1: some warnings being treated as errors
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for SND_ATMEL_SOC_PDC
Depends on SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC && HAS_DMA Selected by
- SND_ATMEL_SOC_SSC && SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC
- SND_ATMEL_SOC_SSC_PDC && SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC && ATMEL_SSC
vim +51 fs/cifs/smb1ops.c
16
17 #ifdef CONFIG_CIFS_WEAK_PW_HASH
18 int calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
19 char *lnm_session_key)
20 {
21 int i, len;
22 int rc;
23 char password_with_pad[CIFS_ENCPWD_SIZE] = {0};
24
25 if (password) {
26 for (len = 0; len < CIFS_ENCPWD_SIZE; len++)
27 if (!password[len])
28 break;
29
30 memcpy(password_with_pad, password, len);
31 }
32
33 if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
34 memcpy(lnm_session_key, password_with_pad,
35 CIFS_ENCPWD_SIZE);
36 return 0;
37 }
38
39 /* calculate old style session key */
40 /* calling toupper is less broken than repeatedly
41 calling nls_toupper would be since that will never
42 work for UTF8, but neither handles multibyte code pages
43 but the only alternative would be converting to UCS-16 (Unicode)
44 (using a routine something like UniStrupr) then
45 uppercasing and then converting back from Unicode - which
46 would only worth doing it if we knew it were utf8. Basically
47 utf8 and other multibyte codepages each need their own strupper
48 function since a byte@a time will ont work. */
49
50 for (i = 0; i < CIFS_ENCPWD_SIZE; i++)
> 51 password_with_pad[i] = toupper(password_with_pad[i]);
52
53 rc = SMBencrypt(password_with_pad, cryptkey, lnm_session_key);
54
55 return rc;
56 }
57 #endif /* CIFS_WEAK_PW_HASH */
58 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 3/3 cifs: move functions that depend on DES to smp1ops.c
In reply to Ronnie SahlbergMove all dependencies of DES into smb1ops.c
Make SMB1 support depend on CONFIG_LIB_DES
--- fs/cifs/Kconfig | 3 +- fs/cifs/cifsencrypt.c | 39 ------ fs/cifs/cifsproto.h | 9 -- fs/cifs/connect.c | 162 --------------------- fs/cifs/ntlmssp.h | 1 + fs/cifs/sess.c | 5 + fs/cifs/smb1ops.c | 319 ++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbencrypt.c | 114 --------------- 8 files changed, 326 insertions(+), 326 deletions(-)
fs/cifs/Kconfig +1 -2
@@ -16,7 +16,6 @@ config CIFS select CRYPTO_GCM select CRYPTO_ECB select CRYPTO_AES - select CRYPTO_LIB_DES select KEYS select DNS_RESOLVER select ASN1
@@ -72,7 +71,7 @@ config CIFS_STATS2 config CIFS_ALLOW_INSECURE_LEGACY bool "Support legacy servers which use less secure dialects" - depends on CIFS + depends on CIFS && CRYPTO_LIB_DES default y help Modern dialects, SMB2.1 and later (including SMB3 and 3.1.1), have
fs/cifs/cifsencrypt.c +0 -39
@@ -250,45 +250,6 @@ int cifs_verify_signature(struct smb_rqst *rqst, } -/* first calculate 24 bytes ntlm response and then 16 byte session key */ -int setup_ntlm_response (struct cifs_ses *ses,const struct nls_table *nls_cp) -{ -int rc =0 ; -unsigned int temp_len =CIFS_SESS_KEY_SIZE +CIFS_AUTH_RESP_SIZE ; -char temp_key[CIFS_SESS_KEY_SIZE ]; - -if (!ses) -return -EINVAL ; - - ses->auth_key.response =kmalloc (temp_len,GFP_KERNEL ); -if (!ses->auth_key.response) -return -ENOMEM ; - - ses->auth_key.len = temp_len; - - rc =SMBNTencrypt (ses->password, ses->server->cryptkey, - ses->auth_key.response +CIFS_SESS_KEY_SIZE , nls_cp); -if (rc) { -cifs_dbg (FYI ,"%s Can't generate NTLM response, error: %d\n" , - __func__, rc); -return rc; - } - - rc =E_md4hash (ses->password, temp_key, nls_cp); -if (rc) { -cifs_dbg (FYI ,"%s Can't generate NT hash, error: %d\n" , - __func__, rc); -return rc; - } - - rc =mdfour (ses->auth_key.response, temp_key,CIFS_SESS_KEY_SIZE ); -if (rc) -cifs_dbg (FYI ,"%s Can't generate NTLM session key, error: %d\n" , - __func__, rc); - -return rc; -} -/* Build a proper attribute value/target info pairs blob. * Fill in netbios and dns domain name and workstation name * and client time (total five av pairs and + one end of fields indicator.
fs/cifs/cifsproto.h +0 -9
@@ -296,10 +296,6 @@ extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,extern int cifs_enable_signing (struct TCP_Server_Info *server,bool mnt_sign_required);extern int CIFSSMBNegotiate (const unsigned int xid,struct cifs_ses *ses); -extern int CIFSTCon (const unsigned int xid,struct cifs_ses *ses, -const char *tree,struct cifs_tcon *tcon, -const struct nls_table *); - extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, const char *searchName, struct cifs_sb_info *cifs_sb, __u16 *searchHandle, __u16 search_flags,
@@ -498,9 +494,6 @@ extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *);extern int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number); -extern int SMBNTencrypt (unsigned char *,unsigned char *,unsigned char *, -const struct nls_table *); -extern int setup_ntlm_response (struct cifs_ses *,const struct nls_table *);extern int setup_ntlmv2_rsp (struct cifs_ses *,const struct nls_table *);extern void cifs_crypto_secmech_release (struct TCP_Server_Info *server);extern int calc_seckey (struct cifs_ses *);
@@ -550,8 +543,6 @@ extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,extern int mdfour (unsigned char *,unsigned char *,int );extern int E_md4hash (const unsigned char *passwd,unsigned char *p16,const struct nls_table *codepage); -extern int SMBencrypt (unsigned char *passwd,const unsigned char *c8, -unsigned char *p24);extern int cifs_setup_volume_info (struct smb3_fs_context *ctx,const char *mntopts,const char *devname);
fs/cifs/connect.c +0 -162
168 lines not on this page · raw message
fs/cifs/ntlmssp.h +1 -0
@@ -124,3 +124,4 @@ void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, struct cifs_ses *ses);int build_ntlmssp_auth_blob (unsigned char **pbuffer,u16 *buflen,struct cifs_ses *ses,const struct nls_table *nls_cp); +int setup_ntlm_response (struct cifs_ses *ses,const struct nls_table *nls_cp);
fs/cifs/sess.c +5 -0
@@ -1061,6 +1061,8 @@ sess_auth_lanman(struct sess_data *sess_data)#endif + +#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY static void sess_auth_ntlm (struct sess_data *sess_data) {
@@ -1170,6 +1172,7 @@ sess_auth_ntlm(struct sess_data *sess_data)kfree (ses->auth_key.response); ses->auth_key.response = NULL; } +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ static void sess_auth_ntlmv2 (struct sess_data *sess_data)
@@ -1687,9 +1690,11 @@ static int select_sec(struct cifs_ses *ses, struct sess_data *sess_data)#else return -EOPNOTSUPP ;#endif +#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY case NTLM : sess_data->func = sess_auth_ntlm;break ; +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ case NTLMv2: sess_data->func = sess_auth_ntlmv2;break ;
fs/cifs/smb1ops.c +319 -0
339 lines not on this page · raw message
fs/cifs/smbencrypt.c +0 -114
135 lines not on this page · raw message
Signature · 1 line
2.30.2
Goal of these patches makes sense. Also will make it easier to build without SMB1 in the future when required.
Quoted 16 lines · Ronnie Sahlberg
Steve, list
These three patches moves smb1 and all functions that depend on DES into
smb1ops.cand will optionally compilesmb1ops.ciff SMB1 support is enabled (CONFIG_CIFS_ALLOW_INSECURE_LEGACY)Additionally, make
CONFIG_CIFS_ALLOW_INSECURE_LEGACYdepend onCONFIG_LIB_DESso that if the kernel is built without DES support we automatically disable the smb1 protocol.This allows to build a cifs module on a kernel where DES has been disabled.
Signature · 3 lines
Thanks, Steve
Any idea how much memory it saves when loading cifs.ko built without SMB1 support?
Quoted 16 lines · Ronnie Sahlberg
Steve, list
These three patches moves smb1 and all functions that depend on DES into
smb1ops.cand will optionally compilesmb1ops.ciff SMB1 support is enabled (CONFIG_CIFS_ALLOW_INSECURE_LEGACY)Additionally, make
CONFIG_CIFS_ALLOW_INSECURE_LEGACYdepend onCONFIG_LIB_DESso that if the kernel is built without DES support we automatically disable the smb1 protocol.This allows to build a cifs module on a kernel where DES has been disabled.
Signature · 3 lines
Thanks, Steve