Skip to contentSkip to conversation

ksmbd: fix possible memory leak in smb2_lock()

PATCH Superseded Hangyu Hua 2 participants 3 messages Feb 1, 2023 – Feb 6, 2023

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 ksmbd: fix possible memory leak in smb2_lock()

argv needs to be free when setup_async_work fails or when the current process is woken up.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
 fs/ksmbd/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ksmbd/smb2pdu.c +3 -0
index d681f91947d9..5b7668c04f76 100644
@@ -7050,6 +7050,7 @@ int smb2_lock(struct ksmbd_work *work)
 						      smb2_remove_blocked_lock,
 						      argv);
 				if (rc) {
+					kfree(argv);
 					err = -ENOMEM;
 					goto out;
 				}
@@ -7061,6 +7062,8 @@ int smb2_lock(struct ksmbd_work *work)
 
 				ksmbd_vfs_posix_lock_wait(flock);
 
+				work->cancel_fn = NULL;
+				kfree(argv);
 				if (work->state != KSMBD_WORK_ACTIVE) {
 					list_del(&smb_lock->llist);
 					spin_lock(&work->conn->llist_lock);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

2023-02-01 17:10 GMT+09:00, Hangyu Hua <[email protected]>:

Quoted 22 lines

argv needs to be free when setup_async_work fails or when the current process is woken up.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
 fs/ksmbd/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ksmbd/smb2pdu.c +1 -0
index d681f91947d9..5b7668c04f76 100644
@@ -7050,6 +7050,7 @@ int smb2_lock(struct ksmbd_work *work)
 						      smb2_remove_blocked_lock,
 						      argv);
 				if (rc) {
+					kfree(argv);
 					err = -ENOMEM;
 					goto out;
 				}

fs/ksmbd/smb2pdu.c int smb2_lock(struct ksmbd_work *work) · line 7066

Quoted 5 lines
fs/ksmbd/smb2pdu.c +2 -0
@@ -7061,6 +7062,8 @@ int smb2_lock(struct ksmbd_work *work)
 
 				ksmbd_vfs_posix_lock_wait(flock);
 
+				work->cancel_fn = NULL;
+				kfree(argv);

This change seems to causes a NULL pointer dereference issue in set_close_state_blocked_works(). It is right to free it and set NULL after removing entry from list.

Quoted 7 lines
fs/ksmbd/smb2pdu.c +0 -1
 				if (work->state != KSMBD_WORK_ACTIVE) {
 					list_del(&smb_lock->llist);
 					spin_lock(&work->conn->llist_lock);
--

2.34.1

author
#2 lore raw
Quoted 24 lines · Namjae Jeon

2023-02-01 17:10 GMT+09:00, Hangyu Hua <[email protected]>:

Quoted 23 lines

argv needs to be free when setup_async_work fails or when the current process is woken up.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
---
  fs/ksmbd/smb2pdu.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ksmbd/smb2pdu.c +1 -0
index d681f91947d9..5b7668c04f76 100644
@@ -7050,6 +7050,7 @@ int smb2_lock(struct ksmbd_work *work)
  						      smb2_remove_blocked_lock,
  						      argv);
  				if (rc) {
+					kfree(argv);
  					err = -ENOMEM;
  					goto out;
  				}
@@ -7061,6 +7062,8 @@ int smb2_lock(struct ksmbd_work *work)
 
Quoted 7 lines

fs/ksmbd/smb2pdu.c int smb2_lock(struct ksmbd_work *work) · line 7066

Quoted 4 lines
fs/ksmbd/smb2pdu.c +2 -0
  				ksmbd_vfs_posix_lock_wait(flock);
 
+				work->cancel_fn = NULL;
+				kfree(argv);

This change seems to causes a NULL pointer dereference issue in set_close_state_blocked_works(). It is right to free it and set NULL after removing entry from list.

I get it. I will send a v2.

Thanks,
Hangyu

Quoted 7 lines
Quoted 7 lines
fs/ksmbd/smb2pdu.c +0 -1
  				if (work->state != KSMBD_WORK_ACTIVE) {
  					list_del(&smb_lock->llist);
  					spin_lock(&work->conn->llist_lock);
--

2.34.1