Skip to contentSkip to conversation

XSA-283: Post-mortem

DISCUSSION George Dunlap 2 participants 3 messages Feb 25, 2019 – Feb 28, 2019

lore
Share & tools
lore
#0 lore raw

This is an attempt to do a 'post-mortem' on XSA-283, to find out how the error came about, and consider what changes we could make to code / processes to prevent such errors from happening in the future. The Security Team hopes to make it a habit to perform such analyses in the future.

As it happened, there XSA-283 was not a security issue; but this was due to an accident of the implementation; a change to the implementation may have become a security issue at any point.

This approach is very much a work in progress; and this is my own work done without consultation from the rest of the XenProject Security Team. Feedback / improvements welcome.

# XSA-283: The issue

Interrupt remapping maps a multi-page datastructure shared between hardware and the OS.

The datastructrue must be page-aligned, meaning that the lower 12 bits of the address of the structure would always be 0. The hardware register pointing to this (DMAR_IRTRA_REG) uses these "extra" bits to store other flags.

This address is also stored in a per-iommu-domain data structrue (struct ir_ctrl->iremap_maddr); but the extra hardware bits were *also* stored in this data structure, in a way that meant "garbage" bits were stored in the offset. It was only an accident of the way the calculation was handled that avoided this resulting in accesses past the end of the buffer.

# Archaeology

GET_IREMAP_ENTRY() was introduced by d210b9fc623 in 2009. This mainly refactored a number of open-coded versions of the same algorithm which already existed.

At that point, ir_ctrl->iremap_maddr was already being filled with the contents of DMAR_IRTA_REG, rather than actually being a machine address.

Various other changesets affecting lines or-ing in the values:
cda2f6c7613 2009-09-07 // Just slightly changes condition for calculation 1e9712f180a 2008-10-17 // Replaces magic constants with macros 12697426971 2008-04-10 // This is the culprit

Changeset 12697426971, in 2008, changes the structure from holding a long-term pointer allocated from the xenheap, and adding "extra" values into a local variable, to holding an maddr allocated from domheap, and adding "extra" values into the maddr stored in the structure.

It was posted to xen-devel in a thread starting with message-id <08DF4D958216244799FC84F3514D70F0013CDBF7@pdsmsx415.ccr.corp.intel.com> .

# Analysis

There was no public review of this patch; the commit contains no R-b or A-b. Keir's only comment on the patch before committing it was to note that it conflicted with a different patch and ask for a rebase.

Fundamentally, both the name of the new structure element ("iremap_maddr") and the name of the local variable it was replacing ("paddr") were wrong. "addr" should imply *only* an address; to contain other information it should have been named "ctrl" instead.

Furthermore, map_vtd_domain_page() silently discards non-aligned bits of addressed passed to it.

# Potential changes that could have prevented this

This could have been caught with a more careful review.

We could consider adding an entry to the style guide speciying that names based on the word 'address' must *only* be an address, and must not contain other extraneous information; and if such information needs to be stored to reflect the contents of a hardware register, then the name should be based on the word 'register' instead.

If map_vtd_domain_page() ASSERT()ed that addresses passed to it were page-aligned, then this issue would have been caught probably before the patch was sent.

A more rigorous change could be to create a special type to store addresses, with access macros to set or get the address, which would make it difficult to do this sort of casual or'ing.

# Recommendations

Look into ASSERTing that map_vtd_domain_page() is passed a page-aligned address.

Consider adding a style recommendation in line with the address / register discussion above.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw
Quoted 6 lines · George Dunlap

This is an attempt to do a 'post-mortem' on XSA-283, to find out how the error came about, and consider what changes we could make to code / processes to prevent such errors from happening in the future. The Security Team hopes to make it a habit to perform such analyses in the future.

...

Quoted 3 lines

There was no public review of this patch; the commit contains no R-b or A-b. Keir's only comment on the patch before committing it was to note that it conflicted with a different patch and ask for a rebase.

Would it be useful to count/triage commits without R-b or A-b?

Rich

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 12 lines · Rich Persaud
Quoted 6 lines · George Dunlap

This is an attempt to do a 'post-mortem' on XSA-283, to find out how the error came about, and consider what changes we could make to code / processes to prevent such errors from happening in the future. The Security Team hopes to make it a habit to perform such analyses in the future.

Quoted 7 lines

...

Quoted 3 lines

There was no public review of this patch; the commit contains no R-b or A-b. Keir's only comment on the patch before committing it was to note that it conflicted with a different patch and ask for a rebase.

Would it be useful to count/triage commits without R-b or A-b?

It would be easy to do, but I doubt it would turn up anything useful; essentially it would turn into “With-Keir” and “After-Keir”, as the discipline that nothing get checked in without an [RA]-b was introduced after Keir sort of faded from the scene. I’m not sure that Keir was in the habit of adding [RA]-b tags to commits even when they were given.

So a search of the tree for all commits without [RA]-b tags would likely just turn up everything for the first 6-8 years of Xen development; not particularly useful if looking for further potential issues (which is, I assume, the goal of your suggestion).

The reason I pointed it out was that *in general*, I don’t think exhorting reviewers to be “more vigilant” is that helpful; but it does seem to me that in this particular case, it’s likely that our modern reviewing process would have flagged this as at least ugly / unnecessary (even if the reviewer didn’t spot the potential security issue).

That said — perhaps something that would be concretely useful would be to ask maintainers to regularly look at the commits that introduced security issues, so that they can get a feel concretely for what sorts of patterns to look for.

-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel