Skip to contentSkip to conversation

some more s390x fixes

GIT PULL Applied Cornelia Huck 3 participants 7 messages Jul 27, 2020 – Jul 28, 2020

lore
Share & tools
lore
#1 lore raw

[PULL 1/2] s390x/protvirt: allow to IPL secure guests with -no-reboot

In reply to Cornelia Huck

From: Christian Borntraeger <[email protected]>

Right now, -no-reboot prevents secure guests from running. This is correct from an implementation point of view, as we have modeled the transition from non-secure to secure as a program directed IPL. From a user perspective, this is not the behavior of least surprise.

We should implement the IPL into protected mode similar to the functions that we use for kdump/kexec. In other words, we do not stop here when -no-reboot is specified on the command line. Like function 0 or function 1, function 10 is not a classic reboot. For example, it can only be called once. Before calling it a second time, a real reboot/reset must happen in-between. So function code 10 is more or less a state transition reset, but not a "standard" reset or reboot.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")

Message-Id: <[email protected]>

[CH: tweaked description]
---
 hw/s390x/ipl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +2 -1
index d46b1f094f75..3d2652d75abd 100644
@@ -630,7 +630,8 @@ void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
         }
     }
     if (reset_type == S390_RESET_MODIFIED_CLEAR ||
-        reset_type == S390_RESET_LOAD_NORMAL) {
+        reset_type == S390_RESET_LOAD_NORMAL ||
+        reset_type == S390_RESET_PV) {
         /* ignore -no-reboot, send no event  */
         qemu_system_reset_request(SHUTDOWN_CAUSE_SUBSYSTEM_RESET);
     } else {
Signature · 1 line
2.25.4
#2 lore raw

[PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter

In reply to Cornelia Huck

From: Halil Pasic <[email protected]>

The function machine_get_loadparm() is supposed to produce a C-string, that is a NUL-terminated one, but it does not. ElectricFence can detect this problem if the loadparm machine property is used.

Let us make the returned string a NUL-terminated one.

Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")

Message-Id: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +5 -1
index 8cc2f25d8a6a..403d30e13bca 100644
@@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
 static char *machine_get_loadparm(Object *obj, Error **errp)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+    char *loadparm_str;
 
-    return g_memdup(ms->loadparm, sizeof(ms->loadparm));
+    /* make a NUL-terminated string */
+    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;
 }
 
 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
Signature · 1 line
2.25.4
#0 lore raw

The following changes since commit 8ffa52c20d5693d454f65f2024a1494edfea65d4:

Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-07-23 13:38:21 +0100)

are available in the Git repository at:

https://github.com/cohuck/qemu tags/s390x-20200727

for you to fetch changes up to d6645483285feaa0aa26fe2b0c3bac6989250d2f:

s390x/s390-virtio-ccw: fix loadparm property getter (2020-07-24 08:49:53 +0200)

----------------------------------------------------------------
fixes for protected virtualization and loadparm handling

----------------------------------------------------------------

Christian Borntraeger (1):
s390x/protvirt: allow to IPL secure guests with -no-reboot

Halil Pasic (1):
s390x/s390-virtio-ccw: fix loadparm property getter

 hw/s390x/ipl.c             | 3 ++-
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.4
#6 lore raw
Quoted 9 lines · Cornelia Huck

The following changes since commit 8ffa52c20d5693d454f65f2024a1494edfea65d4:

Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-07-23 13:38:21 +0100)

are available in the Git repository at:

https://github.com/cohuck/qemu tags/s390x-20200727

Quoted 8 lines

for you to fetch changes up to d6645483285feaa0aa26fe2b0c3bac6989250d2f:

s390x/s390-virtio-ccw: fix loadparm property getter (2020-07-24 08:49:53 +0200)

----------------------------------------------------------------
fixes for protected virtualization and loadparm handling

----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM

#3 lore raw

