Skip to contentSkip to conversation

cifs: Call the calc_signature functions directly

PATCH In review David Howells 3 participants 3 messages Oct 20, 2025 – Oct 21, 2025

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

PATCH 1/1 cifs: Call the calc_signature functions directly

As the SMB1 and SMB2/3 calc_signature functions are called from separate sign and verify paths, just call them directly rather than using a function pointer. The SMB3 calc_signature then jumps to the SMB2 variant if necessary.

---
 fs/smb/client/cifsglob.h      |    2 --
 fs/smb/client/smb2ops.c       |    4 ----
 fs/smb/client/smb2proto.h     |    6 ------
 fs/smb/client/smb2transport.c |   18 +++++++++---------
 4 files changed, 9 insertions(+), 21 deletions(-)
fs/smb/client/cifsglob.h +0 -2
index b91397dbb6aa..7297f0f01cb3 100644
@@ -536,8 +536,6 @@ struct smb_version_operations {
 	void (*new_lease_key)(struct cifs_fid *);
 	int (*generate_signingkey)(struct cifs_ses *ses,
 				   struct TCP_Server_Info *server);
-	int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *,
-				bool allocate_crypto);
 	int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon,
 			     struct cifsFileInfo *src_file);
 	int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
fs/smb/client/smb2ops.c +0 -4
index 7c392cf5940b..66eee3440df6 100644
@@ -5446,7 +5446,6 @@ struct smb_version_operations smb20_operations = {
 	.get_lease_key = smb2_get_lease_key,
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
-	.calc_signature = smb2_calc_signature,
 	.is_read_op = smb2_is_read_op,
 	.set_oplock_level = smb2_set_oplock_level,
 	.create_lease_buf = smb2_create_lease_buf,
@@ -5550,7 +5549,6 @@ struct smb_version_operations smb21_operations = {
 	.get_lease_key = smb2_get_lease_key,
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
-	.calc_signature = smb2_calc_signature,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb21_set_oplock_level,
 	.create_lease_buf = smb2_create_lease_buf,
@@ -5660,7 +5658,6 @@ struct smb_version_operations smb30_operations = {
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
 	.generate_signingkey = generate_smb30signingkey,
-	.calc_signature = smb3_calc_signature,
 	.set_integrity  = smb3_set_integrity,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb3_set_oplock_level,
@@ -5777,7 +5774,6 @@ struct smb_version_operations smb311_operations = {
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
 	.generate_signingkey = generate_smb311signingkey,
-	.calc_signature = smb3_calc_signature,
 	.set_integrity  = smb3_set_integrity,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb3_set_oplock_level,
fs/smb/client/smb2proto.h +0 -6
index b3f1398c9f79..7e98fbe7bf33 100644
@@ -39,12 +39,6 @@ extern struct mid_q_entry *smb2_setup_async_request(
 			struct TCP_Server_Info *server, struct smb_rqst *rqst);
 extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
 						__u64 ses_id, __u32  tid);
-extern int smb2_calc_signature(struct smb_rqst *rqst,
-				struct TCP_Server_Info *server,
-				bool allocate_crypto);
-extern int smb3_calc_signature(struct smb_rqst *rqst,
-				struct TCP_Server_Info *server,
-				bool allocate_crypto);
 extern void smb2_echo_request(struct work_struct *work);
 extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
 extern bool smb2_is_valid_oplock_break(char *buffer,
fs/smb/client/smb2transport.c +9 -9
index 33f33013b392..916c131d763d 100644
@@ -247,9 +247,9 @@ smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32  tid)
 	return tcon;
 }
 
-int
+static int
 smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-			bool allocate_crypto)
+		    bool allocate_crypto)
 {
 	int rc;
 	unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
@@ -576,9 +576,9 @@ generate_smb311signingkey(struct cifs_ses *ses,
 	return generate_smb3signingkey(ses, server, &triplet);
 }
 
-int
+static int
 smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-			bool allocate_crypto)
+		    bool allocate_crypto)
 {
 	int rc;
 	unsigned char smb3_signature[SMB2_CMACAES_SIZE];
@@ -589,6 +589,9 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
 	struct smb_rqst drqst;
 	u8 key[SMB3_SIGN_KEY_SIZE];
 
+	if ((server->vals->protocol_id & 0xf00) == 0x200)
+		return smb2_calc_signature(rqst, server, allocate_crypto);
+
 	rc = smb3_get_sign_key(le64_to_cpu(shdr->SessionId), server, key);
 	if (unlikely(rc)) {
 		cifs_server_dbg(FYI, "%s: Could not get signing key\n", __func__);
@@ -657,7 +660,6 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
 static int
 smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 {
-	int rc = 0;
 	struct smb2_hdr *shdr;
 	struct smb2_sess_setup_req *ssr;
 	bool is_binding;
@@ -684,9 +686,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 		return 0;
 	}
 
-	rc = server->ops->calc_signature(rqst, server, false);
-
-	return rc;
+	return smb3_calc_signature(rqst, server, false);
 }
 
 int
@@ -722,7 +722,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 
 	memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
 
-	rc = server->ops->calc_signature(rqst, server, true);
+	rc = smb3_calc_signature(rqst, server, true);
 
 	if (rc)
 		return rc;
Acked-by on v1 1/1
#1 lore raw

Hi David,

Quoted 112 lines · David Howells

As the SMB1 and SMB2/3 calc_signature functions are called from separate sign and verify paths, just call them directly rather than using a function pointer. The SMB3 calc_signature then jumps to the SMB2 variant if necessary.

---

fs/smb/client/cifsglob.h      |    2 --
fs/smb/client/smb2ops.c       |    4 ----
fs/smb/client/smb2proto.h     |    6 ------
fs/smb/client/smb2transport.c |   18 +++++++++---------
4 files changed, 9 insertions(+), 21 deletions(-)
fs/smb/client/cifsglob.h +0 -2
index b91397dbb6aa..7297f0f01cb3 100644
@@ -536,8 +536,6 @@ struct smb_version_operations {
 	void (*new_lease_key)(struct cifs_fid *);
 	int (*generate_signingkey)(struct cifs_ses *ses,
 				   struct TCP_Server_Info *server);
-	int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *,
-				bool allocate_crypto);
 	int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon,
 			     struct cifsFileInfo *src_file);
 	int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
fs/smb/client/smb2ops.c +0 -4
index 7c392cf5940b..66eee3440df6 100644
@@ -5446,7 +5446,6 @@ struct smb_version_operations smb20_operations = {
 	.get_lease_key = smb2_get_lease_key,
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
-	.calc_signature = smb2_calc_signature,
 	.is_read_op = smb2_is_read_op,
 	.set_oplock_level = smb2_set_oplock_level,
 	.create_lease_buf = smb2_create_lease_buf,
@@ -5550,7 +5549,6 @@ struct smb_version_operations smb21_operations = {
 	.get_lease_key = smb2_get_lease_key,
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
-	.calc_signature = smb2_calc_signature,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb21_set_oplock_level,
 	.create_lease_buf = smb2_create_lease_buf,
@@ -5660,7 +5658,6 @@ struct smb_version_operations smb30_operations = {
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
 	.generate_signingkey = generate_smb30signingkey,
-	.calc_signature = smb3_calc_signature,
 	.set_integrity  = smb3_set_integrity,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb3_set_oplock_level,
@@ -5777,7 +5774,6 @@ struct smb_version_operations smb311_operations = {
 	.set_lease_key = smb2_set_lease_key,
 	.new_lease_key = smb2_new_lease_key,
 	.generate_signingkey = generate_smb311signingkey,
-	.calc_signature = smb3_calc_signature,
 	.set_integrity  = smb3_set_integrity,
 	.is_read_op = smb21_is_read_op,
 	.set_oplock_level = smb3_set_oplock_level,
fs/smb/client/smb2proto.h +0 -6
index b3f1398c9f79..7e98fbe7bf33 100644
@@ -39,12 +39,6 @@ extern struct mid_q_entry *smb2_setup_async_request(
 			struct TCP_Server_Info *server, struct smb_rqst *rqst);
 extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
 						__u64 ses_id, __u32  tid);
-extern int smb2_calc_signature(struct smb_rqst *rqst,
-				struct TCP_Server_Info *server,
-				bool allocate_crypto);
-extern int smb3_calc_signature(struct smb_rqst *rqst,
-				struct TCP_Server_Info *server,
-				bool allocate_crypto);
 extern void smb2_echo_request(struct work_struct *work);
 extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
 extern bool smb2_is_valid_oplock_break(char *buffer,
fs/smb/client/smb2transport.c +4 -4
index 33f33013b392..916c131d763d 100644
@@ -247,9 +247,9 @@ smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32  tid)
 	return tcon;
 }
 
-int
+static int
 smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-			bool allocate_crypto)
+		    bool allocate_crypto)
 {
 	int rc;
 	unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
@@ -576,9 +576,9 @@ generate_smb311signingkey(struct cifs_ses *ses,
 	return generate_smb3signingkey(ses, server, &triplet);
 }
 
-int
+static int
 smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-			bool allocate_crypto)
+		    bool allocate_crypto)
 {
 	int rc;
 	unsigned char smb3_signature[SMB2_CMACAES_SIZE];

fs/smb/client/smb2transport.c smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server, · line 592

Quoted 4 lines
fs/smb/client/smb2transport.c +1 -0
@@ -589,6 +589,9 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
 	struct smb_rqst drqst;
 	u8 key[SMB3_SIGN_KEY_SIZE];
 
+	if ((server->vals->protocol_id & 0xf00) == 0x200)

Please use:

if (server->vals->protocol_id <= SMB21_PROT_ID)

Other than that

Quoted 35 lines
fs/smb/client/smb2transport.c +2 -0
+		return smb2_calc_signature(rqst, server, allocate_crypto);
+
 	rc = smb3_get_sign_key(le64_to_cpu(shdr->SessionId), server, key);
 	if (unlikely(rc)) {
 		cifs_server_dbg(FYI, "%s: Could not get signing key\n", __func__);
@@ -657,7 +660,6 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,

static int
smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) {

fs/smb/client/smb2transport.c +0 -1
-	int rc = 0;
	struct smb2_hdr *shdr;
	struct smb2_sess_setup_req *ssr;
	bool is_binding;
fs/smb/client/smb2transport.c +1 -3
@@ -684,9 +686,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 		return 0;
 	}
 
-	rc = server->ops->calc_signature(rqst, server, false);
-
-	return rc;
+	return smb3_calc_signature(rqst, server, false);
 }
 

int

fs/smb/client/smb2transport.c +1 -1
@@ -722,7 +722,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 
 	memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
 
-	rc = server->ops->calc_signature(rqst, server, true);
+	rc = smb3_calc_signature(rqst, server, true);
 
 	if (rc)
 		return rc;
#2 lore raw

merged updated patch into cifs-2.6.git for-next (and also has Enzo Acked-by now)

Quoted 165 lines · Enzo Matsumiya

Hi David,

Quoted 112 lines · David Howells

As the SMB1 and SMB2/3 calc_signature functions are called from separate sign and verify paths, just call them directly rather than using a function pointer. The SMB3 calc_signature then jumps to the SMB2 variant if necessary.

---

fs/smb/client/cifsglob.h      |    2 --
fs/smb/client/smb2ops.c       |    4 ----
fs/smb/client/smb2proto.h     |    6 ------
fs/smb/client/smb2transport.c |   18 +++++++++---------
4 files changed, 9 insertions(+), 21 deletions(-)
fs/smb/client/cifsglob.h +0 -2
index b91397dbb6aa..7297f0f01cb3 100644
@@ -536,8 +536,6 @@ struct smb_version_operations {
      void (*new_lease_key)(struct cifs_fid *);
      int (*generate_signingkey)(struct cifs_ses *ses,
                                 struct TCP_Server_Info *server);
-      int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *,
-                              bool allocate_crypto);
      int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon,
                           struct cifsFileInfo *src_file);
      int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
fs/smb/client/smb2ops.c +0 -4
index 7c392cf5940b..66eee3440df6 100644
@@ -5446,7 +5446,6 @@ struct smb_version_operations smb20_operations = {
      .get_lease_key = smb2_get_lease_key,
      .set_lease_key = smb2_set_lease_key,
      .new_lease_key = smb2_new_lease_key,
-      .calc_signature = smb2_calc_signature,
      .is_read_op = smb2_is_read_op,
      .set_oplock_level = smb2_set_oplock_level,
      .create_lease_buf = smb2_create_lease_buf,
@@ -5550,7 +5549,6 @@ struct smb_version_operations smb21_operations = {
      .get_lease_key = smb2_get_lease_key,
      .set_lease_key = smb2_set_lease_key,
      .new_lease_key = smb2_new_lease_key,
-      .calc_signature = smb2_calc_signature,
      .is_read_op = smb21_is_read_op,
      .set_oplock_level = smb21_set_oplock_level,
      .create_lease_buf = smb2_create_lease_buf,
@@ -5660,7 +5658,6 @@ struct smb_version_operations smb30_operations = {
      .set_lease_key = smb2_set_lease_key,
      .new_lease_key = smb2_new_lease_key,
      .generate_signingkey = generate_smb30signingkey,
-      .calc_signature = smb3_calc_signature,
      .set_integrity  = smb3_set_integrity,
      .is_read_op = smb21_is_read_op,
      .set_oplock_level = smb3_set_oplock_level,
@@ -5777,7 +5774,6 @@ struct smb_version_operations smb311_operations = {
      .set_lease_key = smb2_set_lease_key,
      .new_lease_key = smb2_new_lease_key,
      .generate_signingkey = generate_smb311signingkey,
-      .calc_signature = smb3_calc_signature,
      .set_integrity  = smb3_set_integrity,
      .is_read_op = smb21_is_read_op,
      .set_oplock_level = smb3_set_oplock_level,
fs/smb/client/smb2proto.h +0 -6
index b3f1398c9f79..7e98fbe7bf33 100644
@@ -39,12 +39,6 @@ extern struct mid_q_entry *smb2_setup_async_request(
                      struct TCP_Server_Info *server, struct smb_rqst *rqst);
 extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
                                              __u64 ses_id, __u32  tid);
-extern int smb2_calc_signature(struct smb_rqst *rqst,
-                              struct TCP_Server_Info *server,
-                              bool allocate_crypto);
-extern int smb3_calc_signature(struct smb_rqst *rqst,
-                              struct TCP_Server_Info *server,
-                              bool allocate_crypto);
 extern void smb2_echo_request(struct work_struct *work);
 extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
 extern bool smb2_is_valid_oplock_break(char *buffer,
fs/smb/client/smb2transport.c +4 -4
index 33f33013b392..916c131d763d 100644
@@ -247,9 +247,9 @@ smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32  tid)
      return tcon;
 }
 
-int
+static int
 smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-                      bool allocate_crypto)
+                  bool allocate_crypto)
 {
      int rc;
      unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
@@ -576,9 +576,9 @@ generate_smb311signingkey(struct cifs_ses *ses,
      return generate_smb3signingkey(ses, server, &triplet);
 }
 
-int
+static int
 smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
-                      bool allocate_crypto)
+                  bool allocate_crypto)
 {
      int rc;
      unsigned char smb3_signature[SMB2_CMACAES_SIZE];

fs/smb/client/smb2transport.c smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server, · line 592

Quoted 4 lines
fs/smb/client/smb2transport.c +1 -0
@@ -589,6 +589,9 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
      struct smb_rqst drqst;
      u8 key[SMB3_SIGN_KEY_SIZE];
 
+      if ((server->vals->protocol_id & 0xf00) == 0x200)

Please use:

   if (server->vals->protocol_id <= SMB21_PROT_ID)

Other than that

Quoted 35 lines
fs/smb/client/smb2transport.c +2 -0
+              return smb2_calc_signature(rqst, server, allocate_crypto);
+
      rc = smb3_get_sign_key(le64_to_cpu(shdr->SessionId), server, key);
      if (unlikely(rc)) {
              cifs_server_dbg(FYI, "%s: Could not get signing key\n", __func__);
@@ -657,7 +660,6 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,

static int
smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) {

fs/smb/client/smb2transport.c +1 -4
-      int rc = 0;
      struct smb2_hdr *shdr;
      struct smb2_sess_setup_req *ssr;
      bool is_binding;
@@ -684,9 +686,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
              return 0;
      }
 
-      rc = server->ops->calc_signature(rqst, server, false);
-
-      return rc;
+      return smb3_calc_signature(rqst, server, false);
 }
 

int

fs/smb/client/smb2transport.c +1 -1
@@ -722,7 +722,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 
      memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
 
-      rc = server->ops->calc_signature(rqst, server, true);
+      rc = smb3_calc_signature(rqst, server, true);
 
      if (rc)
              return rc;
Signature · 3 lines
Thanks,

Steve