Skip to contentSkip to conversation

xen/xsm: flask: Prevent NULL deference in flask_assign_{, dt}device()

PATCH In review Julien Grall 5 participants 7 messages Oct 4, 2019 – Oct 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/xsm: flask: Prevent NULL deference in flask_assign_{, dt}device()

flask_assign_{, dt}device() may be used to check whether you can test if a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

Fixes 71e617a6b8 ('use is_iommu_enabled() where appropriate...')
---
 xen/xsm/flask/hooks.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/xsm/flask/hooks.c +6 -2
index 3b30827764..cf7f25cda2 100644
@@ -1296,11 +1296,13 @@ static int flask_assign_device(struct domain *d, uint32_t machine_bdf)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_device(machine_bdf);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
         return rc;
@@ -1355,11 +1357,13 @@ static int flask_assign_dtdevice(struct domain *d, const char *dtpath)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_dtdevice(dtpath);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
         return rc;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Julien Grall

flask_assign_{, dt}device() may be used to check whether you can test if a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

Fixes 71e617a6b8 ('use is_iommu_enabled() where appropriate...')

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall
Quoted 11 lines · Julien Grall

flask_assign_{, dt}device() may be used to check whether you can test if a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

Fixes 71e617a6b8 ('use is_iommu_enabled() where appropriate...')
Quoted 39 lines
---
 xen/xsm/flask/hooks.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/xsm/flask/hooks.c +6 -3
index 3b30827764..cf7f25cda2 100644
@@ -1296,11 +1296,13 @@ static int flask_assign_device(struct domain *d, uint32_t machine_bdf)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_device(machine_bdf);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
         return rc;
@@ -1355,11 +1357,13 @@ static int flask_assign_dtdevice(struct domain *d, const char *dtpath)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_dtdevice(dtpath);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
         return rc;
--
Quoted 2 lines

2.11.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Julien Grall
Quoted 10 lines · Julien Grall

flask_assign_{, dt}device() may be used to check whether you can test if a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

Fixes 71e617a6b8 ('use is_iommu_enabled() where appropriate...')

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Julien Grall

Hi Julien

Quoted 10 lines · Julien Grall

flask_assign_{, dt}device() may be used to check whether you can test if
a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up
to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

The correct CID is 1486742

Quoted 43 lines
Fixes 71e617a6b8 ('use is_iommu_enabled() where appropriate...')
Signed-off-by Julien Grall <

[email protected]

Quoted 1 line
---
 xen/xsm/flask/hooks.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/xsm/flask/hooks.c +3 -1
index 3b30827764..cf7f25cda2 100644
@@ -1296,11 +1296,13 @@ static int flask_assign_device(struct domain
 *d, uint32_t machine_bdf)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_device(machine_bdf);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
         return rc;
xen/xsm/flask/hooks.c +3 -1
@@ -1355,11 +1357,13 @@ static int flask_assign_dtdevice(struct
 domain *d, const char *dtpath)
     u32 dsid, rsid;
     int rc = -EPERM;
     struct avc_audit_data ad;
-    u32 dperm = flask_iommu_resource_use_perm(d);
+    u32 dperm;
 
     if ( !d )
         return flask_test_assign_dtdevice(dtpath);
 
+    dperm = flask_iommu_resource_use_perm(d);
+
     rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD);
     if ( rc )
Quoted 1 line
         return rc;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 1 line · Artem Mygaiev

Hi Julien

Hi,

Quoted 5 lines · Julien Grall
Quoted 4 lines

flask_assign_{, dt}device() may be used to check whether you can test if
a device is assigned. In this case, the domain will be NULL.

Quoted 8 lines
Quoted 6 lines

However, flask_iommu_resource_use_perm() will be called and may end up
to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Coverity-ID: 1486741

The correct CID is 1486742

Hmmm yes. The coverity report e-mail is a bit confusing to read.

However, I have already committed the patch so we will have to leave with it :(.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Hi,

Quoted 16 lines · Julien Grall
Quoted 1 line · Artem Mygaiev

Hi Julien

Hi,

Quoted 10 lines · Julien Grall
Quoted 9 lines

flask_assign_{, dt}device() may be used to check whether you can test if
a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up
to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Coverity-ID: 1486741

The correct CID is 1486742

Hmmm yes. The coverity report e-mail is a bit confusing to read.

However, I have already committed the patch so we will have to leave with it :(.

I guess the solution could be to fix another one and make a proper commit comment with cross-reference :)

Quoted 2 lines

Cheers,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel