Subject: sysctl/XSM: drop .page_offline() hook
From: Jan Beulich <[email-masked]>

Integrate the checking with xsm_sysctl(), now that it has the full op
struct passed. As a positive side effect, permissions are then checked at
the same early point with and without Flask.

This is part of CVE-2026-62426 / XSA-499.

Signed-off-by: Jan Beulich <[email-masked]>
Reviewed-by: Andrew Cooper <[email-masked]>
Acked-By: Daniel P. Smith <[email-masked]>

--- a/xen/common/sysctl.c
+++ b/xen/common/sysctl.c
@@ -187,10 +187,6 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         if ( op->u.page_offline.end < op->u.page_offline.start )
             break;
 
-        ret = xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd);
-        if ( ret )
-            break;
-
         ptr = status = xmalloc_array(uint32_t,
                                      (op->u.page_offline.end -
                                       op->u.page_offline.start + 1));
--- a/xen/include/xsm/dummy.h
+++ b/xen/include/xsm/dummy.h
@@ -429,12 +429,6 @@ static XSM_INLINE int cf_check xsm_resou
     return xsm_default_action(action, current->domain, NULL);
 }
 
-static XSM_INLINE int cf_check xsm_page_offline(XSM_DEFAULT_ARG uint32_t cmd)
-{
-    XSM_ASSERT_ACTION(XSM_HOOK);
-    return xsm_default_action(action, current->domain, NULL);
-}
-
 static XSM_INLINE int cf_check xsm_hypfs_op(XSM_DEFAULT_VOID)
 {
     XSM_ASSERT_ACTION(XSM_PRIV);
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -128,7 +128,6 @@ struct xsm_ops {
     int (*resource_setup_gsi)(int gsi);
     int (*resource_setup_misc)(void);
 
-    int (*page_offline)(uint32_t cmd);
     int (*hypfs_op)(void);
 
     long (*do_xsm_op)(XEN_GUEST_HANDLE_PARAM(void) op);
@@ -521,11 +520,6 @@ static inline int xsm_resource_setup_mis
     return alternative_call(xsm_ops.resource_setup_misc);
 }
 
-static inline int xsm_page_offline(xsm_default_t def, uint32_t cmd)
-{
-    return alternative_call(xsm_ops.page_offline, cmd);
-}
-
 static inline int xsm_hypfs_op(xsm_default_t def)
 {
     return alternative_call(xsm_ops.hypfs_op);
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -83,7 +83,6 @@ static const struct xsm_ops __initconst_
     .resource_setup_gsi            = xsm_resource_setup_gsi,
     .resource_setup_misc           = xsm_resource_setup_misc,
 
-    .page_offline                  = xsm_page_offline,
     .hypfs_op                      = xsm_hypfs_op,
     .hvm_param                     = xsm_hvm_param,
     .hvm_param_altp2mhvm           = xsm_hvm_param_altp2mhvm,
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -58,6 +58,7 @@ static int flask_deassign_dtdevice(struc
 
 static int flask_resource_plug_core(void);
 static int flask_resource_unplug_core(void);
+static int flask_resource_use_core(void);
 
 static uint32_t domain_sid(const struct domain *dom)
 {
@@ -908,10 +909,6 @@ static int cf_check flask_sysctl(const s
 {
     switch ( op->cmd )
     {
-    /* These have individual XSM hooks */
-    case XEN_SYSCTL_page_offline_op:
-        return 0;
-
     case XEN_SYSCTL_readconsole:
         return domain_has_xen(current->domain,
                               XEN__READCONSOLE |
@@ -942,6 +939,23 @@ static int cf_check flask_sysctl(const s
     case XEN_SYSCTL_pm_op:
         return domain_has_xen(current->domain, XEN__PM_OP);
 
+    case XEN_SYSCTL_page_offline_op:
+        switch ( op->u.page_offline.cmd )
+        {
+        case sysctl_page_offline:
+            return flask_resource_unplug_core();
+
+        case sysctl_page_online:
+            return flask_resource_plug_core();
+
+        case sysctl_query_page_offline:
+            return flask_resource_use_core();
+
+        default:
+            return avc_unknown_permission("page_offline",
+                                          op->u.page_offline.cmd);
+        }
+
     case XEN_SYSCTL_lockprof_op:
         return domain_has_xen(current->domain, XEN__LOCKPROF);
 
@@ -1333,21 +1347,6 @@ static int cf_check flask_resource_setup
     return avc_current_has_perm(SECINITSID_XEN, SECCLASS_RESOURCE, RESOURCE__SETUP, NULL);
 }
 
-static inline int cf_check flask_page_offline(uint32_t cmd)
-{
-    switch ( cmd )
-    {
-    case sysctl_page_offline:
-        return flask_resource_unplug_core();
-    case sysctl_page_online:
-        return flask_resource_plug_core();
-    case sysctl_query_page_offline:
-        return flask_resource_use_core();
-    default:
-        return avc_unknown_permission("page_offline", cmd);
-    }
-}
-
 static inline int cf_check flask_hypfs_op(void)
 {
     return domain_has_xen(current->domain, XEN__HYPFS_OP);
@@ -1992,7 +1991,6 @@ static const struct xsm_ops __initconst_
     .resource_setup_gsi = flask_resource_setup_gsi,
     .resource_setup_misc = flask_resource_setup_misc,
 
-    .page_offline = flask_page_offline,
     .hypfs_op = flask_hypfs_op,
     .hvm_param = flask_hvm_param,
     .hvm_param_altp2mhvm = flask_hvm_param_altp2mhvm,