x86: XSA-45 followup
cover x86: XSA-45 followup
These aren't part of the actual security fixes, but the first helps proving that what needs to be preemptible now really is. The second is really just cleanup the potential for which was noticed while putting together the earlier ones.
1: cleanup after making various page table manipulation operations preemptible 2: miscellaneous mm.c cleanup
PATCH 1/2 x86: cleanup after making various page table manipulation operations preemptible
This drops the "preemptible" parameters from various functions where now they can't (or shouldn't, validated by assertions) be run in non- preemptible mode anymore, to prove that manipulations of at least L3 and L4 page tables and page table entries are now always preemptible, i.e. the earlier patches actually fulfill their purpose of fixing the resulting security issue.
xen/arch/x86/domain.c +1 -1
@@ -1859,7 +1859,7 @@ static int relinquish_memory( }if (test_and_clear_bit (_PGT_pinned, &page->u.inuse.type_info) ) - ret =put_page_and_type_preemptible (page,1 ); + ret =put_page_and_type_preemptible (page);switch ( ret ) {case 0 :
xen/arch/x86/mm.c +52 -46
311 lines not on this page · raw message
xen/include/asm-x86/mm.h +2 -7
@@ -364,15 +364,10 @@ static inline void put_page_and_type(strput_page (page); } -static inline int put_page_and_type_preemptible (struct page_info *page, -int preemptible) +static inline int put_page_and_type_preemptible (struct page_info *page) { -int rc =0 ; +int rc =put_page_type_preemptible (page); -if ( preemptible ) - rc =put_page_type_preemptible (page); -else -put_page_type (page);if (likely (rc ==0 ) )put_page (page);return rc;
x86: cleanup after making various page table manipulation operations preemptible
This drops the "preemptible" parameters from various functions where now they can't (or shouldn't, validated by assertions) be run in non- preemptible mode anymore, to prove that manipulations of at least L3 and L4 page tables and page table entries are now always preemptible, i.e. the earlier patches actually fulfill their purpose of fixing the resulting security issue.
xen/arch/x86/domain.c +1 -1
@@ -1859,7 +1859,7 @@ static int relinquish_memory( }if (test_and_clear_bit (_PGT_pinned, &page->u.inuse.type_info) ) - ret =put_page_and_type_preemptible (page,1 ); + ret =put_page_and_type_preemptible (page);switch ( ret ) {case 0 :
xen/arch/x86/mm.c +52 -46
311 lines not on this page · raw message
xen/include/asm-x86/mm.h +2 -7
@@ -364,15 +364,10 @@ static inline void put_page_and_type(strput_page (page); } -static inline int put_page_and_type_preemptible (struct page_info *page, -int preemptible) +static inline int put_page_and_type_preemptible (struct page_info *page) { -int rc =0 ; +int rc =put_page_type_preemptible (page); -if ( preemptible ) - rc =put_page_type_preemptible (page); -else -put_page_type (page);if (likely (rc ==0 ) )put_page (page);return rc;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/2 x86: miscellaneous mm.c cleanup
In reply to Jan BeulichThis simply streamlines code in a few places, where room for improvement was noticed during the earlier here and the patches in the XSA-45 series.
This also drops the bogus use of the domain lock in the CR3 write emulation (which protected against nothing).
xen/arch/x86/mm.c +18 -34
@@ -2075,19 +2075,17 @@ static int alloc_page_type(struct page_i/* No need for atomic update of type_info here: noone else updates it. */ wmb (); -if ( rc == -EAGAIN ) - { -get_page_light (page); - page->u.inuse.type_info |= PGT_partial; - } -else if ( rc == -EINTR ) +switch ( rc ) { +case 0 : + page->u.inuse.type_info |= PGT_validated; +break ; +case -EINTR :ASSERT ((page->u.inuse.type_info & (PGT_count_mask|PGT_validated|PGT_partial)) ==1 ); page->u.inuse.type_info &= ~PGT_count_mask; - } -else if ( rc ) - { +break ; +default :ASSERT (rc <0 ); MEM_LOG("Error while validating mfn %lx (pfn %lx) for type %" PRtype_info ": caf=%08lx taf=%" PRtype_info,
@@ -2099,13 +2097,11 @@ static int alloc_page_type(struct page_i {ASSERT ((page->u.inuse.type_info & (PGT_count_mask | PGT_validated)) ==1 ); +case -EAGAIN :get_page_light (page); page->u.inuse.type_info |= PGT_partial; } - } -else - { - page->u.inuse.type_info |= PGT_validated; +break ; }return rc;
@@ -2884,7 +2880,7 @@ long do_mmuext_op( {struct mmuext_op op;unsigned long type; -unsigned int i =0 , done =0 ; +unsigned int i, done =0 ;struct vcpu *curr = current;struct domain *d = curr->domain;struct domain *pg_owner;
@@ -2917,22 +2913,16 @@ long do_mmuext_op(perfc_incr (calls_to_mmuext_op);if (unlikely (!guest_handle_okay (uops, count)) ) - { - rc = -EFAULT ; - goto out; - } +return -EFAULT ;if ( (pg_owner =get_pg_owner (foreigndom)) ==NULL ) - { - rc = -ESRCH ; - goto out; - } +return -ESRCH ; rc =xsm_mmuext_op (XSM_TARGET , d, pg_owner);if ( rc ) { -rcu_unlock_domain (pg_owner); - goto out; +put_pg_owner (pg_owner); +return rc; }for ( i =0 ; i < count; i++ )
@@ -3404,7 +3394,6 @@ long do_mmuext_op(perfc_add (num_mmuext_ops, i); - out:/* Add incremental work we have done to the @done output parameter. */ if (unlikely (!guest_handle_is_null (pdone)) ) {
@@ -3460,22 +3449,17 @@ long do_mmu_update(perfc_incr (calls_to_mmu_update);if (unlikely (!guest_handle_okay (ureqs, count)) ) - { - rc = -EFAULT ; - goto out; - } +return -EFAULT ;if ( (pt_dom = foreigndom >>16 ) !=0 ) {/* Pagetables belong to a foreign domain (PFD). */ if ( (pt_owner =rcu_lock_domain_by_id (pt_dom -1 )) ==NULL ) - { - rc = -EINVAL ; - goto out; - } +return -EINVAL ; +if ( pt_owner == d )rcu_unlock_domain (pt_owner); -if ( (v = pt_owner->vcpu ? pt_owner->vcpu[0 ] :NULL ) ==NULL ) +else if ( !pt_owner->vcpu || (v = pt_owner->vcpu[0 ]) ==NULL ) { rc = -EINVAL ; goto out;
xen/arch/x86/traps.c +2 -2
@@ -2318,7 +2318,7 @@ static int emulate_privileged_op(structcase 3 : {/* Write CR3 */ unsigned long gfn;struct page_info *page; -domain_lock (v->domain); + gfn = !is_pv_32on64_vcpu (v) ?xen_cr3_to_pfn (*reg) :compat_cr3_to_pfn (*reg); page =get_page_from_gfn (v->domain, gfn,NULL ,P2M_ALLOC );
@@ -2329,7 +2329,7 @@ static int emulate_privileged_op(struct }else rc = -EINVAL ; -domain_unlock (v->domain); +switch ( rc ) {case 0 :
xen/include/asm-x86/config.h +0 -2
@@ -273,8 +273,6 @@ extern unsigned char boot_edid_info[128]#endif -#define PGT_base_page_table PGT_l4_page_table -#define __HYPERVISOR_CS64 0xe008#define __HYPERVISOR_CS32 0xe038#define __HYPERVISOR_CS __HYPERVISOR_CS64
x86: miscellaneous mm.c cleanup
This simply streamlines code in a few places, where room for improvement was noticed during the earlier here and the patches in the XSA-45 series.
This also drops the bogus use of the domain lock in the CR3 write emulation (which protected against nothing).
xen/arch/x86/mm.c +18 -34
108 lines not on this page · raw message
xen/arch/x86/traps.c +2 -2
@@ -2318,7 +2318,7 @@ static int emulate_privileged_op(structcase 3 : {/* Write CR3 */ unsigned long gfn;struct page_info *page; -domain_lock (v->domain); + gfn = !is_pv_32on64_vcpu (v) ?xen_cr3_to_pfn (*reg) :compat_cr3_to_pfn (*reg); page =get_page_from_gfn (v->domain, gfn,NULL ,P2M_ALLOC );
@@ -2329,7 +2329,7 @@ static int emulate_privileged_op(struct }else rc = -EINVAL ; -domain_unlock (v->domain); +switch ( rc ) {case 0 :
xen/include/asm-x86/config.h +0 -2
@@ -273,8 +273,6 @@ extern unsigned char boot_edid_info[128]#endif -#define PGT_base_page_table PGT_l4_page_table -#define __HYPERVISOR_CS64 0xe008#define __HYPERVISOR_CS32 0xe038#define __HYPERVISOR_CS __HYPERVISOR_CS64
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 9 lines · Jan Beulich
These aren't part of the actual security fixes, but the first helps proving that what needs to be preemptible now really is. The second is really just cleanup the potential for which was noticed while putting together the earlier ones.
1: cleanup after making various page table manipulation operations preemptible 2: miscellaneous
mm.ccleanupSigned-off-by Jan Beulich <[email protected]>
Questionable for 4.3? I'm not sure.
-- Keir
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 5 lines · Jan Beulich
These aren't part of the actual security fixes, but the first helps proving that what needs to be preemptible now really is. The second is really just cleanup the potential for which was noticed while putting together the earlier ones.
Quoted 7 lines
Quoted 1 line
1: cleanup after making various page table manipulation operations
preemptible
Quoted 3 lines
2: miscellaneous
mm.ccleanupSigned-off-by Jan Beulich <[email protected]>Questionable for 4.3? I'm not sure.
I'm definitive about the first one, and am even intending to put its backports on the stable branches later today (as the whole batch already passed the push gate). You may have noticed that I committed them already (you should have raised your concern regarding committing them at this stage when these were discussed on security@), so if you're unhappy with the second one to be there we ought to revert it.
Jan
Quoted 16 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 5 lines · Jan Beulich
These aren't part of the actual security fixes, but the first helps proving that what needs to be preemptible now really is. The second is really just cleanup the potential for which was noticed while putting together the earlier ones.
Quoted 7 lines
Quoted 1 line
1: cleanup after making various page table manipulation operations
preemptible
Quoted 3 lines
2: miscellaneous
mm.ccleanupSigned-off-by Jan Beulich <[email protected]>Questionable for 4.3? I'm not sure.
Quoted 7 lines
I'm definitive about the first one, and am even intending to put its backports on the stable branches later today (as the whole batch already passed the push gate). You may have noticed that I committed them already (you should have raised your concern regarding committing them at this stage when these were discussed on security@), so if you're unhappy with the second one to be there we ought to revert it.
Yeah 1/2 looks surely fine, it's just mechanistic cleanup really. 2/2 hmmm well I think it's okay too -- you wouldn't backport that one though, right?
-- Keir
Quoted 2 lines
Jan
Quoted 27 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 16 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 5 lines · Jan Beulich
These aren't part of the actual security fixes, but the first helps proving that what needs to be preemptible now really is. The second is really just cleanup the potential for which was noticed while putting together the earlier ones.
Quoted 7 lines
Quoted 1 line
1: cleanup after making various page table manipulation operations
preemptible
Quoted 3 lines
2: miscellaneous
mm.ccleanupSigned-off-by Jan Beulich <[email protected]>Questionable for 4.3? I'm not sure.
Quoted 7 lines
I'm definitive about the first one, and am even intending to put its backports on the stable branches later today (as the whole batch already passed the push gate). You may have noticed that I committed them already (you should have raised your concern regarding committing them at this stage when these were discussed on security@), so if you're unhappy with the second one to be there we ought to revert it.
Quoted 2 lines
Yeah 1/2 looks surely fine, it's just mechanistic cleanup really. 2/2 hmmm well I think it's okay too -- you wouldn't backport that one though, right?
Right, only the first one.
Jan