Skip to contentSkip to conversation

drbd: silence underflow warning in read_in_block()

PATCH In review Dan Carpenter 2 participants 2 messages May 6, 2014 – May 7, 2014

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

PATCH 1/1 drbd: silence underflow warning in read_in_block()

My static checker warns that "data_size" could be negative and underflow the limit check. The code looks suspicious but I don't know if it is a real bug.

drivers/block/drbd/drbd_receiver.c +1 -1
index b6c8aaf..15daf86d 100644
@@ -1528,7 +1528,7 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector,
 	struct drbd_peer_request *peer_req;
 	struct page *page;
 	int dgs, ds, err;
-	int data_size = pi->size;
+	unsigned int data_size = pi->size;
 	void *dig_in = peer_device->connection->int_dig_in;
 	void *dig_vv = peer_device->connection->int_dig_vv;
 	unsigned long *data;
maintainer
#1 lore raw
Quoted 3 lines · Dan Carpenter

My static checker warns that "data_size" could be negative and underflow the limit check. The code looks suspicious but I don't know if it is a real bug.

"real life" bug only if you manage to receive corrupted data. The maximum sent payload is DRBD_BIO_MAX_SIZE
which is an architecture independend constant (1U << 20).

Patch is correct, but while at it, we should revisit all "int data_size", and make them all unsigned int...

Lars

Quoted 16 lines
drivers/block/drbd/drbd_receiver.c +1 -1
index b6c8aaf..15daf86d 100644
@@ -1528,7 +1528,7 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector,
 	struct drbd_peer_request *peer_req;
 	struct page *page;
 	int dgs, ds, err;
-	int data_size = pi->size;
+	unsigned int data_size = pi->size;
 	void *dig_in = peer_device->connection->int_dig_in;
 	void *dig_vv = peer_device->connection->int_dig_vv;
 	unsigned long *data;