Skip to contentSkip to conversation

libceph: Amend checking to fix `make W=1` build breakage

PATCH In review Andy Shevchenko 2 participants 7 messages Nov 10, 2025 – Nov 24, 2025 Ceph common code (libceph)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libceph: Amend checking to fix `make W=1` build breakage

In a few cases the code compares 32-bit value to a SIZE_MAX derived constant which is much higher than that value on 64-bit platforms, Clang, in particular, is not happy about this

net/ceph/osdmap.c:1441:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
1441 | if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))

      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ceph/osdmap.c:1624:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
 1624 |         if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

fs/ceph/snap.c:377:10: error: result of comparison of constant 2305843009213693948 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
377 | if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))

      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix this by casting to size_t. Note, that possible replacement of SIZE_MAX by U32_MAX may lead to the behaviour changes on the corner cases.

---
 net/ceph/osdmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ceph/osdmap.c +2 -2
index 295098873861..8e7cb2fde6f1 100644
@@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);
@@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
 	u32 len, i;
 
 	ceph_decode_32_safe(p, end, len, e_inval);
-	if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
Signature · 1 line
2.50.1
#1 lore raw
Quoted 37 lines · Andy Shevchenko

In a few cases the code compares 32-bit value to a SIZE_MAX derived constant which is much higher than that value on 64-bit platforms, Clang, in particular, is not happy about this

net/ceph/osdmap.c:1441:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
1441 | if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))

      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ceph/osdmap.c:1624:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
 1624 |         if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

fs/ceph/snap.c:377:10: error: result of comparison of constant 2305843009213693948 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
377 | if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))

      |             ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix this by casting to size_t. Note, that possible replacement of SIZE_MAX by U32_MAX may lead to the behaviour changes on the corner cases.

---
 net/ceph/osdmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ceph/osdmap.c +1 -1
index 295098873861..8e7cb2fde6f1 100644
@@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);

net/ceph/osdmap.c static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end, · line 1621

Quoted 1 line
net/ceph/osdmap.c +0 -0
@@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
 	u32 len, i;

I am guessing... What if we change the declaration of len on size_t, then could it be more clear solution here? For example, let's consider this for both cases:

size_t len, i;

Could it eliminate the issue and to make the Clang happy? Or could it introduce another warnings/issues?

Thanks,
Slava.

Quoted 7 lines
net/ceph/osdmap.c +1 -1
 	ceph_decode_32_safe(p, end, len, e_inval);
-	if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
#2 lore raw
Quoted 1 line · Viacheslav Dubeyko

On Mon, 2025-11-10 at 15:46 +0100, Andy Shevchenko wrote:

...

Quoted 12 lines

net/ceph/osdmap.c static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · line 1444

Quoted 8 lines
net/ceph/osdmap.c +1 -1
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);

I am guessing... What if we change the declaration of len on size_t, then could it be more clear solution here? For example, let's consider this for both cases:

Quoted 4 lines

size_t len, i;

Could it eliminate the issue and to make the Clang happy? Or could it introduce another warnings/issues?

Probably, but the code is pierced with the sizeof(u32) and alike, moreover size_t is architecture-dependent type, while the set of macros in decode.h seems to operate on the fixed-width type. That said, I prefer my way of fixing this. But if you find another, better one, I am all ears!

*Also note, I'm not familiar with the guts of the ceph, so maybe your solution is the best, but I want more people to confirm this.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by
#3 lore raw
Quoted 22 lines · On Mon, 2025-11-10 at 21:36 +0200, [email protected] wrote:
Quoted 1 line · Viacheslav Dubeyko

On Mon, 2025-11-10 at 15:46 +0100, Andy Shevchenko wrote:

...

Quoted 12 lines

net/ceph/osdmap.c static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · line 1444

Quoted 8 lines
net/ceph/osdmap.c +1 -1
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);

I am guessing... What if we change the declaration of len on size_t, then could it be more clear solution here? For example, let's consider this for both cases:

Quoted 4 lines

size_t len, i;

Could it eliminate the issue and to make the Clang happy? Or could it introduce another warnings/issues?

Quoted 7 lines

Probably, but the code is pierced with the sizeof(u32) and alike, moreover size_t is architecture-dependent type, while the set of macros in decode.h seems to operate on the fixed-width type. That said, I prefer my way of fixing this. But if you find another, better one, I am all ears!

*Also note, I'm not familiar with the guts of the ceph, so maybe your solution is the best, but I want more people to confirm this.

I think the patch looks good as it is. And we can take it. If we find the better way
of fixing this, then we can do it anytime.

Thanks,
Slava.

#4 lore raw
Quoted 3 lines · Viacheslav Dubeyko
Quoted 2 lines · On Mon, 2025-11-10 at 21:36 +0200, [email protected] wrote:
Quoted 1 line · Viacheslav Dubeyko

On Mon, 2025-11-10 at 15:46 +0100, Andy Shevchenko wrote:

...

Quoted 22 lines
Quoted 22 lines
Quoted 12 lines

net/ceph/osdmap.c static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · line 1444

Quoted 8 lines
net/ceph/osdmap.c +1 -1
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);

I am guessing... What if we change the declaration of len on size_t, then could it be more clear solution here? For example, let's consider this for both cases:

Quoted 4 lines

size_t len, i;

Could it eliminate the issue and to make the Clang happy? Or could it introduce another warnings/issues?

Probably, but the code is pierced with the sizeof(u32) and alike, moreover size_t is architecture-dependent type, while the set of macros in decode.h seems to operate on the fixed-width type. That said, I prefer my way of fixing this. But if you find another, better one, I am all ears!

Quoted 8 lines
Quoted 2 lines

*Also note, I'm not familiar with the guts of the ceph, so maybe your solution is the best, but I want more people to confirm this.

I think the patch looks good as it is. And we can take it. If we find the better way
of fixing this, then we can do it anytime.

Thanks, can this be applied? My builds are still broken.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 32 lines · On Mon, 2025-11-24 at 17:09 +0200, [email protected] wrote:
Quoted 3 lines · Viacheslav Dubeyko
Quoted 2 lines · On Mon, 2025-11-10 at 21:36 +0200, [email protected] wrote:
Quoted 1 line · Viacheslav Dubeyko

On Mon, 2025-11-10 at 15:46 +0100, Andy Shevchenko wrote:

...

Quoted 25 lines
Quoted 24 lines
Quoted 12 lines

net/ceph/osdmap.c static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · line 1444

Quoted 8 lines
net/ceph/osdmap.c +1 -1
 	ceph_decode_32_safe(p, end, len, e_inval);
 	if (len == 0 && incremental)
 		return NULL;	/* new_pg_temp: [] to remove */
-	if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+	if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
 		return ERR_PTR(-EINVAL);
 
 	ceph_decode_need(p, end, len * sizeof(u32), e_inval);

I am guessing... What if we change the declaration of len on size_t, then could it be more clear solution here? For example, let's consider this for both cases:

Quoted 4 lines

size_t len, i;

Could it eliminate the issue and to make the Clang happy? Or could it introduce another warnings/issues?

Probably, but the code is pierced with the sizeof(u32) and alike, moreover size_t is architecture-dependent type, while the set of macros in decode.h seems to operate on the fixed-width type. That said, I prefer my way of fixing this. But if you find another, better one, I am all ears!

*Also note, I'm not familiar with the guts of the ceph, so maybe your solution is the best, but I want more people to confirm this.

Quoted 7 lines
Quoted 5 lines

I think the patch looks good as it is. And we can take it. If we find the better way
of fixing this, then we can do it anytime.

Thanks, can this be applied? My builds are still broken.

The patchset has been applied on testing branch already [1].

Ilya, when are we planning to send this patchset upstream?

Thanks,
Slava.

[1] https://github.com/ceph/ceph-client.git

#6 lore raw
Quoted 2 lines · Viacheslav Dubeyko
Quoted 1 line · On Mon, 2025-11-24 at 17:09 +0200, [email protected] wrote:

On Mon, Nov 10, 2025 at 08:39:49PM +0000, Viacheslav Dubeyko wrote:

...

Quoted 3 lines
Quoted 1 line

Thanks, can this be applied? My builds are still broken.

The patchset has been applied on testing branch already [1].

Thanks again, and same recommendation as per previous email.

Quoted 3 lines

Ilya, when are we planning to send this patchset upstream?

[1] https://github.com/ceph/ceph-client.git

Signature · 2 lines
With Best Regards,
Andy Shevchenko