Skip to contentSkip to conversation

xen/sysctl: fix XEN_SYSCTL_getdomaininfolist handling with XSM

PATCH In review Juergen Gross 4 participants 10 messages Apr 30, 2023 – May 2, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/sysctl: fix XEN_SYSCTL_getdomaininfolist handling with XSM

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
---
 xen/common/sysctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
             if ( num_domains == op->u.getdomaininfolist.max_domains )
                 break;
 
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                 continue;
 
             getdomaininfo(d, &info);
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

Should have finished reading the list first, before sending the same patch again ...

Jan

#2 lore raw
In reply to Juergen Gross
Quoted 19 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
---
  xen/common/sysctl.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +0 -0
index 02505ab044..0cbfe8bd44 100644

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 95

Quoted 9 lines
xen/common/sysctl.c +1 -2
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
              if ( num_domains == op->u.getdomaininfolist.max_domains )
                  break;
 
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                  continue;
 
              getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

V/r,
Daniel P. Smith

#3 lore raw
Quoted 26 lines · Daniel P. Smith
Quoted 25 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
---
  xen/common/sysctl.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
              if ( num_domains == op->u.getdomaininfolist.max_domains )
                  break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                  continue;
Quoted 8 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 95

Quoted 1 line
xen/common/sysctl.c +0 -0
              getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

By dropping that intermediate variable it prevents returning an error as the result of the hypercall if xsm_getdomaininfo() for the last domain fails.

Note that xsm_getdomaininfo() failing for other domains not the last one don't cause the return value of the hypercall to be an error code, because the variable containing the error gets overwritten by further loops.

Regards, Roger.

#4 lore raw
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Daniel P. Smith
Quoted 25 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")
---
   xen/common/sysctl.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
Quoted 8 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 95

Quoted 1 line
xen/common/sysctl.c +0 -0
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Quoted 3 lines

By dropping that intermediate variable it prevents returning an error as the result of the hypercall if xsm_getdomaininfo() for the last domain fails.

Ah, understood. I missed ret is state tracking.

Quoted 4 lines

Note that xsm_getdomaininfo() failing for other domains not the last one don't cause the return value of the hypercall to be an error code, because the variable containing the error gets overwritten by further loops.

In the end, this is just addressing an issue that has not been seen by anyone and happened upon while debugging another issue.

V/r,
DPS

#5 lore raw
In reply to Daniel P. Smith
Quoted 15 lines · Daniel P. Smith
Quoted 14 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
  xen/common/sysctl.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 15 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 93

Quoted 12 lines
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

You are missing the fact that ret getting set by a failing xsm_getdomaininfo() call might result in the ret value being propagated to the sysctl caller. And this should not happen. So the fix is to NOT modify ret here.

Quoted 1 line

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

Your statement sounds as if xsm_getdomaininfo() would always return the same value for a given caller domain. Isn't that return value also depending on the domain specified via the second parameter? In case it isn't, why does that parameter even exist?

Juergen

#6 lore raw
Quoted 33 lines · Juergen Gross
Quoted 15 lines · Daniel P. Smith
Quoted 14 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
  xen/common/sysctl.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 16 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) · line 94

Quoted 13 lines
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) 
 u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Quoted 3 lines

You are missing the fact that ret getting set by a failing xsm_getdomaininfo() call might result in the ret value being propagated to the sysctl caller. And this should not happen. So the fix is to NOT modify ret here.

You are correct, my apologies for that.

Quoted 6 lines
Quoted 1 line

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

Your statement sounds as if xsm_getdomaininfo() would always return the same value for a given caller domain. Isn't that return value also depending on the domain specified via the second parameter? In case it isn't, why does that parameter even exist?

It would if the default action was something other than XSM_HOOK. Look at line 82 of include/xsm/dummy.h. XSM_HOOK will always return 0 regardless of the src or dest domains. The function xsm_defualt_action() is the policy for both default/dummy and SILO with the exception for evntchn, grants, and argo checks for SILO.

v/r,
DPS

#7 lore raw
Quoted 40 lines · Daniel P. Smith
Quoted 33 lines · Juergen Gross
Quoted 15 lines · Daniel P. Smith
Quoted 14 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
  xen/common/sysctl.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 16 lines

xen/common/sysctl.c long · line 94

Quoted 13 lines
xen/common/sysctl.c +1 -2
index 02505ab044..0cbfe8bd44 100644
@@ -89,8 +89,7 @@ long 
 do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Quoted 3 lines

You are missing the fact that ret getting set by a failing xsm_getdomaininfo() call might result in the ret value being propagated to the sysctl caller. And this should not happen. So the fix is to NOT modify ret here.

You are correct, my apologies for that.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

Your statement sounds as if xsm_getdomaininfo() would always return the same value for a given caller domain. Isn't that return value also depending on the domain specified via the second parameter? In case it isn't, why does that parameter even exist?

It would if the default action was something other than XSM_HOOK. Look at line 82 of include/xsm/dummy.h. XSM_HOOK will always return 0 regardless of the src or dest domains. The function xsm_defualt_action() is the policy for both default/dummy and SILO with the exception for evntchn, grants, and argo checks for SILO.

Sorry, one last clarification. xsm_default_action() is also what is used when XSM=n. The difference is that for XSM=n, xsm_default_action() is in-lined at the call site whereas with XSM=y and not using FLASK results in a function call xsm_default_action().

v/r,
dps

#8 lore raw
In reply to Daniel P. Smith
Quoted 33 lines · Daniel P. Smith
Quoted 32 lines · Juergen Gross
Quoted 30 lines · Daniel P. Smith
Quoted 19 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
  xen/common/sysctl.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +0 -0
index 02505ab044..0cbfe8bd44 100644

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 93

Quoted 7 lines
xen/common/sysctl.c +1 -2
@@ -89,8 +89,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Quoted 5 lines
Quoted 3 lines

You are missing the fact that ret getting set by a failing xsm_getdomaininfo() call might result in the ret value being propagated to the sysctl caller. And this should not happen. So the fix is to NOT modify ret here.

You are correct, my apologies for that.

No need to apologize. :-)

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

Your statement sounds as if xsm_getdomaininfo() would always return the same value for a given caller domain. Isn't that return value also depending on the domain specified via the second parameter? In case it isn't, why does that parameter even exist?

It would if the default action was something other than XSM_HOOK. Look at line 82 of include/xsm/dummy.h. XSM_HOOK will always return 0 regardless of the src or dest domains. The function xsm_defualt_action() is the policy for both default/dummy and SILO with the exception for evntchn, grants, and argo checks for SILO.

Ah, okay. I didn't analyze all of the involved xsm code.

Juergen

#9 lore raw
Quoted 35 lines · Juergen Gross
Quoted 34 lines · Daniel P. Smith
Quoted 33 lines · Juergen Gross
Quoted 31 lines · Daniel P. Smith
Quoted 19 lines · Juergen Gross

In case XSM is active, the handling of XEN_SYSCTL_getdomaininfolist can fail if the last domain scanned isn't allowed to be accessed by the calling domain (i.e. xsm_getdomaininfo(XSM_HOOK, d) is failing).

Fix that by just ignoring scanned domains where xsm_getdomaininfo() is returning an error, like it is effectively done when such a situation occurs for a domain not being the last one scanned.

Fixes d046f361dc93 ("Xen Security Modules: XSM")

---
  xen/common/sysctl.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/sysctl.c +0 -0
index 02505ab044..0cbfe8bd44 100644

xen/common/sysctl.c long · line 94

Quoted 8 lines
xen/common/sysctl.c +1 -2
@@ -89,8 +89,7 @@ long 
 do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
               if ( num_domains == op->u.getdomaininfolist.max_domains )
                   break;
-            ret = xsm_getdomaininfo(XSM_HOOK, d);
-            if ( ret )
+            if ( xsm_getdomaininfo(XSM_HOOK, d) )
                   continue;
               getdomaininfo(d, &info);

This change does not match the commit message. This says it fixes an issue, but unless I am totally missing something, this change is nothing more than formatting that drops the use of an intermediate variable. Please feel free to correct me if I am wrong here, otherwise I believe the commit message should be changed to reflect the code change.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You are missing the fact that ret getting set by a failing xsm_getdomaininfo() call might result in the ret value being propagated to the sysctl caller. And this should not happen. So the fix is to NOT modify ret here.

You are correct, my apologies for that.

No need to apologize. :-)

I believe it is proper to admit when you are wrong.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Second, as far as the problem description goes. The *only* time the call to xsm_getdomaininfo() at this location will return anything other than 0, is when FLASK is being used and a domain whose type is not allowed getdomaininfo is making the call. XSM_HOOK signals a no-op check for the default/dummy policy, and the SILO policy does not override the default/dummy policy for this check.

Your statement sounds as if xsm_getdomaininfo() would always return the same value for a given caller domain. Isn't that return value also depending on the domain specified via the second parameter? In case it isn't, why does that parameter even exist?

It would if the default action was something other than XSM_HOOK. Look at line 82 of include/xsm/dummy.h. XSM_HOOK will always return 0 regardless of the src or dest domains. The function xsm_defualt_action() is the policy for both default/dummy and SILO with the exception for evntchn, grants, and argo checks for SILO.

Ah, okay. I didn't analyze all of the involved xsm code.

No worries! I am always willing to help in any way that I can. While I don't have the bandwidth to be proactive and keep up with everything on xen-devel, please do not hesitate to ask me or ping me on anything XSM related. I will gladly take a look and provide what insights I might have on your query.

v/r,
dps