VT-d/RMRR: Avoid memory corruption in add_user_rmrr()
PATCH 1/1 VT-d/RMRR: Avoid memory corruption in add_user_rmrr()
register_one_rmrr() already frees its parameter if errors are encountered.
Introduced by c/s 431685e8de and spotted by Coverity.
Coverity-ID: 1399607
---
CC: Jan Beulich <[email protected]>
--- xen/drivers/passthrough/vtd/dmar.c | 4 ---- 1 file changed, 4 deletions(-)
xen/drivers/passthrough/vtd/dmar.c +0 -4
@@ -975,13 +975,9 @@ static int __init add_user_rmrr(void) rmrr->scope.devices_cnt = user_rmrrs[i].dev_count;if (register_one_rmrr (rmrr) ) - { printk(XENLOG_ERR VTDPREFIX"Could not register RMMR range " ERMRRU_FMT "\n" ,ERMRRU_ARG (user_rmrrs[i])); -scope_devices_free (&rmrr->scope); -xfree (rmrr); - } }return 0 ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.01.17 at 11:10, <[email protected]> wrote:
register_one_rmrr()already frees its parameter if errors are encountered.Introduced by c/s
431685e8deand spotted by Coverity.Coverity-ID: 1399607
Signed-off-by Andrew Cooper <[email protected]>
I notice, however, that register_one_rmrr() returning success doesn't always mean success, so in non-debug builds we may be left without any log message here despite there being a problem with what the user specified. Elena, Venu, can you look into this please? Perhaps the function should return a positive value in that case, so that the original caller can retain its current behavior but the newly added caller can be adjusted?
Jan
Quoted 18 lines
xen/drivers/passthrough/vtd/dmar.c +0
-4@@ -975,13 +975,9 @@ static int __init add_user_rmrr(void) rmrr->scope.devices_cnt = user_rmrrs[i].dev_count;if (register_one_rmrr (rmrr) ) - { printk(XENLOG_ERR VTDPREFIX"Could not register RMMR range " ERMRRU_FMT "\n" ,ERMRRU_ARG (user_rmrrs[i])); -scope_devices_free (&rmrr->scope); -xfree (rmrr); - } }return 0 ;Signature · 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Jan,
Sure. I will look in to it.
Venu
Quoted 43 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Monday, January 30, 2017 04:39 AM
To: Andrew Cooper; Elena Ufimtseva; Venu Busireddy
Cc: Xen-devel
Subject: Re: [PATCH] VT-d/RMRR: Avoid memory corruption inadd_user_rmrr()Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.17 at 11:10, <[email protected]> wrote:
register_one_rmrr()already frees its parameter if errors areencountered.
Quoted 5 lines
Introduced by c/s
431685e8deand spotted by Coverity.Coverity-ID: 1399607
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>I notice, however, that
register_one_rmrr()returning success doesn't always mean success, so in non-debug builds we may be left without any log message here despite there being a problem with what the user specified. Elena, Venu, can you look into this please? Perhaps the function should return a positive value in that case, so that the original caller can retain its current behavior but the newly added caller can be adjusted?Jan
Quoted 15 lines
xen/drivers/passthrough/vtd/dmar.c +0
-4@@ -975,13 +975,9 @@ static int __init add_user_rmrr(void) rmrr->scope.devices_cnt = user_rmrrs[i].dev_count;if (register_one_rmrr (rmrr) ) - { printk(XENLOG_ERR VTDPREFIX"Could not register RMMR range " ERMRRU_FMT "\n" ,ERMRRU_ARG (user_rmrrs[i])); -scope_devices_free (&rmrr->scope); -xfree (rmrr); - } }
Quoted 6 lines
Quoted 3 lines
xen/drivers/passthrough/vtd/dmar.c +0
-1return 0 ; --2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 16:22, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 30.01.17 at 22:09, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
I notice, however, that
register_one_rmrr()returning success doesn't always mean success, so in non-debug builds we may be left without any log message here despite there being a problem with what the user specified. Elena, Venu, can you look into this please? Perhaps the function should return a positive value in that case, so that the original caller can retain its current behavior but the newly added caller can be adjusted?As far as I can see,
register_one_rmrr()can only return success even when there is an error is when the user specifies a bad device (andpci_device_detect()fails), and we set "ignore" to true. Given that, the simplest way to fix this would be to return-EINVALin the "if ( ignore )" block. Do you think that would be acceptable? If you agree, I will send the patch for review.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
No, as said, the other caller of
register_one_rmrr()needs to retain its current behavior.I sent you another email explaining why maintaining the current behavior for the old caller will be difficult *without* making any changes in that path also. Waiting for your reply for that email.
I don't think I've seen that, yet.
Here is the justification for returning -EINVAL.
Whether we return a positive value or negative value here, the net result in acpi_parse_dmar() will be that VT-d will be disabled. The advantage of returning -EINVAL is that no other changes will be needed. The disadvantage is that VT-d will be disabled for this error also.
That brings up this question. Do we want to disable VT-d if the PCIe device specified via ACPI cannot be detected? We do so if the address range is incorrectly specified. If the answer is yes, then returning -EINVAL may be acceptable, and that will be the only change needed. If not, we will have to make changes to acpi_parse_dmar() also to deal with the non-zero return value from register_one_rmrr() for failure to detect the device.
That brings up one another question. In the original code, is there a historical reason why the ckeck on rmrru->base_address and rmrru->end_address warranted returning -EFAULT, thus diabling the VT-d, but failure to detect the device did not warrant returning an error?
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Also - any reason you've dropped xen-devel and Andrew?
Thought this would avoid email churn. Once we agree how you want the final solution looks like, I will send out the patch to everyone that is needed to be copied. But if the standard process is to reply to everyone in every email, I will follow that in the future. Please confirm.
Yes, discussions like this should be held in public, both for others to chime int as well as for it getting archived (e.g. for future archaeologists).
Understood. Hence I am copying my personal reply to you (with minor changes) to everyone involved.
Venu
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
(adding VT-d maintainers to Cc)
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 18:00, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 16:22, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.01.17 at 22:09, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
I notice, however, that
register_one_rmrr()returning success doesn't always mean success, so in non-debug builds we may be left without any log message here despite there being a problem with what the user specified. Elena, Venu, can you look into this please? Perhaps the function should return a positive value in that case, so that the original caller can retain its current behavior but the newly added caller can be adjusted?Quoted 6 lines
As far as I can see,
register_one_rmrr()can only return success even when there is an error is when the user specifies a bad device (andpci_device_detect()fails), and we set "ignore" to true. Given that, the simplest way to fix this would be to return-EINVALin the "if ( ignore )" block. Do you think that would be acceptable? If you agree, I will send the patch for review.Quoted 2 lines
No, as said, the other caller of
register_one_rmrr()needs to retain its current behavior.I sent you another email explaining why maintaining the current behavior for the old caller will be difficult *without* making any changes in that path also. Waiting for your reply for that email.
Quoted 8 lines
Quoted 1 line
I don't think I've seen that, yet.
Here is the justification for returning
-EINVAL.Whether we return a positive value or negative value here, the net result in
acpi_parse_dmar()will be that VT-d will be disabled. The advantage of returning-EINVALis that no other changes will be needed. The disadvantage is that VT-d will be disabled for this error also.
This disadvantage is what counts. And returning a positive value was of course meant to be accompanied by an adjustment to the pre-existing caller (to check just for negative values instead of for non-zero ones). That is clearly better (going forward) than to have this caller special case -EINVAL.
Quoted 7 lines
That brings up this question. Do we want to disable VT-d if the PCIe device specified via ACPI cannot be detected? We do so if the address range is incorrectly specified. If the answer is yes, then returning
-EINVALmay be acceptable, and that will be the only change needed. If not, we will have to make changes toacpi_parse_dmar()also to deal with the non-zero return value fromregister_one_rmrr()for failure to detect the device.
Part of the issue is that you appear to think only in terms of a single device. The logic, however, is such that initialization failure is being avoided as long as at least one of the (possibly many) listed devices can be successfully probed.
Quoted 4 lines
That brings up one another question. In the original code, is there a historical reason why the ckeck on
rmrru->base_addressandrmrru->end_addresswarranted returning-EFAULT, thus diabling the VT-d, but failure to detect the device did not warrant returning an error?
For the very reason of there possibly being multiple devices. I would guess that some firmware authors aren't pedantic enough to e.g. avoid listing devices which are present depending on some configuration option.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines · On 01.02.17 at 10:44, <[email protected]> wrote:
Quoted 1 line · On 31.01.17 at 18:00, <[email protected]> wrote:
That brings up this question. Do we want to disable VT-d if the PCIe device specified via ACPI cannot be detected? We do so if the address range is incorrectly specified. If the answer is yes, then returning
-EINVALmay be acceptable, and that will be the only change needed. If not, we will have to make changes toacpi_parse_dmar()also to deal with the non-zero return value fromregister_one_rmrr()for failure to detect the device.
Quoted 4 lines
Part of the issue is that you appear to think only in terms of a single device. The logic, however, is such that initialization failure is being avoided as long as at least one of the (possibly many) listed devices can be successfully probed.
Actually I was wrong here (one of the rare cases where replying without looking at the code another time would have been better):
An RMRR is being ignored when none of the devices can be successfully probed; normal processing results if at least one device can be confirmed to be there. The conclusion, though, is the same - we don't want such (apparently) pointless RMRRs result in VT-d initialization failure, since as long as the RMRR really is there for no reason, nothing will break by us using the IOMMU(s).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel