Skip to content

Commit 7704446

Browse files
Raphael Zimmeridryomov
authored andcommitted
libceph: Use u32 for non-negative values in ceph_monmap_decode()
This patch fixes unnecessary implicit conversions that change signedness of blob_len and num_mon in ceph_monmap_decode(). Currently blob_len and num_mon are (signed) int variables. They are used to hold values that are always non-negative and get assigned in ceph_decode_32_safe(), which is meant to assign u32 values. Both variables are subsequently used as unsigned values, and the value of num_mon is further assigned to monmap->num_mon, which is of type u32. Therefore, both variables should be of type u32. This is especially relevant for num_mon. If the value read from the incoming message is very large, it is interpreted as a negative value, and the check for num_mon > CEPH_MAX_MON does not catch it. This leads to the attempt to allocate a very large chunk of memory for monmap, which will most likely fail. In this case, an unnecessary attempt to allocate memory is performed, and -ENOMEM is returned instead of -EINVAL. Cc: [email protected] Signed-off-by: Raphael Zimmer <[email protected]> Reviewed-by: Viacheslav Dubeyko <[email protected]> Reviewed-by: Ilya Dryomov <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent a5f930e commit 7704446

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

net/ceph/mon_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static struct ceph_monmap *ceph_monmap_decode(void **p, void *end, bool msgr2)
7272
struct ceph_monmap *monmap = NULL;
7373
struct ceph_fsid fsid;
7474
u32 struct_len;
75-
int blob_len;
76-
int num_mon;
75+
u32 blob_len;
76+
u32 num_mon;
7777
u8 struct_v;
7878
u32 epoch;
7979
int ret;
@@ -112,7 +112,7 @@ static struct ceph_monmap *ceph_monmap_decode(void **p, void *end, bool msgr2)
112112
}
113113
ceph_decode_32_safe(p, end, num_mon, e_inval);
114114

115-
dout("%s fsid %pU epoch %u num_mon %d\n", __func__, &fsid, epoch,
115+
dout("%s fsid %pU epoch %u num_mon %u\n", __func__, &fsid, epoch,
116116
num_mon);
117117
if (num_mon > CEPH_MAX_MON)
118118
goto e_inval;

0 commit comments

Comments
 (0)