Skip to contentSkip to conversation

libxc/x86: fix a couple of bugs

PATCH Superseded Roger Pau Monne 2 participants 9 messages Mar 21, 2018 – Mar 28, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover libxc/x86: fix a couple of bugs

Hello,

Following two patches fix two bugs related to the mapping and handling of the hvm_start_info.

Thanks, Roger.

Roger Pau Monne (2):
libxc/x86: fix mapping of the start_info area libxc/x86: do not unconditionally set the module cmdline address

 tools/libxc/xc_dom_x86.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 7 lines
2.16.2


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

PATCH 1/2 libxc/x86: fix mapping of the start_info area

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/xc_dom_x86.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +5 -1
index 0b65dab4bc..e29c666b89 100644
@@ -1671,7 +1671,11 @@ static int bootlate_hvm(struct xc_dom_image *dom)
     unsigned int i;
 
     start_info_size = sizeof(*start_info) + dom->cmdline_size;
-    start_info_size += sizeof(struct hvm_modlist_entry) * dom->num_modules;
+    start_info_size += sizeof(struct hvm_modlist_entry) *
+                       HVMLOADER_MODULE_MAX_COUNT;
+    start_info_size += HVMLOADER_MODULE_CMDLINE_SIZE *
+                       HVMLOADER_MODULE_MAX_COUNT;
+
 
     if ( start_info_size >
          dom->start_info_seg.pages << XC_DOM_PAGE_SHIFT(dom) )
Signature · 7 lines
2.16.2


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

Re: [PATCH for-4.11 1/2] libxc/x86: fix mapping of the start_info area

Quoted 7 lines · Roger Pau Monne

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

I get the cmdline bit.

What does it need to be HVMLOADER_MODULE_MAX_COUNT? Isn't better to just map what we need here?

Wei.

Quoted 29 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/xc_dom_x86.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +5 -1
index 0b65dab4bc..e29c666b89 100644
@@ -1671,7 +1671,11 @@ static int bootlate_hvm(struct xc_dom_image *dom)
     unsigned int i;
 
     start_info_size = sizeof(*start_info) + dom->cmdline_size;
-    start_info_size += sizeof(struct hvm_modlist_entry) * dom->num_modules;
+    start_info_size += sizeof(struct hvm_modlist_entry) *
+                       HVMLOADER_MODULE_MAX_COUNT;
+    start_info_size += HVMLOADER_MODULE_CMDLINE_SIZE *
+                       HVMLOADER_MODULE_MAX_COUNT;
+
 
     if ( start_info_size >
          dom->start_info_seg.pages << XC_DOM_PAGE_SHIFT(dom) )
Signature · 1 line
2.16.2

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

#3 lore raw

Re: [PATCH for-4.11 1/2] libxc/x86: fix mapping of the start_info area

Quoted 5 lines · Wei Liu
Quoted 4 lines · Roger Pau Monne

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

Quoted 8 lines
Quoted 3 lines

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

I get the cmdline bit.

What does it need to be HVMLOADER_MODULE_MAX_COUNT? Isn't better to just map what we need here?

Because the position of the modules command line is:

modlist_paddr + sizeof(struct hvm_modlist_entry) * HVMLOADER_MODULE_MAX_COUNT;

(This is from add_module_to_list).

So if dom->num_modules < HVMLOADER_MODULE_MAX_COUNT the mapped region is smaller that what we might end up using.

I'm not sure why HVMLOADER_MODULE_MAX_COUNT is used when allocating memory (in alloc_magic_pages_hvm) instead of the actual number of modules (dom->num_modules), but the proposed change seems to be the easier way to fix the mapping issue.

I've CC'ed the original authors of this code in another thread, but got no response.

Thanks, Roger.

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

#4 lore raw

Re: [PATCH for-4.11 1/2] libxc/x86: fix mapping of the start_info area

Ping?

Quoted 32 lines · Roger Pau Monné
Quoted 5 lines · Wei Liu
Quoted 4 lines · Roger Pau Monne

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

Quoted 8 lines
Quoted 3 lines

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

I get the cmdline bit.

What does it need to be HVMLOADER_MODULE_MAX_COUNT? Isn't better to just map what we need here?

Because the position of the modules command line is:

modlist_paddr + sizeof(struct hvm_modlist_entry) * HVMLOADER_MODULE_MAX_COUNT;

(This is from add_module_to_list).

So if dom->num_modules < HVMLOADER_MODULE_MAX_COUNT the mapped region is smaller that what we might end up using.

I'm not sure why HVMLOADER_MODULE_MAX_COUNT is used when allocating memory (in alloc_magic_pages_hvm) instead of the actual number of modules (dom->num_modules), but the proposed change seems to be the easier way to fix the mapping issue.

I've CC'ed the original authors of this code in another thread, but got no response.

Quoted 6 lines

Thanks, Roger.

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

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

#5 lore raw

Re: [PATCH for-4.11 1/2] libxc/x86: fix mapping of the start_info area

In reply to Roger Pau Monné
Quoted 21 lines · Roger Pau Monné
Quoted 5 lines · Wei Liu
Quoted 4 lines · Roger Pau Monne

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

Quoted 8 lines
Quoted 3 lines

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

I get the cmdline bit.

What does it need to be HVMLOADER_MODULE_MAX_COUNT? Isn't better to just map what we need here?

Because the position of the modules command line is:

modlist_paddr + sizeof(struct hvm_modlist_entry) * HVMLOADER_MODULE_MAX_COUNT;

(This is from add_module_to_list).

Quoted 8 lines

So if dom->num_modules < HVMLOADER_MODULE_MAX_COUNT the mapped region is smaller that what we might end up using.

I'm not sure why HVMLOADER_MODULE_MAX_COUNT is used when allocating memory (in alloc_magic_pages_hvm) instead of the actual number of modules (dom->num_modules), but the proposed change seems to be the easier way to fix the mapping issue.

This patch is correct, in the sense that it replicates the logic from alloc_magic_pages_hvm to bootlate_hvm. However, I don't think bootlate_hvm is in the business of calculating the size once more. This is bound to fail in the future.

Instead, you can stash the size to dom once the calculation in alloc_magic_pages_hvm is done, and then use it in bootlate_hvm. This is the least fragile way I can think of.

Does this make sense?

Wei.

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

#6 lore raw

Re: [PATCH for-4.11 1/2] libxc/x86: fix mapping of the start_info area

Quoted 31 lines · Wei Liu
Quoted 21 lines · Roger Pau Monné
Quoted 5 lines · Wei Liu
Quoted 4 lines · Roger Pau Monne

The start_info size calculated in bootlate_hvm is wrong. It should use HVMLOADER_MODULE_MAX_COUNT instead of dom->num_modules and it doesn't take into account the size of the modules command line.

Quoted 8 lines
Quoted 3 lines

This is not a problem so far because the actually used amount of memory doesn't cross a page boundary, and so no page-fault is triggered.

I get the cmdline bit.

What does it need to be HVMLOADER_MODULE_MAX_COUNT? Isn't better to just map what we need here?

Because the position of the modules command line is:

modlist_paddr + sizeof(struct hvm_modlist_entry) * HVMLOADER_MODULE_MAX_COUNT;

(This is from add_module_to_list).

Quoted 8 lines

So if dom->num_modules < HVMLOADER_MODULE_MAX_COUNT the mapped region is smaller that what we might end up using.

I'm not sure why HVMLOADER_MODULE_MAX_COUNT is used when allocating memory (in alloc_magic_pages_hvm) instead of the actual number of modules (dom->num_modules), but the proposed change seems to be the easier way to fix the mapping issue.

Quoted 4 lines

This patch is correct, in the sense that it replicates the logic from alloc_magic_pages_hvm to bootlate_hvm. However, I don't think bootlate_hvm is in the business of calculating the size once more. This is bound to fail in the future.

Agree, the calculation now is fairly simple, yet we have already failed to replicate it properly.

Quoted 3 lines

Instead, you can stash the size to dom once the calculation in alloc_magic_pages_hvm is done, and then use it in bootlate_hvm. This is the least fragile way I can think of.

Ack, I think this is correct, and more robust future-wise.

Thanks, Roger.

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

#7 lore raw

PATCH 2/2 libxc/x86: do not unconditionally set the module cmdline address

In reply to Roger Pau Monne

This will lead to writing a wrong module command line physical memory address if no command line is actually provided.

This hasn't caused problems so far because hvmloader is the only consumer of the modules command line, and it's unconditionally set in that case.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/xc_dom_x86.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/libxc/xc_dom_x86.c +2 -3
index e29c666b89..27dad89906 100644
@@ -1653,11 +1653,10 @@ static void add_module_to_list(struct xc_dom_image *dom,
                < HVMLOADER_MODULE_CMDLINE_SIZE);
         strncpy(modules_cmdline_start + HVMLOADER_MODULE_CMDLINE_SIZE * index,
                 cmdline, HVMLOADER_MODULE_CMDLINE_SIZE);
+        modlist[index].cmdline_paddr = modules_cmdline_paddr +
+                                       HVMLOADER_MODULE_CMDLINE_SIZE * index;
     }
 
-    modlist[index].cmdline_paddr =
-        modules_cmdline_paddr + HVMLOADER_MODULE_CMDLINE_SIZE * index;
-
     start_info->nr_modules++;
 }
 
Signature · 7 lines
2.16.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/2
#8 lore raw

Re: [PATCH for-4.11 2/2] libxc/x86: do not unconditionally set the module cmdline address

Quoted 8 lines · Roger Pau Monne

This will lead to writing a wrong module command line physical memory address if no command line is actually provided.

This hasn't caused problems so far because hvmloader is the only consumer of the modules command line, and it's unconditionally set in that case.

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