Skip to contentSkip to conversation

ceph: fix wrong sizeof argument issue in register_session()

PATCH In review Viacheslav Dubeyko 2 participants 2 messages Jun 6, 2025 – Jun 8, 2025

Subsystems (2)
lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

PATCH 1/1 ceph: fix wrong sizeof argument issue in register_session()

From: Viacheslav Dubeyko <[email protected]>

The Coverity Scan service has detected the wrong sizeof argument in register_session() [1]. The CID 1598909 defect contains explanation: "The wrong sizeof value is used in an expression or as argument to a function. The result is an incorrect value that may cause unexpected program behaviors. In register_session: The sizeof operator is invoked on the wrong argument (CWE-569)".

The patch introduces a ptr_size variable that is initialized by sizeof(struct ceph_mds_session *). And this variable is used instead of sizeof(void *) in the code.

[1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1598909

---
 fs/ceph/mds_client.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +3 -2
index 230e0c3f341f..5181798643d7 100644
@@ -979,14 +979,15 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
 	if (mds >= mdsc->max_sessions) {
 		int newmax = 1 << get_count_order(mds + 1);
 		struct ceph_mds_session **sa;
+		size_t ptr_size = sizeof(struct ceph_mds_session *);
 
 		doutc(cl, "realloc to %d\n", newmax);
-		sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
+		sa = kcalloc(newmax, ptr_size, GFP_NOFS);
 		if (!sa)
 			goto fail_realloc;
 		if (mdsc->sessions) {
 			memcpy(sa, mdsc->sessions,
-			       mdsc->max_sessions * sizeof(void *));
+			       mdsc->max_sessions * ptr_size);
 			kfree(mdsc->sessions);
 		}
 		mdsc->sessions = sa;
Signature · 1 line
2.49.0
maintainer
#1 lore raw

Reviewed by: Alex Markuze <[email protected]>

Quoted 47 lines · Viacheslav Dubeyko

From: Viacheslav Dubeyko <[email protected]>

The Coverity Scan service has detected the wrong sizeof argument in register_session() [1]. The CID 1598909 defect contains explanation: "The wrong sizeof value is used in an expression or as argument to a function. The result is an incorrect value that may cause unexpected program behaviors. In register_session: The sizeof operator is invoked on the wrong argument (CWE-569)".

The patch introduces a ptr_size variable that is initialized by sizeof(struct ceph_mds_session *). And this variable is used instead of sizeof(void *) in the code.

[1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1598909

---
 fs/ceph/mds_client.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +3 -3
index 230e0c3f341f..5181798643d7 100644
@@ -979,14 +979,15 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
        if (mds >= mdsc->max_sessions) {
                int newmax = 1 << get_count_order(mds + 1);
                struct ceph_mds_session **sa;
+               size_t ptr_size = sizeof(struct ceph_mds_session *);
 
                doutc(cl, "realloc to %d\n", newmax);
-               sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
+               sa = kcalloc(newmax, ptr_size, GFP_NOFS);
                if (!sa)
                        goto fail_realloc;
                if (mdsc->sessions) {
                        memcpy(sa, mdsc->sessions,
-                              mdsc->max_sessions * sizeof(void *));
+                              mdsc->max_sessions * ptr_size);
                        kfree(mdsc->sessions);
                }
                mdsc->sessions = sa;
--

2.49.0