Skip to contentSkip to conversation

xen/kexec: return error code for unknown hypercalls

PATCH In review Roger Pau Monne 2 participants 3 messages Feb 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/kexec: return error code for unknown hypercalls

Currently do_kexec_op_internal() will return 0 for unknown hypercalls. Fix this by returning -EOPNOTSUPP instead.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
Arguably the error code for unsupported kexec hypercalls was already wonky before the XSM addiiton, as it would return -EINVAL. It's however way worse after the XSM addition, as it returns 0.

---
 xen/common/kexec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/common/kexec.c +5 -2
index 84fe8c35976e..8f52c5506d4a 100644
@@ -1217,9 +1217,8 @@ static int do_kexec_op_internal(unsigned long op,
                                 XEN_GUEST_HANDLE_PARAM(void) uarg,
                                 bool compat)
 {
-    int ret = -EINVAL;
+    int ret = xsm_kexec(XSM_PRIV);
 
-    ret = xsm_kexec(XSM_PRIV);
     if ( ret )
         return ret;
 
@@ -1258,6 +1257,10 @@ static int do_kexec_op_internal(unsigned long op,
     case KEXEC_CMD_kexec_status:
         ret = kexec_status(uarg);
         break;
+
+    default:
+        ret = -EOPNOTSUPP;
+        break;
     }
 
     clear_bit(KEXEC_FLAG_IN_HYPERCALL, &kexec_flags);
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Roger Pau Monne

Currently do_kexec_op_internal() will return 0 for unknown hypercalls. Fix this by returning -EOPNOTSUPP instead.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
Quoted 13 lines

---
Arguably the error code for unsupported kexec hypercalls was already wonky before the XSM addiiton, as it would return -EINVAL. It's however way worse after the XSM addition, as it returns 0.

---
 xen/common/kexec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/common/kexec.c +0 -0
index 84fe8c35976e..8f52c5506d4a 100644

xen/common/kexec.c static int do_kexec_op_internal(unsigned long op, · line 1223

Quoted 9 lines
xen/common/kexec.c +1 -2
@@ -1217,9 +1217,8 @@ static int do_kexec_op_internal(unsigned long op,
                                 XEN_GUEST_HANDLE_PARAM(void) uarg,
                                 bool compat)
 {
-    int ret = -EINVAL;
+    int ret = xsm_kexec(XSM_PRIV);
 
-    ret = xsm_kexec(XSM_PRIV);
     if ( ret )
         return ret;

Personally, I'd just have int ret; and leave the xsm_kexec() call as it was.  That leaves the slightly more normal pattern intact.

Quoted 12 lines
xen/common/kexec.c +4 -0
@@ -1258,6 +1257,10 @@ static int do_kexec_op_internal(unsigned long op,
     case KEXEC_CMD_kexec_status:
         ret = kexec_status(uarg);
         break;
+
+    default:
+        ret = -EOPNOTSUPP;
+        break;
     }
 
     clear_bit(KEXEC_FLAG_IN_HYPERCALL, &kexec_flags);
#2 lore raw
Quoted 29 lines · Andrew Cooper
Quoted 6 lines · Roger Pau Monne

Currently do_kexec_op_internal() will return 0 for unknown hypercalls. Fix this by returning -EOPNOTSUPP instead.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
Quoted 19 lines

---
Arguably the error code for unsupported kexec hypercalls was already wonky before the XSM addiiton, as it would return -EINVAL. It's however way worse after the XSM addition, as it returns 0.

---
 xen/common/kexec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/common/kexec.c +1 -1
index 84fe8c35976e..8f52c5506d4a 100644
@@ -1217,9 +1217,8 @@ static int do_kexec_op_internal(unsigned long op,
                                 XEN_GUEST_HANDLE_PARAM(void) uarg,
                                 bool compat)
 {
-    int ret = -EINVAL;
+    int ret = xsm_kexec(XSM_PRIV);
 
Quoted 6 lines

xen/common/kexec.c static int do_kexec_op_internal(unsigned long op, · line 1223

Quoted 3 lines
xen/common/kexec.c +0 -1
-    ret = xsm_kexec(XSM_PRIV);
     if ( ret )
         return ret;

Personally, I'd just have int ret; and leave the xsm_kexec() call as it was.  That leaves the slightly more normal pattern intact.

I'm fine with that as it also drops the dead -EINVAL initialization.

Thanks, Roger.