Skip to contentSkip to conversation

nfs/blocklayout: reject stripe volume with zero chunk_size

PATCH In review Liu Chao 2 participants 2 messages Oct 16

Subsystems (2)
lore
Share & tools
lore

Liu Chao

author
#0 lore raw

PATCH 1/1 nfs/blocklayout: reject stripe volume with zero chunk_size

bl_parse_stripe() copies v->stripe.chunk_size from the volume descriptor supplied by the server into d->chunk_size without any validation. bl_map_stripe() later divides the block offset by d->chunk_size, so a malicious or broken server that advertises a stripe volume with chunk_size == 0 triggers a divide error in the kernel and crashes the client.

Reject the volume at parse time when chunk_size is zero, before the value is stored, so the deviceid node allocation fails cleanly with -EIO instead of faulting later.

---
 fs/nfs/blocklayout/dev.c | 3 +++
 1 file changed, 3 insertions(+)
fs/nfs/blocklayout/dev.c +3 -0
index 134d7f760..6203052e0 100644
@@ -505,6 +505,9 @@ bl_parse_stripe(struct nfs_server *server, struct pnfs_block_dev *d,
 		len += d->children[i].len;
 	}
 
+	if (!v->stripe.chunk_size)
+		return -EINVAL;
+
 	d->len = len;
 	d->chunk_size = v->stripe.chunk_size;
 	d->map = bl_map_stripe;
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Liu Chao

bl_parse_stripe() copies v->stripe.chunk_size from the volume descriptor supplied by the server into d->chunk_size without any validation. bl_map_stripe() later divides the block offset by d->chunk_size, so a malicious or broken server that advertises a stripe volume with chunk_size == 0 triggers a divide error in the kernel and crashes the client.

Reject the volume at parse time when chunk_size is zero, before the value is stored, so the deviceid node allocation fails cleanly with -EIO instead of faulting later.

Looks good: