Skip to contentSkip to conversation

drbd: potential integer overflow in receive_SyncParam()

PATCH In review Dan Carpenter 2 participants 2 messages Jun 12, 2012

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

PATCH 1/1 drbd: potential integer overflow in receive_SyncParam()

I believe this comes from the network so there is a risk of integer overflow on 32 bit. Using kcalloc() is a little cleaner as well.

drivers/block/drbd/drbd_receiver.c +1 -1
index ea4836e..1e27876 100644
@@ -2902,7 +2902,7 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packets cmd, unsi
 
 			fifo_size = (mdev->sync_conf.c_plan_ahead * 10 * SLEEP_TIME) / HZ;
 			if (fifo_size != mdev->rs_plan_s.size && fifo_size > 0) {
-				rs_plan_s   = kzalloc(sizeof(int) * fifo_size, GFP_KERNEL);
+				rs_plan_s = kcalloc(fifo_size, sizeof(int), GFP_KERNEL);
 				if (!rs_plan_s) {
 					dev_err(DEV, "kmalloc of fifo_buffer failed");
 					goto disconnect;
maintainer
#1 lore raw
Quoted 10 lines · Dan Carpenter

I believe this comes from the network so there is a risk of integer overflow on 32 bit. Using kcalloc() is a little cleaner as well.

drivers/block/drbd/drbd_receiver.c +0 -0
index ea4836e..1e27876 100644

drivers/block/drbd/drbd_receiver.c static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packets cmd, unsi · line 2908

Quoted 8 lines
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -2902,7 +2902,7 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packets cmd, unsi
 
 			fifo_size = (mdev->sync_conf.c_plan_ahead * 10 * SLEEP_TIME) / HZ;
 			if (fifo_size != mdev->rs_plan_s.size && fifo_size > 0) {
-				rs_plan_s   = kzalloc(sizeof(int) * fifo_size, GFP_KERNEL);
+				rs_plan_s = kcalloc(fifo_size, sizeof(int), GFP_KERNEL);
 				if (!rs_plan_s) {
 					dev_err(DEV, "kmalloc of fifo_buffer failed");
 					goto disconnect;

sync_conf.c_plan_ahead is capped at 300 by drbdsetup. But yes, since this is not enforced in kernel code, your fix is correct.

Lars