Skip to contentSkip to conversation

s390/uv: Panic if the security of the system cannot be guaranteed.

PATCH In review Claudio Imbrenda 4 participants 5 messages Aug 1, 2024 – Aug 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/uv: Panic if the security of the system cannot be guaranteed.

The return value uv_set_shared() and uv_remove_shared() (which are wrappers around the share() function) is not always checked. The system integrity of a protected guest depends on the Share and Unshare UVCs being successful. This means that any caller that fails to check the return value will compromise the security of the protected guest.

No code path that would lead to such violation of the security guarantees is currently exercised, since all the areas that are shared never get unshared during the lifetime of the system. This might change and become an issue in the future.

The Share and Unshare UVCs can only fail in case of hypervisor misbehaviour (either a bug or malicious behaviour). In such cases there is no reasonable way forward, and the system needs to panic.

This patch replaces the return at the end of the share() function with a panic, to guarantee system integrity.

Fixes 5abb9351dfd9 ("s390/uv: introduce guest side ultravisor code")
---
 arch/s390/include/asm/uv.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/include/asm/uv.h +4 -1
index 0b5f8f3e84f1..153d93468b77 100644
@@ -441,7 +441,10 @@ static inline int share(unsigned long addr, u16 cmd)
 
 	if (!uv_call(0, (u64)&uvcb))
 		return 0;
-	return -EINVAL;
+	pr_err("%s UVC failed (rc: 0x%x, rrc: 0x%x), possible hypervisor bug.\n",
+	       uvcb.header.cmd == UVC_CMD_SET_SHARED_ACCESS ? "Share" : "Unshare",
+	       uvcb.header.rc, uvcb.header.rrc);
+	panic("System security cannot be guaranteed unless the system panics now.\n");
 }
 
 /*
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Claudio Imbrenda

The return value uv_set_shared() and uv_remove_shared() (which are wrappers around the share() function) is not always checked. The system integrity of a protected guest depends on the Share and Unshare UVCs being successful. This means that any caller that fails to check the return value will compromise the security of the protected guest.

No code path that would lead to such violation of the security guarantees is currently exercised, since all the areas that are shared never get unshared during the lifetime of the system. This might change and become an issue in the future.

For people wondering what the effects might be, this is the important paragraph to read. Fortunately we're currently not unsharing anything.

Claudio already stated that there's no way out of this but I want to reiterate on this. The hypervisor has to mess up quite badly to force a rc > 0 for the guest. Likewise the guest has to mess up memory management to achieve a rc > 0.

The only time where the cause of the rc can be fixed is when the hypervisor is malicious and tracks its changes. In all other cases we won't know why we ended up with a rc and it makes sense to stop the VM before something worse happens.

@Claudio:
The patch subject is a bit non-specific.
How about:
"s390/uv: Panic for set and remove shared access UVC errors"

With that fixed:

#2 lore raw
Quoted 26 lines · On Thu, 1 Aug 2024 15:20:30 +0200 Janosch Frank <[email protected]> wrote:
Quoted 10 lines · Claudio Imbrenda

The return value uv_set_shared() and uv_remove_shared() (which are wrappers around the share() function) is not always checked. The system integrity of a protected guest depends on the Share and Unshare UVCs being successful. This means that any caller that fails to check the return value will compromise the security of the protected guest.

No code path that would lead to such violation of the security guarantees is currently exercised, since all the areas that are shared never get unshared during the lifetime of the system. This might change and become an issue in the future.

For people wondering what the effects might be, this is the important paragraph to read. Fortunately we're currently not unsharing anything.

Claudio already stated that there's no way out of this but I want to reiterate on this. The hypervisor has to mess up quite badly to force a rc > 0 for the guest. Likewise the guest has to mess up memory management to achieve a rc > 0.

The only time where the cause of the rc can be fixed is when the hypervisor is malicious and tracks its changes. In all other cases we won't know why we ended up with a rc and it makes sense to stop the VM before something worse happens.

Quoted 4 lines

@Claudio:
The patch subject is a bit non-specific.
How about:
"s390/uv: Panic for set and remove shared access UVC errors"

feel free to fix the subject when picking (unless you really want me to send a v2)

Quoted 4 lines

With that fixed:

Reviewed-by on v1 1/1
#3 lore raw
In reply to Claudio Imbrenda
Quoted 15 lines · Claudio Imbrenda

The return value uv_set_shared() and uv_remove_shared() (which are wrappers around the share() function) is not always checked. The system integrity of a protected guest depends on the Share and Unshare UVCs being successful. This means that any caller that fails to check the return value will compromise the security of the protected guest.

No code path that would lead to such violation of the security guarantees is currently exercised, since all the areas that are shared never get unshared during the lifetime of the system. This might change and become an issue in the future.

The Share and Unshare UVCs can only fail in case of hypervisor misbehaviour (either a bug or malicious behaviour). In such cases there is no reasonable way forward, and the system needs to panic.

Quoted 5 lines

This patch replaces the return at the end of the share() function with a panic, to guarantee system integrity.

Fixes 5abb9351dfd9 ("s390/uv: introduce guest side ultravisor code")
Quoted 20 lines
---
  arch/s390/include/asm/uv.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/include/asm/uv.h +4 -1
index 0b5f8f3e84f1..153d93468b77 100644
@@ -441,7 +441,10 @@ static inline int share(unsigned long addr, u16 cmd)
 
  	if (!uv_call(0, (u64)&uvcb))
  		return 0;
-	return -EINVAL;
+	pr_err("%s UVC failed (rc: 0x%x, rrc: 0x%x), possible hypervisor bug.\n",
+	       uvcb.header.cmd == UVC_CMD_SET_SHARED_ACCESS ? "Share" : "Unshare",
+	       uvcb.header.rc, uvcb.header.rrc);
+	panic("System security cannot be guaranteed unless the system panics now.\n");
  }
 
  /*
Reviewed-by on v1 1/1
#4 lore raw
In reply to Claudio Imbrenda

Am 01.08.24 um 13:25 schrieb Claudio Imbrenda:

Quoted 15 lines

The return value uv_set_shared() and uv_remove_shared() (which are wrappers around the share() function) is not always checked. The system integrity of a protected guest depends on the Share and Unshare UVCs being successful. This means that any caller that fails to check the return value will compromise the security of the protected guest.

No code path that would lead to such violation of the security guarantees is currently exercised, since all the areas that are shared never get unshared during the lifetime of the system. This might change and become an issue in the future.

The Share and Unshare UVCs can only fail in case of hypervisor misbehaviour (either a bug or malicious behaviour). In such cases there is no reasonable way forward, and the system needs to panic.

Quoted 5 lines

This patch replaces the return at the end of the share() function with a panic, to guarantee system integrity.

Fixes 5abb9351dfd9 ("s390/uv: introduce guest side ultravisor code")
Quoted 20 lines
---
  arch/s390/include/asm/uv.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/include/asm/uv.h +4 -1
index 0b5f8f3e84f1..153d93468b77 100644
@@ -441,7 +441,10 @@ static inline int share(unsigned long addr, u16 cmd)
 
  	if (!uv_call(0, (u64)&uvcb))
  		return 0;
-	return -EINVAL;
+	pr_err("%s UVC failed (rc: 0x%x, rrc: 0x%x), possible hypervisor bug.\n",
+	       uvcb.header.cmd == UVC_CMD_SET_SHARED_ACCESS ? "Share" : "Unshare",
+	       uvcb.header.rc, uvcb.header.rrc);
+	panic("System security cannot be guaranteed unless the system panics now.\n");
  }
 
  /*