flask: sort io{port,mem}con entries
PATCH v2 1/1 flask: sort io{port,mem}con entries
These entries are not always sorted by checkpolicy, so sort them during policy load (as is already done for later ocontext additions).
--- xen/xsm/flask/ss/policydb.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
xen/xsm/flask/ss/policydb.c +29 -6
@@ -1737,7 +1737,7 @@ int policydb_read(struct policydb *p, void *fp) {struct role_allow *ra, *lra;struct role_trans *tr, *ltr; -struct ocontext *l, *c/*, *newc*/ ; +struct ocontext *l, *c, **pn;int i, j, rc;__le32 buf[8 ];u32 len,/*len2,*/ config, nprim, nel/*, nel2*/ ;
@@ -1994,6 +1994,7 @@ int policydb_read(struct policydb *p, void *fp)if ( rc <0 ) goto bad; nel =le32_to_cpu (buf[0 ]); + pn = &p->ocontexts[i]; l =NULL ;for ( j =0 ; j < nel; j++ ) {
@@ -2003,11 +2004,6 @@ int policydb_read(struct policydb *p, void *fp) rc = -ENOMEM ; goto bad; } -if ( l ) - l->next = c; -else - p->ocontexts[i] = c; - l = c; rc = -EINVAL ;switch ( i ) {
@@ -2050,6 +2046,18 @@ int policydb_read(struct policydb *p, void *fp) rc =context_read_and_validate (&c->context, p, fp);if ( rc ) goto bad; + +if ( *pn || ( l && l->u.ioport.high_ioport >= c->u.ioport.low_ioport ) ) + { + pn = &p->ocontexts[i]; + l = *pn; +while ( l && l->u.ioport.high_ioport < c->u.ioport.low_ioport ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c;break ;case OCON_IOMEM :if ( p->target_type !=TARGET_XEN )
@@ -2078,6 +2086,18 @@ int policydb_read(struct policydb *p, void *fp) rc =context_read_and_validate (&c->context, p, fp);if ( rc ) goto bad; + +if ( *pn || ( l && l->u.iomem.high_iomem >= c->u.iomem.low_iomem ) ) + { + pn = &p->ocontexts[i]; + l = *pn; +while ( l && l->u.iomem.high_iomem < c->u.iomem.low_iomem ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c;break ;case OCON_DEVICE :if ( p->target_type !=TARGET_XEN )
@@ -2123,6 +2143,9 @@ int policydb_read(struct policydb *p, void *fp) rc = -EINVAL ; goto bad; } + + *pn = c; + pn = &c->next; } }
Signature · 7 lines
2.14.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 96 lines
-----Daniel De Graaf <[email protected]> wrote: -----
To: [email protected], Nicolas Poirot <[email protected]>
From: Daniel De Graaf <[email protected]>
Date: 10/05/2018 06:33PM
Cc: George Dunlap <[email protected]>, Jan Beulich <[email protected]>, Daniel De Graaf <[email protected]>
Subject: [PATCH v2] flask: sort io{port,mem}con entriesThese entries are not always sorted by checkpolicy, so sort them during policy load (as is already done for later ocontext additions).
Reported-by Nicolas Poirot <[email protected]>Signed-off-by Daniel De Graaf <[email protected]>---
xen/xsm/flask/ss/policydb.c | 35 +++++++++++++++++++++++++++++------1 file changed, 29 insertions(+), 6 deletions(-)xen/xsm/flask/ss/policydb.c +14
-6@@ -1737,7 +1737,7 @@ int policydb_read(struct policydb *p, void *fp) { struct role_allow *ra, *lra; struct role_trans *tr, *ltr; - struct ocontext *l, *c /*, *newc*/; + struct ocontext *l, *c, **pn; int i, j, rc; __le32 buf[8]; u32 len, /*len2,*/ config, nprim, nel /*, nel2*/;@@ -1994,6 +1994,7 @@ int policydb_read(struct policydb *p, void *fp) if ( rc < 0 ) goto bad; nel = le32_to_cpu(buf[0]); + pn = &p->ocontexts[i]; l = NULL; for ( j = 0; j < nel; j++ ) {@@ -2003,11 +2004,6 @@ int policydb_read(struct policydb *p, void *fp) rc = -ENOMEM; goto bad; } - if ( l ) - l->next = c; - else - p->ocontexts[i] = c; - l = c; rc = -EINVAL; switch ( i ) {@@ -2050,6 +2046,18 @@ int policydb_read(struct policydb *p, void *fp) rc = context_read_and_validate(&c->context, p, fp); if ( rc ) goto bad; + + if ( *pn || ( l && l->u.ioport.high_ioport >= c->u.ioport.low_ioport ) ) + { + pn = &p->ocontexts[i]; + l = *pn; + while ( l && l->u.ioport.high_ioport < c->u.ioport.low_ioport ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c; break;case
OCON_IOMEM:
if (p->target_type!=TARGET_XEN)xen/xsm/flask/ss/policydb.c +12
-0@@ -2078,6 +2086,18 @@ int policydb_read(struct policydb *p, void *fp) rc = context_read_and_validate(&c->context, p, fp); if ( rc ) goto bad; + + if ( *pn || ( l && l->u.iomem.high_iomem >= c->u.iomem.low_iomem ) ) + { + pn = &p->ocontexts[i]; + l = *pn; + while ( l && l->u.iomem.high_iomem < c->u.iomem.low_iomem ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c; break;case
OCON_DEVICE:
if (p->target_type!=TARGET_XEN)xen/xsm/flask/ss/policydb.c +3
-0@@ -2123,6 +2143,9 @@ int policydb_read(struct policydb *p, void *fp) rc = -EINVAL; goto bad; } + + *pn = c; + pn = &c->next; } }
Quoted 3 lines
Signature · 1 line
2.14.4
Tested in the same conditions as the previous patch, looks good. Thank you.
1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 99 lines
-----Daniel De Graaf <[email protected]> wrote: -----
To: [email protected], Nicolas Poirot <[email protected]>
From: Daniel De Graaf <[email protected]>
Date: 05/10/2018 18:33
Cc: George Dunlap <[email protected]>, Jan Beulich <[email protected]>, Daniel De Graaf <[email protected]>
Subject: [PATCH v2] flask: sort io{port,mem}con entriesThese entries are not always sorted by checkpolicy, so sort them during policy load (as is already done for later ocontext additions).
Reported-by Nicolas Poirot <[email protected]>Signed-off-by Daniel De Graaf <[email protected]>--- xen/xsm/flask/ss/policydb.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)xen/xsm/flask/ss/policydb.c +29
-6@@ -1737,7 +1737,7 @@ int policydb_read(struct policydb *p, void *fp) {struct role_allow *ra, *lra;struct role_trans *tr, *ltr; -struct ocontext *l, *c/*, *newc*/ ; +struct ocontext *l, *c, **pn;int i, j, rc;__le32 buf[8 ];u32 len,/*len2,*/ config, nprim, nel/*, nel2*/ ;@@ -1994,6 +1994,7 @@ int policydb_read(struct policydb *p, void *fp)if ( rc <0 ) goto bad; nel =le32_to_cpu (buf[0 ]); + pn = &p->ocontexts[i]; l =NULL ;for ( j =0 ; j < nel; j++ ) {@@ -2003,11 +2004,6 @@ int policydb_read(struct policydb *p, void *fp) rc = -ENOMEM ; goto bad; } -if ( l ) - l->next = c; -else - p->ocontexts[i] = c; - l = c; rc = -EINVAL ;switch ( i ) {@@ -2050,6 +2046,18 @@ int policydb_read(struct policydb *p, void *fp) rc =context_read_and_validate (&c->context, p, fp);if ( rc ) goto bad; + +if ( *pn || ( l && l->u.ioport.high_ioport >= c->u.ioport.low_ioport ) ) + { + pn = &p->ocontexts[i]; + l = *pn; +while ( l && l->u.ioport.high_ioport < c->u.ioport.low_ioport ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c;break ;case OCON_IOMEM :if ( p->target_type !=TARGET_XEN )@@ -2078,6 +2086,18 @@ int policydb_read(struct policydb *p, void *fp) rc =context_read_and_validate (&c->context, p, fp);if ( rc ) goto bad; + +if ( *pn || ( l && l->u.iomem.high_iomem >= c->u.iomem.low_iomem ) ) + { + pn = &p->ocontexts[i]; + l = *pn; +while ( l && l->u.iomem.high_iomem < c->u.iomem.low_iomem ) { + pn = &l->next; + l = *pn; + } + c->next = l; + } + l = c;break ;case OCON_DEVICE :if ( p->target_type !=TARGET_XEN )@@ -2123,6 +2143,9 @@ int policydb_read(struct policydb *p, void *fp) rc = -EINVAL ; goto bad; } + + *pn = c; + pn = &c->next; } }Signature · 1 line
2.14.4
Tested on the same conditions as the previous patch, looks good. Thank you.
1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel