|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging-4.16] xen/gnttab: fix gnttab_acquire_resource()
commit b9560762392c01b3ee84148c07be8017cb42dbc9
Author: Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Oct 11 15:01:22 2022 +0200
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Oct 11 15:01:22 2022 +0200
xen/gnttab: fix gnttab_acquire_resource()
Commit 9dc46386d89d ("gnttab: work around "may be used uninitialized"
warning") was wrong, as vaddrs can legitimately be NULL in case
XENMEM_resource_grant_table_id_status was specified for a grant table
v1. This would result in crashes in debug builds due to
ASSERT_UNREACHABLE() triggering.
Check vaddrs only to be NULL in the rc == 0 case.
Expand the tests in tools/tests/resource to tickle this path, and verify
that
using XENMEM_resource_grant_table_id_status on a v1 grant table fails.
Fixes: 9dc46386d89d ("gnttab: work around "may be used uninitialized"
warning")
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx> # xen
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
master commit: 52daa6a8483e4fbd6757c9d1b791e23931791608
master date: 2022-09-09 16:28:38 +0100
---
tools/tests/resource/test-resource.c | 15 +++++++++++++++
xen/common/grant_table.c | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/tools/tests/resource/test-resource.c
b/tools/tests/resource/test-resource.c
index 0557f8a1b5..37dfff4dcd 100644
--- a/tools/tests/resource/test-resource.c
+++ b/tools/tests/resource/test-resource.c
@@ -106,6 +106,21 @@ static void test_gnttab(uint32_t domid, unsigned int
nr_frames,
if ( rc )
return fail(" Fail: Unmap grant table %d - %s\n",
errno, strerror(errno));
+
+ /*
+ * Verify that an attempt to map the status frames fails, as the domain is
+ * in gnttab v1 mode.
+ */
+ res = xenforeignmemory_map_resource(
+ fh, domid, XENMEM_resource_grant_table,
+ XENMEM_resource_grant_table_id_status, 0, 1,
+ (void **)&gnttab, PROT_READ | PROT_WRITE, 0);
+
+ if ( res )
+ {
+ fail(" Fail: Managed to map gnttab v2 status frames in v1 mode\n");
+ xenforeignmemory_unmap_resource(fh, res);
+ }
}
static void test_domain_configurations(void)
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index d8ca645b96..76272b3c8a 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -4142,7 +4142,7 @@ int gnttab_acquire_resource(
* on non-error paths, and hence it needs setting to NULL at the top of the
* function. Leave some runtime safety.
*/
- if ( !vaddrs )
+ if ( !rc && !vaddrs )
{
ASSERT_UNREACHABLE();
rc = -ENODATA;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.16
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |