Skip to contentSkip to conversation

smb: client: Better exception handling for SMB3 hash allocations

PATCH Applied Markus Elfring 2 participants 7 messages Oct 10, 2025 – Oct 13, 2025

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

cover smb: client: Better exception handling for SMB3 hash allocations

From: Markus Elfring <[email protected]>
Date: Fri, 10 Oct 2025 08:40:08 +0200

Refine a few implementation details for further development considerations.

Markus Elfring (3):
Return directly after a failed cifs_alloc_hash()
in smb3_crypto_shash_allocate()
Improve resource release
in smb311_crypto_shash_allocate()
Omit a variable initialisation
in smb311_crypto_shash_allocate()

 fs/smb/client/smb2transport.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/3 smb: client: Return directly after a failed cifs_alloc_hash() in smb3_crypto_shash_allocate()

From: Markus Elfring <[email protected]>
Date: Thu, 9 Oct 2025 18:44:53 +0200

Return directly after a call of the function “cifs_alloc_hash” failed at the beginning.

---
 fs/smb/client/smb2transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2transport.c +1 -1
index bc0e92eb2b64..499b00c2a001 100644
@@ -34,7 +34,7 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
 
 	rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
 	if (rc)
-		goto err;
+		return rc;
 
 	rc = cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
 	if (rc)
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/3 smb: client: Improve resource release in smb311_crypto_shash_allocate()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 9 Oct 2025 19:00:11 +0200

Adjust jump targets so that cifs_free_hash() functions will be called in a recommended order at the end of this function implementation.

---
 fs/smb/client/smb2transport.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/smb/client/smb2transport.c +4 -3
index 499b00c2a001..b790f6b970a9 100644
@@ -58,16 +58,17 @@ smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
 
 	rc = cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
 	if (rc)
-		goto err;
+		goto free_hmacsha256;
 
 	rc = cifs_alloc_hash("sha512", &p->sha512);
 	if (rc)
-		goto err;
+		goto free_aes_cmac;
 
 	return 0;
 
-err:
+free_aes_cmac:
 	cifs_free_hash(&p->aes_cmac);
+free_hmacsha256:
 	cifs_free_hash(&p->hmacsha256);
 	return rc;
 }
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/3 smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 10 Oct 2025 08:05:21 +0200
Subject: [PATCH 3/3] smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The local variable “rc” is immediately reassigned. Thus omit the explicit initialisation at the beginning.

---
 fs/smb/client/smb2transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2transport.c +1 -1
index b790f6b970a9..3f8b0509f8c8 100644
@@ -50,7 +50,7 @@ int
 smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
 {
 	struct cifs_secmech *p = &server->secmech;
-	int rc = 0;
+	int rc;
 
 	rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
 	if (rc)
Signature · 1 line
2.51.0
Applied
#4 lore raw

Re: [PATCH 3/3] smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()

merged into cifs-2.6.git for-next

Quoted 34 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 10 Oct 2025 08:05:21 +0200
Subject: [PATCH 3/3] smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The local variable “rc” is immediately reassigned. Thus omit the explicit initialisation at the beginning.

---
 fs/smb/client/smb2transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2transport.c +1 -2
index b790f6b970a9..3f8b0509f8c8 100644
@@ -50,7 +50,7 @@ int
 smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
 {
        struct cifs_secmech *p = &server->secmech;
-       int rc = 0;
+       int rc;
 
        rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
        if (rc)
--

2.51.0

Signature · 3 lines
Thanks,

Steve
#5 lore raw

Re: [PATCH 3/3] smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()

Removed from cifs-2.6.git for-next, as it conflicts with Eric's recent patch series ("smb: client: More crypto library conversions").

Obviously one of the problems of minor cleanup patches, is they can cause noise like this

Quoted 44 lines · Steve French

merged into cifs-2.6.git for-next

Quoted 30 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 10 Oct 2025 08:05:21 +0200
Subject: [PATCH 3/3] smb: client: Omit a variable initialisation in smb311_crypto_shash_allocate()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The local variable “rc” is immediately reassigned. Thus omit the explicit initialisation at the beginning.

---
 fs/smb/client/smb2transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2transport.c +1 -2
index b790f6b970a9..3f8b0509f8c8 100644
@@ -50,7 +50,7 @@ int
 smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
 {
        struct cifs_secmech *p = &server->secmech;
-       int rc = 0;
+       int rc;
 
        rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
        if (rc)
--
Quoted 4 lines

2.51.0

--
Thanks,

Steve

Signature · 3 lines
Thanks,

Steve