]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cifs: Call the calc_signature functions directly
authorDavid Howells <dhowells@redhat.com>
Tue, 14 Oct 2025 17:10:08 +0000 (18:10 +0100)
committerSteve French <stfrench@microsoft.com>
Thu, 23 Oct 2025 07:47:20 +0000 (02:47 -0500)
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.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Enzo Matsumiya <ematsumiya@suse.de>
cc: Paulo Alcantara <pc@manguebit.org>
cc: Shyam Prasad N <sprasad@microsoft.com>
cc: Tom Talpey <tom@talpey.com>
cc: linux-cifs@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifsglob.h
fs/smb/client/smb2ops.c
fs/smb/client/smb2proto.h
fs/smb/client/smb2transport.c

index 00982aa9428f0eba3b5f1163a4a5992ce9c365d6..203e2aaa3c2500b24eaa4f053a3d0d4e0f640b8d 100644 (file)
@@ -534,8 +534,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,
index 95cd484cfbba5b9f800f4d46cd1f7ee509ced0a1..0f9130ef2e7d6d9290f32f9b930fba2f231d697b 100644 (file)
@@ -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,
index 6eb86d134abcc5d2486444146903a6c4a3f22b35..5241daaae5433e23b21df0d5b0460afe9f957556 100644 (file)
@@ -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,
index ad6068e17a2a99e81b782e8a8a4a7731d07e7807..6a9b80385b86b9dac24f215690e99ddc9b745b84 100644 (file)
@@ -209,9 +209,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];
@@ -465,9 +465,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];
@@ -477,6 +477,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 <= SMB21_PROT_ID)
+               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__);
@@ -547,7 +550,6 @@ out:
 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;
@@ -574,9 +576,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
@@ -612,7 +612,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;