Skip to contentSkip to conversation

rbd: check snap_count against RBD_MAX_SNAP_COUNT

PATCH Applied Rosen Penev 3 participants 3 messages May 30 – Jun 1

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

PATCH 1/1 rbd: check snap_count against RBD_MAX_SNAP_COUNT

snap_count is u32 but the comparison is against a SIZE_MAX-derived value (~2^61 on 64-bit), which clang flags as always false with -Wtautological-constant-out-of-range-compare.

The proper check here should be that snap_count does not go over RBD_MAX_SNAP_COUNT.

Assisted-by Opencode:Big-pickle
---
 drivers/block/rbd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/rbd.c +2 -5
index 94709466ad19..25215c209484 100644
@@ -6075,12 +6075,9 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev,
 
 	/*
 	 * Make sure the reported number of snapshot ids wouldn't go
-	 * beyond the end of our buffer.  But before checking that,
-	 * make sure the computed size of the snapshot context we
-	 * allocate is representable in a size_t.
+	 * beyond the end of our buffer.
 	 */
-	if (snap_count > (SIZE_MAX - sizeof (struct ceph_snap_context))
-				 / sizeof (u64)) {
+	if (snap_count > RBD_MAX_SNAP_COUNT) {
 		ret = -EINVAL;
 		goto out;
 	}
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Rosen Penev

snap_count is u32 but the comparison is against a SIZE_MAX-derived value (~2^61 on 64-bit), which clang flags as always false with -Wtautological-constant-out-of-range-compare.

The proper check here should be that snap_count does not go over RBD_MAX_SNAP_COUNT.

Assisted-by Opencode:Big-pickle

Looks good to me.

Quoted 23 lines
---
  drivers/block/rbd.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/rbd.c +2 -5
index 94709466ad19..25215c209484 100644
@@ -6075,12 +6075,9 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev,
 
  	/*
  	 * Make sure the reported number of snapshot ids wouldn't go
-	 * beyond the end of our buffer.  But before checking that,
-	 * make sure the computed size of the snapshot context we
-	 * allocate is representable in a size_t.
+	 * beyond the end of our buffer.
  	 */
-	if (snap_count > (SIZE_MAX - sizeof (struct ceph_snap_context))
-				 / sizeof (u64)) {
+	if (snap_count > RBD_MAX_SNAP_COUNT) {
  		ret = -EINVAL;
  		goto out;
  	}
maintainer Applied
#2 lore raw
In reply to Rosen Penev
Quoted 8 lines · Rosen Penev

snap_count is u32 but the comparison is against a SIZE_MAX-derived value (~2^61 on 64-bit), which clang flags as always false with -Wtautological-constant-out-of-range-compare.

The proper check here should be that snap_count does not go over RBD_MAX_SNAP_COUNT.

[...]

Applied, thanks!

[1/1] rbd: check snap_count against RBD_MAX_SNAP_COUNT

      commit: 2e1b3f4c51ace14f67201bd2a92ca6312a3c3724

Best regards,

Signature · 1 line
Jens Axboe