Skip to contentSkip to conversation

ksmbd: fix possible refcount leak in smb2_open()

PATCH In review ChenXiaoSong 2 participants 4 messages Mar 2, 2023 – Mar 7, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: fix possible refcount leak in smb2_open()

Reference count of acls will leak when memory allocation fails. Fix this by adding the missing posix_acl_release().

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
 fs/ksmbd/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +4 -1
index 0685c1c77b9f..f04d810a2588 100644
@@ -2977,8 +2977,11 @@ int smb2_open(struct ksmbd_work *work)
 							sizeof(struct smb_acl) +
 							sizeof(struct smb_ace) * ace_num * 2,
 							GFP_KERNEL);
-					if (!pntsd)
+					if (!pntsd) {
+						posix_acl_release(fattr.cf_acls);
+						posix_acl_release(fattr.cf_dacls);
 						goto err_out;
+					}
 
 					rc = build_sec_desc(idmap,
 							    pntsd, NULL, 0,
Signature · 1 line
2.31.1
#1 lore raw

Hi Namjae and Steve:

Do you have any suggestions for this patch?

Quoted 27 lines · ChenXiaoSong

Reference count of acls will leak when memory allocation fails. Fix this by adding the missing posix_acl_release().

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
  fs/ksmbd/smb2pdu.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +4 -1
index 0685c1c77b9f..f04d810a2588 100644
@@ -2977,8 +2977,11 @@ int smb2_open(struct ksmbd_work *work)
  							sizeof(struct smb_acl) +
  							sizeof(struct smb_ace) * ace_num * 2,
  							GFP_KERNEL);
-					if (!pntsd)
+					if (!pntsd) {
+						posix_acl_release(fattr.cf_acls);
+						posix_acl_release(fattr.cf_dacls);
  						goto err_out;
+					}
 
  					rc = build_sec_desc(idmap,
  							    pntsd, NULL, 0,
maintainer
#2 lore raw

2023-03-07 17:52 GMT+09:00, ChenXiaoSong <[email protected]>:

Quoted 1 line

Hi Namjae and Steve:

Hi Chen,

Quoted 2 lines

Do you have any suggestions for this patch?

Sorry, It was in the spam box...
I have sent ack. Thanks for noticing.

Quoted 30 lines · ChenXiaoSong
Quoted 27 lines

Reference count of acls will leak when memory allocation fails. Fix this by adding the missing posix_acl_release().

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
  fs/ksmbd/smb2pdu.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +4 -1
index 0685c1c77b9f..f04d810a2588 100644
@@ -2977,8 +2977,11 @@ int smb2_open(struct ksmbd_work *work)
  							sizeof(struct smb_acl) +
  							sizeof(struct smb_ace) * ace_num * 2,
  							GFP_KERNEL);
-					if (!pntsd)
+					if (!pntsd) {
+						posix_acl_release(fattr.cf_acls);
+						posix_acl_release(fattr.cf_dacls);
  						goto err_out;
+					}
 
  					rc = build_sec_desc(idmap,
  							    pntsd, NULL, 0,