smb: Use loff_t for directory position in cached_dirents
Subsystems (2)
PATCH 1/7 smb: Use loff_t for directory position in cached_dirents
Change the pos field in struct cached_dirents from int to loff_t to support large directory offsets. This avoids overflow and matches kernel conventions for directory positions.
--- fs/smb/client/cached_dir.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cached_dir.h +1 -1
@@ -26,7 +26,7 @@ struct cached_dirents {* open file instance. */ struct mutex de_mutex; -int pos;/* Expected ctx->pos */ +loff_t pos;/* Expected ctx->pos */ struct list_head entries; };
Signature · 1 line
2.43.0
PATCH 2/7 smb: minor fix to use sizeof to initialize flags_string buffer
Replaced hardcoded length with sizeof(flags_string).
--- fs/smb/client/cifs_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifs_debug.c +1 -1
@@ -1105,7 +1105,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,if ((count <1 ) || (count >11 ))return -EINVAL ; -memset (flags_string,0 ,12 ); +memset (flags_string,0 ,sizeof (flags_string));if (copy_from_user (flags_string, buffer, count))return -EFAULT ;
Signature · 1 line
2.43.0
Re: [PATCH 2/7] smb: minor fix to use sizeof to initialize flags_string buffer
Quoted 6 lines · Bharath SM
Replaced hardcoded length with
sizeof(flags_string).Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH 2/7] smb: minor fix to use sizeof to initialize flags_string buffer
In reply to Bharath SMQuoted 22 lines · Bharath SM
Replaced hardcoded length with
sizeof(flags_string).Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/smb/client/cifs_debug.c +1
-2@@ -1105,7 +1105,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,if ((count <1 ) || (count >11 ))return -EINVAL ; -memset (flags_string,0 ,12 ); +memset (flags_string,0 ,sizeof (flags_string));if (copy_from_user (flags_string, buffer, count))return -EFAULT ; --
Quoted 3 lines
2.43.0
Why not define the size of the flags_string as a constant too?
Signature · 2 lines
Regards, Shyam
PATCH 3/7 smb: minor fix to use SMB2_NTLMV2_SESSKEY_SIZE for auth_key size
In reply to Bharath SMReplaced hardcoded value 16 with SMB2_NTLMV2_SESSKEY_SIZE in the auth_key definition and memcpy call.
--- fs/smb/client/cifs_ioctl.h | 2 +- fs/smb/client/ioctl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/cifs_ioctl.h +1 -1
@@ -61,7 +61,7 @@ struct smb_query_info {struct smb3_key_debug_info {__u64 Suid;__u16 cipher_type; -__u8 auth_key[16 ];/* SMB2_NTLMV2_SESSKEY_SIZE */ +__u8 auth_key[SMB2_NTLMV2_SESSKEY_SIZE ];__u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE ];__u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE ]; } __packed;
fs/smb/client/ioctl.c +1 -1
@@ -506,7 +506,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)le16_to_cpu (tcon->ses->server->cipher_type); pkey_inf.Suid = tcon->ses->Suid;memcpy (pkey_inf.auth_key, tcon->ses->auth_key.response, -16 /* SMB2_NTLMV2_SESSKEY_SIZE */ ); +SMB2_NTLMV2_SESSKEY_SIZE );memcpy (pkey_inf.smb3decryptionkey, tcon->ses->smb3decryptionkey,SMB3_SIGN_KEY_SIZE ); memcpy(pkey_inf.smb3encryptionkey,
Signature · 1 line
2.43.0
Re: [PATCH 3/7] smb: minor fix to use SMB2_NTLMV2_SESSKEY_SIZE for auth_key size
Quoted 27 lines · Bharath SM
Replaced hardcoded value 16 with
SMB2_NTLMV2_SESSKEY_SIZEin theauth_keydefinition and memcpy call.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_ioctl.h | 2 +- fs/smb/client/ioctl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/smb/client/cifs_ioctl.h +1
-1@@ -61,7 +61,7 @@ struct smb_query_info {struct smb3_key_debug_info {__u64 Suid;__u16 cipher_type; -__u8 auth_key[16 ];/* SMB2_NTLMV2_SESSKEY_SIZE */ +__u8 auth_key[SMB2_NTLMV2_SESSKEY_SIZE ];__u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE ];__u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE ]; } __packed;fs/smb/client/ioctl.c +0
-0
fs/smb/client/ioctl.c long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) · line 509
Quoted 5 lines
fs/smb/client/ioctl.c +1
-1@@ -506,7 +506,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)le16_to_cpu (tcon->ses->server->cipher_type); pkey_inf.Suid = tcon->ses->Suid;memcpy (pkey_inf.auth_key, tcon->ses->auth_key.response, -16 /* SMB2_NTLMV2_SESSKEY_SIZE */ ); +SMB2_NTLMV2_SESSKEY_SIZE );
^ sizeof(pkey_in.auth_key)?
Re: [PATCH 3/7] smb: minor fix to use SMB2_NTLMV2_SESSKEY_SIZE for auth_key size
In reply to Bharath SMQuoted 37 lines · Bharath SM
Replaced hardcoded value 16 with
SMB2_NTLMV2_SESSKEY_SIZEin theauth_keydefinition and memcpy call.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_ioctl.h | 2 +- fs/smb/client/ioctl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/smb/client/cifs_ioctl.h +1
-1@@ -61,7 +61,7 @@ struct smb_query_info {struct smb3_key_debug_info {__u64 Suid;__u16 cipher_type; -__u8 auth_key[16 ];/* SMB2_NTLMV2_SESSKEY_SIZE */ +__u8 auth_key[SMB2_NTLMV2_SESSKEY_SIZE ];__u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE ];__u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE ]; } __packed;fs/smb/client/ioctl.c +1
-2@@ -506,7 +506,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)le16_to_cpu (tcon->ses->server->cipher_type); pkey_inf.Suid = tcon->ses->Suid;memcpy (pkey_inf.auth_key, tcon->ses->auth_key.response, -16 /* SMB2_NTLMV2_SESSKEY_SIZE */ ); +SMB2_NTLMV2_SESSKEY_SIZE );memcpy (pkey_inf.smb3decryptionkey, tcon->ses->smb3decryptionkey,SMB3_SIGN_KEY_SIZE ); memcpy(pkey_inf.smb3encryptionkey, --
Quoted 3 lines
2.43.0
Looks good to me.
Signature · 2 lines
Regards, Shyam
PATCH 4/7 smb: add NULL check after kzalloc in cifsConvertToUTF16
In reply to Bharath SMAdded a check to return -ENOMEM if kzalloc for wchar_to fails
--- fs/smb/client/cifs_unicode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/cifs_unicode.c +2 -0
@@ -466,6 +466,8 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,return cifs_strtoUTF16 (target, source,PATH_MAX , cp); wchar_to =kzalloc (6 ,GFP_KERNEL ); +if (wchar_to ==NULL ) +return -ENOMEM ;for (i =0 ; i < srclen; j++) { src_char = source[i];
Signature · 1 line
2.43.0
Paulo Alcantara
maintainerRe: [PATCH 4/7] smb: add NULL check after kzalloc in cifsConvertToUTF16
Quoted 12 lines · Bharath SM
Added a check to return
-ENOMEMif kzalloc forwchar_tofailsSigned-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_unicode.c | 2 ++ 1 file changed, 2 insertions(+)fs/smb/client/cifs_unicode.c +0
-0
fs/smb/client/cifs_unicode.c cifsConvertToUTF16(__le16 *target, const char *source, int srclen, · line 470
Quoted 5 lines
fs/smb/client/cifs_unicode.c +2
-0@@ -466,6 +466,8 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,return cifs_strtoUTF16 (target, source,PATH_MAX , cp); wchar_to =kzalloc (6 ,GFP_KERNEL ); +if (wchar_to ==NULL ) +return -ENOMEM ;
I wouldn't do that as there are several places that rely on cifsConvertToUTF16() returning >= 0 and some other places that don't even check its return value.
What about having it defined as
wchar_t wchar_to[3] = {};and then getting rid of the memory allocation altogether?
Re: [PATCH 4/7] smb: add NULL check after kzalloc in cifsConvertToUTF16
makes sense. thanks. will update.
Quoted 30 lines · Paulo Alcantara
Quoted 12 lines · Bharath SM
Added a check to return
-ENOMEMif kzalloc forwchar_tofailsSigned-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_unicode.c | 2 ++ 1 file changed, 2 insertions(+)fs/smb/client/cifs_unicode.c +0
-0fs/smb/client/cifs_unicode.c cifsConvertToUTF16(__le16 *target, const char *source, int srclen, · line 470
Quoted 5 lines
fs/smb/client/cifs_unicode.c +2
-0@@ -466,6 +466,8 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,return cifs_strtoUTF16 (target, source,PATH_MAX , cp); wchar_to =kzalloc (6 ,GFP_KERNEL ); +if (wchar_to ==NULL ) +return -ENOMEM ;I wouldn't do that as there are several places that rely on
cifsConvertToUTF16()returning >= 0 and some other places that don't even check its return value.What about having it defined as
wchar_t wchar_to[3] = {};and then getting rid of the memory allocation altogether?
Re: [PATCH 4/7] smb: add NULL check after kzalloc in cifsConvertToUTF16
In reply to Bharath SMQuoted 22 lines · Bharath SM
Added a check to return
-ENOMEMif kzalloc forwchar_tofailsSigned-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_unicode.c | 2 ++ 1 file changed, 2 insertions(+)fs/smb/client/cifs_unicode.c +2
-1@@ -466,6 +466,8 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,return cifs_strtoUTF16 (target, source,PATH_MAX , cp); wchar_to =kzalloc (6 ,GFP_KERNEL ); +if (wchar_to ==NULL ) +return -ENOMEM ;for (i =0 ; i < srclen; j++) { src_char = source[i]; --
Quoted 3 lines
2.43.0
Looks good to me.
Signature · 2 lines
Regards, Shyam
PATCH 5/7 cifs: minor cleanup to remove unused permission bit macros
In reply to Bharath SMDropped READ_BIT, WRITE_BIT, EXEC_BIT, UBITSHIFT,
and GBITSHIFT from cifsacl.h as they are unused
--- fs/smb/client/cifsacl.h | 7 ------- 1 file changed, 7 deletions(-)
fs/smb/client/cifsacl.h +0 -7
@@ -11,17 +11,10 @@#include "../common/smbacl.h" -#define READ_BIT 0x4 -#define WRITE_BIT 0x2 -#define EXEC_BIT 0x1 -#define ACL_OWNER_MASK 0700#define ACL_GROUP_MASK 0070#define ACL_EVERYONE_MASK 0007 -#define UBITSHIFT 6 -#define GBITSHIFT 3 -/* * Security Descriptor length containing DACL with 3 ACEs (one each for * owner, group and world).
Signature · 1 line
2.43.0
PATCH 6/7 smb: Fix potential divide-by-zero issue when iface_min_speed is 0
In reply to Bharath SMAddress potential divide-by-zero issue when iface_min_speed is 0 by adding proper handling to prevent undefined behavior.
--- fs/smb/client/cifs_debug.c | 2 +- fs/smb/client/sess.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/cifs_debug.c +1 -1
@@ -599,7 +599,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)seq_printf (m,"\n\t%d)" , ++j);cifs_dump_iface (m, iface); - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ; seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)" "\n\t\tAllocated channels: %u\n", iface->weight_fulfilled,
fs/smb/client/sess.c +2 -2
@@ -218,7 +218,7 @@ int cifs_try_adding_channels(struct cifs_ses *ses)continue ;/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ;if (iface->weight_fulfilled >= iface_weight)continue ;
@@ -387,7 +387,7 @@ cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server) }/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ;if (iface->weight_fulfilled >= iface_weight)continue ;
Signature · 1 line
2.43.0
Paulo Alcantara
maintainerRe: [PATCH 6/7] smb: Fix potential divide-by-zero issue when iface_min_speed is 0
Quoted 8 lines · Bharath SM
Address potential divide-by-zero issue when
iface_min_speedis 0 by adding proper handling to prevent undefined behavior.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_debug.c | 2 +- fs/smb/client/sess.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Isn't be7a6a776695 ("smb: client: fix oops due to unset link speed") enough to prevent that already?
Re: [PATCH 6/7] smb: Fix potential divide-by-zero issue when iface_min_speed is 0
Quoted 6 lines · Paulo Alcantara
Quoted 3 lines · Bharath SM
Address potential divide-by-zero issue when
iface_min_speedis 0 by adding proper handling to prevent undefined behavior.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_debug.c | 2 +- fs/smb/client/sess.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)Isn't
be7a6a776695("smb: client: fix oops due to unset link speed") enough to prevent that already?
Right, I didn't notice this check. I think this fix should take of the issue.
Re: [PATCH 6/7] smb: Fix potential divide-by-zero issue when iface_min_speed is 0
In reply to Bharath SMQuoted 46 lines · Bharath SM
Address potential divide-by-zero issue when
iface_min_speedis 0 by adding proper handling to prevent undefined behavior.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cifs_debug.c | 2 +- fs/smb/client/sess.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)fs/smb/client/cifs_debug.c +1
-1@@ -599,7 +599,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)seq_printf (m,"\n\t%d)" , ++j);cifs_dump_iface (m, iface); - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ; seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)" "\n\t\tAllocated channels: %u\n", iface->weight_fulfilled,fs/smb/client/sess.c +2
-3@@ -218,7 +218,7 @@ int cifs_try_adding_channels(struct cifs_ses *ses)continue ;/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ;if (iface->weight_fulfilled >= iface_weight)continue ;@@ -387,7 +387,7 @@ cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server) }/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; + iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) :0 ;if (iface->weight_fulfilled >= iface_weight)continue ; --
Quoted 3 lines
2.43.0
Good spot.
Might want to add the Fixes tag:
based on speed")
Signature · 2 lines
Regards, Shyam
PATCH 7/7 smb: Fix memory allocation and ACL handling in cifs_xattr_set
In reply to Bharath SMIf set_acl is NULL, then there is a chance that memory allocated for pacl memory doesn't get freed. Ensure proper memory deallocation for pacl in cifs_xattr_set to avoid leaks.
--- fs/smb/client/xattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/client/xattr.c +2 -1
@@ -174,6 +174,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler, pacl =kmalloc (size,GFP_KERNEL );if (!pacl) { rc = -ENOMEM ; + goto out; }else {memcpy (pacl, value, size);if (pTcon->ses->server->ops->set_acl) {
@@ -211,8 +212,8 @@ static int cifs_xattr_set(const struct xattr_handler *handler, }if (rc ==0 )/* force revalidate of the inode */ CIFS_I (inode)->time =0 ; -kfree (pacl); } +kfree (pacl);break ; } }
Signature · 1 line
2.43.0
Paulo Alcantara
maintainerRe: [PATCH 7/7] smb: Fix memory allocation and ACL handling in cifs_xattr_set
Hi Bharath,
Quoted 3 lines · Bharath SM
If
set_aclis NULL, then there is a chance that memory allocated for pacl memory doesn't get freed. Ensure proper memory deallocation for pacl incifs_xattr_setto avoid leaks.
If ->set_acl is NULL, then the following is executed
} else {
rc = -EOPNOTSUPP;
}
if (rc == 0) /* force revalidate of the inode */
CIFS_I(inode)->time = 0;
kfree(pacl);Can you elaborate where the potential leak is?
Quoted 8 lines · Bharath SM
Change the pos field in struct
cached_direntsfrom int toloff_tto support large directory offsets. This avoids overflow and matches kernel conventions for directory positions.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cached_dir.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 24 lines · Bharath SM
Change the pos field in struct
cached_direntsfrom int toloff_tto support large directory offsets. This avoids overflow and matches kernel conventions for directory positions.Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/cached_dir.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/smb/client/cached_dir.h +1
-2@@ -26,7 +26,7 @@ struct cached_dirents {* open file instance. */ struct mutex de_mutex; -int pos;/* Expected ctx->pos */ +loff_t pos;/* Expected ctx->pos */ struct list_head entries; }; --
Quoted 3 lines
2.43.0
Looks good to me.
Signature · 2 lines
Regards, Shyam