Skip to contentSkip to conversation

nvme: lightnvm: buffer overflow in nvme_nvm_identity()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 26, 2016

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

PATCH 1/1 nvme: lightnvm: buffer overflow in nvme_nvm_identity()

nvme_nvm_id->ppaf is 4 bytes larger than nvm_id->ppaf. We're using the larger size struct for the sizeof() so we end up corrupting the first four bytes of nvm_id->groups[]. It doesn't look like we actually want to copy those last bytes anyway.

---
Static analysis, not tested. Please review this one carefully, I think this bug would show up in testing.

drivers/nvme/host/lightnvm.c +1 -1
index 5cd3725..0f0864f 100644
@@ -319,7 +319,7 @@ static int nvme_nvm_identity(struct nvm_dev *nvmdev, struct nvm_id *nvm_id)
 	nvm_id->cap = le32_to_cpu(nvme_nvm_id->cap);
 	nvm_id->dom = le32_to_cpu(nvme_nvm_id->dom);
 	memcpy(&nvm_id->ppaf, &nvme_nvm_id->ppaf,
-					sizeof(struct nvme_nvm_addr_format));
+					sizeof(struct nvm_addr_format));
 
 	ret = init_grps(nvm_id, nvme_nvm_id);
 out:
#1 lore raw
Quoted 5 lines · Dan Carpenter

nvme_nvm_id->ppaf is 4 bytes larger than nvm_id->ppaf. We're using the larger size struct for the sizeof() so we end up corrupting the first four bytes of nvm_id->groups[]. It doesn't look like we actually want to copy those last bytes anyway.

Thanks, Dan. You are right. The four bytes are overwritten afterwards and hid the issue.