Re: [PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter

In reply to Cornelia Huck
Quoted 23 lines · Cornelia Huck

From: Halil Pasic <[email protected]>

The function machine_get_loadparm() is supposed to produce a C-string, that is a NUL-terminated one, but it does not. ElectricFence can detect this problem if the loadparm machine property is used.

Let us make the returned string a NUL-terminated one.

Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")

Message-Id: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index 8cc2f25d8a6a..403d30e13bca 100644

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 709

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +5 -1
@@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
 static char *machine_get_loadparm(Object *obj, Error **errp)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+    char *loadparm_str;
 
-    return g_memdup(ms->loadparm, sizeof(ms->loadparm));
+    /* make a NUL-terminated string */
+    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;

Hi. Coverity points out (CID 1431058) that this code now reads off the end of the ms->loadparm buffer, because g_memdup() is going to read and copy 9 bytes (size + 1) and the array itself is only 8 bytes.

I don't think you can use g_memdup() here -- you need to allocate the memory with g_malloc() and then fill it with memcpy(), something like:

    loadparm_str = g_malloc(sizeof(ms->loadparm) + 1);
    memcpy(loadparm_str, ms->loadparm, sizeof(ms->loadparm));
    loadparm_str[sizeof(ms->loadparm)] = 0;

thanks
-- PMM

#4 lore raw

Re: [PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter

Quoted 40 lines · On Tue, 28 Jul 2020 14:52:36 +0100 Peter Maydell <[email protected]>…
Quoted 23 lines · Cornelia Huck

From: Halil Pasic <[email protected]>

The function machine_get_loadparm() is supposed to produce a C-string, that is a NUL-terminated one, but it does not. ElectricFence can detect this problem if the loadparm machine property is used.

Let us make the returned string a NUL-terminated one.

Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")

Message-Id: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index 8cc2f25d8a6a..403d30e13bca 100644

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 709

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +5 -1
@@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
 static char *machine_get_loadparm(Object *obj, Error **errp)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+    char *loadparm_str;
 
-    return g_memdup(ms->loadparm, sizeof(ms->loadparm));
+    /* make a NUL-terminated string */
+    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;  

Hi. Coverity points out (CID 1431058) that this code now reads off the end of the ms->loadparm buffer, because g_memdup() is going to read and copy 9 bytes (size + 1) and the array itself is only 8 bytes.

Quoted 7 lines

I don't think you can use g_memdup() here -- you need to allocate the memory with g_malloc() and then fill it with memcpy(), something like:

    loadparm_str = g_malloc(sizeof(ms->loadparm) + 1);
    memcpy(loadparm_str, ms->loadparm, sizeof(ms->loadparm));
    loadparm_str[sizeof(ms->loadparm)] = 0;

Sigh.

Halil, do you have time to cook up a patch?

#5 lore raw

Re: [PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter

Quoted 47 lines · On Tue, 28 Jul 2020 17:14:38 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 44 lines · On Tue, 28 Jul 2020 14:52:36 +0100 Peter Maydell <[email protected]>…
Quoted 23 lines · Cornelia Huck

From: Halil Pasic <[email protected]>

The function machine_get_loadparm() is supposed to produce a C-string, that is a NUL-terminated one, but it does not. ElectricFence can detect this problem if the loadparm machine property is used.

Let us make the returned string a NUL-terminated one.

Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")

Message-Id: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index 8cc2f25d8a6a..403d30e13bca 100644

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 709

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +5 -1
@@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
 static char *machine_get_loadparm(Object *obj, Error **errp)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+    char *loadparm_str;
 
-    return g_memdup(ms->loadparm, sizeof(ms->loadparm));
+    /* make a NUL-terminated string */
+    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;  

Hi. Coverity points out (CID 1431058) that this code now reads off the end of the ms->loadparm buffer, because g_memdup() is going to read and copy 9 bytes (size + 1) and the array itself is only 8 bytes.

I don't think you can use g_memdup() here -- you need to allocate the memory with g_malloc() and then fill it with memcpy(), something like:

Quoted 9 lines
Quoted 3 lines
    loadparm_str = g_malloc(sizeof(ms->loadparm) + 1);
    memcpy(loadparm_str, ms->loadparm, sizeof(ms->loadparm));
    loadparm_str[sizeof(ms->loadparm)] = 0;

Sigh.

Halil, do you have time to cook up a patch?

Will do!

Halil