Skip to contentSkip to conversation

smb: server: smb2pdu: check return value of xa_store()

PATCH Superseded Salah Triki 1 participant 1 message Apr 15, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 smb: server: smb2pdu: check return value of xa_store()

xa_store() may fail so check its return value and return error code if error occurred.

---
Change in v2:
- Free chann before returning the error.

 fs/smb/server/smb2pdu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/smb/server/smb2pdu.c +9 -2
index d24d95d15d87..2219dc8e6740 100644
@@ -1445,7 +1445,7 @@ static int ntlm_authenticate(struct ksmbd_work *work,
 {
 	struct ksmbd_conn *conn = work->conn;
 	struct ksmbd_session *sess = work->sess;
-	struct channel *chann = NULL;
+	struct channel *chann = NULL, *old;
 	struct ksmbd_user *user;
 	u64 prev_id;
 	int sz, rc;
@@ -1557,7 +1557,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
 				return -ENOMEM;
 
 			chann->conn = conn;
-			xa_store(&sess->ksmbd_chann_list, (long)conn, chann, KSMBD_DEFAULT_GFP);
+			old = xa_store(&sess->ksmbd_chann_list, (long)conn, chann,
+					KSMBD_DEFAULT_GFP);
+			if (xa_is_err(old))
+				goto free_channel;
 		}
 	}
 
@@ -1574,6 +1577,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
 		return -ENOENT;
 	}
 	return 0;
+
+free_channel:
+	kfree(chann);
+	return xa_err(old);
 }
 
 #ifdef CONFIG_SMB_SERVER_KERBEROS5
Signature · 1 line
2.43.0