Skip to contentSkip to conversation

nbd: allocate sufficient space for NBD_CMD_STATUS

PATCH New Thadeu Lima de Souza Cascardo 1 participant 2 messages Jun 18, 2020

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

PATCH 1/1 nbd: allocate sufficient space for NBD_CMD_STATUS

The nest attribute NBD_ATTR_DEVICE_LIST was not accounted for when allocating the message, resulting in -EMSGSIZE.

As __alloc_skb aligns size requests to SMP_CACHE_BYTES and SLUB will end up allocating more than requested, this can hardly be reproduced on most setups.

However, I managed to test this on a 32-bit x86 with 15 entries, by loading with nbds_max=15. It failed with -EMSGSIZE, while it worked with 14 or 16 entries.

---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 43cff01a5a67..19551d8ca355 100644
@@ -2265,6 +2265,7 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	msg_size = nla_total_size(nla_attr_size(sizeof(u32)) +
 				  nla_attr_size(sizeof(u8)));
 	msg_size *= (index == -1) ? nbd_total_devices : 1;
+	msg_size += nla_total_size(0); /* for NBD_ATTR_DEVICE_LIST */
 
 	reply = genlmsg_new(msg_size, GFP_KERNEL);
 	if (!reply)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 nbd: allocate sufficient space for NBD_CMD_STATUS

The nest attribute NBD_ATTR_DEVICE_LIST was not accounted for when allocating the message, resulting in -EMSGSIZE.

As __alloc_skb aligns size requests to SMP_CACHE_BYTES and SLUB will end up allocating more than requested, this can hardly be reproduced on most setups.

However, I managed to test this on a 32-bit x86 with 15 entries, by loading with nbds_max=15. It failed with -EMSGSIZE, while it worked with 14 or 16 entries.

---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 43cff01a5a67..19551d8ca355 100644
@@ -2265,6 +2265,7 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	msg_size = nla_total_size(nla_attr_size(sizeof(u32)) +
 				  nla_attr_size(sizeof(u8)));
 	msg_size *= (index == -1) ? nbd_total_devices : 1;
+	msg_size += nla_total_size(0); /* for NBD_ATTR_DEVICE_LIST */
 
 	reply = genlmsg_new(msg_size, GFP_KERNEL);
 	if (!reply)
Signature · 1 line
2.25.1