Skip to contentSkip to conversation

passthrough/amd: avoid reading an uninitialized variable.

PATCH In review Tim Deegan 5 participants 6 messages Apr 16, 2015 – Apr 23, 2015

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

PATCH 1/1 passthrough/amd: avoid reading an uninitialized variable.

update_intremap_entry_from_msi() doesn't write to its data pointer on some error paths, so we copying that variable into the msg would count as undefined behaviour.

Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>

---
I'm not sure whether we ought to be writing some default value instead. Happy to respin if someone knowledgeable can advise.

---
 xen/drivers/passthrough/amd/iommu_intr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/drivers/passthrough/amd/iommu_intr.c +3 -2
index c1b76fb..c097d52 100644
@@ -529,10 +529,11 @@ int amd_iommu_msi_msg_update_ire(
     } while ( PCI_SLOT(bdf) == PCI_SLOT(pdev->devfn) );
 
     if ( !rc )
+    {
         for ( i = 1; i < nr; ++i )
             msi_desc[i].remap_index = msi_desc->remap_index + i;
-
-    msg->data = data;
+        msg->data = data;
+    }
     return rc;
 }
 
Signature · 1 line
2.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Tim Deegan

update_intremap_entry_from_msi() doesn't write to its data pointer on some error paths, so we copying that variable into the msg would count as undefined behaviour.

Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>

This looks curiously familiar.

http://lists.xen.org/archives/html/xen-devel/2015-03/msg03679.html

I was meaning to get around to submitting it as a formal patch, but you have definitely beaten me to it :)

#2 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.04.15 at 19:19, <[email protected]> wrote:
Quoted 7 lines · Tim Deegan

update_intremap_entry_from_msi() doesn't write to its data pointer on some error paths, so we copying that variable into the msg would count as undefined behaviour.

Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>
Quoted 6 lines

This looks curiously familiar.

http://lists.xen.org/archives/html/xen-devel/2015-03/msg03679.html

I was meaning to get around to submitting it as a formal patch, but you have definitely beaten me to it :)

But sadly it didn't help with the issue Sander reported (and I also didn't expect it to, as errors here should cause the caller to not use msg at all, and the regressing patch didn't alter anything that could have caused errors to surface where none where seen before). Still the patch is a good one as correcting a language spec violation.

Jan

#3 lore raw
In reply to Tim Deegan
Quoted 7 lines · Tim Deegan

update_intremap_entry_from_msi() doesn't write to its data pointer on some error paths, so we copying that variable into the msg would count as undefined behaviour.

Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>

CC-ing Sander who I believe saw this problem.
http://lists.xen.org/archives/html/xen-devel/2015-03/msg03679.html

Quoted 33 lines

---
I'm not sure whether we ought to be writing some default value instead. Happy to respin if someone knowledgeable can advise.

---
 xen/drivers/passthrough/amd/iommu_intr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/drivers/passthrough/amd/iommu_intr.c +3 -2
index c1b76fb..c097d52 100644
@@ -529,10 +529,11 @@ int amd_iommu_msi_msg_update_ire(
     } while ( PCI_SLOT(bdf) == PCI_SLOT(pdev->devfn) );
 
     if ( !rc )
+    {
         for ( i = 1; i < nr; ++i )
             msi_desc[i].remap_index = msi_desc->remap_index + i;
-
-    msg->data = data;
+        msg->data = data;
+    }
     return rc;
 }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw
Quoted 9 lines · Tim Deegan
Quoted 7 lines · Tim Deegan

update_intremap_entry_from_msi() doesn't write to its data pointer on some error paths, so we copying that variable into the msg would count as undefined behaviour.

Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>
Quoted 5 lines

AMD maintainers: can you ack/nack this please?

Cheers,

Tim.

Thanks,

Suravee