Skip to contentSkip to conversation

nvme-pci: fix parameter order in nvme_free_sgls() call

PATCH Applied Roger Pau Monne 5 participants 7 messages Jan 27 – Jul 17

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

PATCH 1/1 nvme-pci: fix parameter order in nvme_free_sgls() call

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Fixes f0887e2a52d4 ("nvme-pci: create common sgl unmapping helper")

---
If possible it would be good for this to go in 6.19.0-rc8, as corruption of the root device as part of a kernel update is unexpected. Sadly 6.18 already contained this issue, and no-one noticed, so its impact is limited?

---
 drivers/nvme/host/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +2 -2
index 0e4caeab739c..c8c5ed3eeac7 100644
@@ -806,8 +806,8 @@ static void nvme_unmap_data(struct request *req)
 	if (!blk_rq_dma_unmap(req, dma_dev, &iod->dma_state, iod->total_len,
 			      map)) {
 		if (nvme_pci_cmd_use_sgl(&iod->cmd))
-			nvme_free_sgls(req, iod->descriptors[0],
-				       &iod->cmd.common.dptr.sgl, attrs);
+			nvme_free_sgls(req, &iod->cmd.common.dptr.sgl,
+			               iod->descriptors[0], attrs);
 		else
 			nvme_free_prps(req, attrs);
 	}
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Roger Pau Monne

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Quoted 6 lines
Fixes f0887e2a52d4 ("nvme-pci: create common sgl unmapping helper")

---
If possible it would be good for this to go in 6.19.0-rc8, as corruption of the root device as part of a kernel update is unexpected. Sadly 6.18 already contained this issue, and no-one noticed, so its impact is limited?

This only affects non-IOMMU paths with a non-noop dma_unmap_phys. So it is a very common setup, but very severe for those. Because of that we should get into 6.19-rc and -stable ASAP.

The fix looks good:

but maybe we can reword the subject to sound less harmless, e.g.:

nvme-pci: DMA unmap the correct regions in nvme_free_sgls

?

#2 lore raw
Quoted 14 lines · Christoph Hellwig
Quoted 6 lines · Roger Pau Monne

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Quoted 6 lines
Fixes f0887e2a52d4 ("nvme-pci: create common sgl unmapping helper")

---
If possible it would be good for this to go in 6.19.0-rc8, as corruption of the root device as part of a kernel update is unexpected. Sadly 6.18 already contained this issue, and no-one noticed, so its impact is limited?

Quoted 2 lines

This only affects non-IOMMU paths with a non-noop dma_unmap_phys. So it is a very common setup, but very severe for those. Because of

Do you mean a "not very common setup"? Otherwise I can't parse the sentence.

Quoted 5 lines

that we should get into 6.19-rc and -stable ASAP.

The fix looks good:

Thanks.

Quoted 3 lines

but maybe we can reword the subject to sound less harmless, e.g.:

nvme-pci: DMA unmap the correct regions in nvme_free_sgls

Fine with me. I think I was more focused on describing the logical change rather that the actual effect of it. Can you adjust it when picking up?

Regards, Roger.

#3 lore raw
Quoted 8 lines · Roger Pau Monné
Quoted 5 lines
Quoted 2 lines

the root device as part of a kernel update is unexpected. Sadly 6.18 already contained this issue, and no-one noticed, so its impact is limited?

This only affects non-IOMMU paths with a non-noop dma_unmap_phys. So it is a very common setup, but very severe for those. Because of

Do you mean a "not very common setup"? Otherwise I can't parse the sentence.

Yes, sorry.

maintainer Applied
#4 lore raw
In reply to Roger Pau Monne
Quoted 5 lines · Roger Pau Monne

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Thanks, applied to nvme-6.19 with updated subject.

#5 lore raw
Quoted 6 lines · Keith Busch
Quoted 5 lines · Roger Pau Monne

The call to nvme_free_sgls() in nvme_unmap_data() has the sg_list and sge parameters swapped. This wasn't noticed by the compiler because both share the same type. On a Xen PV hardware domain, and possibly any other architectures that takes that path, this leads to corruption of the NVMe contents.

Quoted 5 lines · Christoph Hellwig

but maybe we can reword the subject to sound less harmless, e.g.:

nvme-pci: DMA unmap the correct regions in nvme_free_sgls

Quoted 1 line · Keith Busch

Thanks, applied to nvme-6.19 with updated subject.

Hi,

I think this wants to be included in v6.18 too, as it also has the faulty commit. And indeed, I do hit this issue when running 6.18.38.

Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
maintainer
#6 lore raw
Quoted 2 lines · Marek Marczykowski-Górecki

I think this wants to be included in v6.18 too, as it also has the faulty commit. And indeed, I do hit this issue when running 6.18.38.

Nicolai Buchwitz sent a 6.18.y backport of this, which is now queued for 6.18, thanks.

Signature · 2 lines
Thanks,
Sasha