x86/mm: Prevent leaking domain mappings in paging_log_dirty_op()
PATCH 1/1 x86/mm: Prevent leaking domain mappings in paging_log_dirty_op()
Coverity ID: 1135374 1135375 1135376 1135377
If {copy_to,clear}_guest_offset() fails, we would leak the domain mappings for l4 thru l1.
Fixing this requires having conditional unmaps on the faulting path, which in turn requires explicitly initialising the pointers to NULL because of the early ENOMEM exit.
--- xen/arch/x86/mm/paging.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
xen/arch/x86/mm/paging.c +11 -2
@@ -330,8 +330,8 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) {int rv =0 , clean =0 , peek =1 ;unsigned long pages =0 ; -mfn_t *l4, *l3, *l2; -unsigned long *l1; +mfn_t *l4 =NULL , *l3 =NULL , *l2 =NULL ; +unsigned long *l1 =NULL ;int i4, i3, i2;domain_pause (d);
@@ -432,6 +432,15 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc)return rv; out: +if ( l1 ) +unmap_domain_page (l1); +if ( l2 ) +unmap_domain_page (l2); +if ( l3 ) +unmap_domain_page (l3); +if ( l4 ) +unmap_domain_page (l4); +paging_unlock (d);domain_unpause (d);return rv;
Signature · 1 line
1.7.10.4
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Coverity ID: 1135374 1135375 1135376 1135377
If {copy_to,clear}_guest_offset() fails, we would leak the domain mappings for
l4 thru l1.
Quoted 6 lines
Fixing this requires having conditional unmaps on the faulting path, which in
turn requires explicitly initialising the pointers to NULL because of the early ENOMEM exit.Signed-off-by Andrew Cooper <[email protected]>
with a minor comment:
Quoted 6 lines
xen/arch/x86/mm/paging.c +2
-0@@ -432,6 +432,15 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc)return rv; out: +if ( l1 ) +unmap_domain_page (l1);
xen/arch/x86/mm/paging.c int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) · line 446
Quoted 10 lines
xen/arch/x86/mm/paging.c +7
-0+if ( l2 ) +unmap_domain_page (l2); +if ( l3 ) +unmap_domain_page (l3); +if ( l4 ) +unmap_domain_page (l4); +paging_unlock (d);domain_unpause (d);return rv;
While on an error path, it would nevertheless seem better to do the unmaps after the unlock/unpause.
Jan
PATCH v2 1/1 x86/mm: Prevent leaking domain mappings in paging_log_dirty_op()
Coverity ID: 1135374 1135375 1135376 1135377
If {copy_to,clear}_guest_offset() fails, we would leak the domain mappings for l4 thru l1.
Fixing this requires having conditional unmaps on the faulting path, which in turn requires explicitly initialising the pointers to NULL because of the early ENOMEM exit.
---
Changes in v2:
* Reorder unmaps until after the unlock/unpause (Suggested by Jan)
--- xen/arch/x86/mm/paging.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
xen/arch/x86/mm/paging.c +12 -2
@@ -330,8 +330,8 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) {int rv =0 , clean =0 , peek =1 ;unsigned long pages =0 ; -mfn_t *l4, *l3, *l2; -unsigned long *l1; +mfn_t *l4 =NULL , *l3 =NULL , *l2 =NULL ; +unsigned long *l1 =NULL ;int i4, i3, i2;domain_pause (d);
@@ -434,6 +434,16 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) out:paging_unlock (d);domain_unpause (d); + +if ( l1 ) +unmap_domain_page (l1); +if ( l2 ) +unmap_domain_page (l2); +if ( l3 ) +unmap_domain_page (l3); +if ( l4 ) +unmap_domain_page (l4); +return rv; }
Signature · 1 line
1.7.10.4
Ping: [Patch v2] x86/mm: Prevent leaking domain mappings in paging_log_dirty_op()
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Coverity ID: 1135374 1135375 1135376 1135377
If {copy_to,clear}_guest_offset() fails, we would leak the domain mappings for
l4 thru l1.Fixing this requires having conditional unmaps on the faulting path, which in
turn requires explicitly initialising the pointers to NULL because of the early ENOMEM exit.
Quoted 4 lines
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>Reviewed-by Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>
Tim?
Quoted 50 lines
---
Changes in v2:
* Reorder unmaps until after the unlock/unpause (Suggested by Jan)--- xen/arch/x86/mm/paging.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +2
-2@@ -330,8 +330,8 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) {int rv =0 , clean =0 , peek =1 ;unsigned long pages =0 ; -mfn_t *l4, *l3, *l2; -unsigned long *l1; +mfn_t *l4 =NULL , *l3 =NULL , *l2 =NULL ; +unsigned long *l1 =NULL ;int i4, i3, i2;domain_pause(d);xen/arch/x86/mm/paging.c +10
-0@@ -434,6 +434,16 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) out:paging_unlock (d );domain_unpause (d); + +if ( l1 ) +unmap_domain_page (l1); +if ( l2 ) +unmap_domain_page (l2); +if ( l3 ) +unmap_domain_page (l3); +if ( l4 ) +unmap_domain_page (l4); +return rv; }Signature · 8 lines
-- 1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Tim Deegan
Acked-byRe: Ping: [Patch v2] x86/mm: Prevent leaking domain mappings in paging_log_dirty_op()
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Coverity ID: 1135374 1135375 1135376 1135377
If {copy_to,clear}_guest_offset() fails, we would leak the domain mappings for
l4 thru l1.Fixing this requires having conditional unmaps on the faulting path, which in
turn requires explicitly initialising the pointers to NULL because of the early ENOMEM exit.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>Reviewed-by Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>Tim?
Sorry, I hadn't seen v2. I think I'd prefer the unmap to be done at the one 'goto out', where we know that all four are mapped (so no initializers needed either; doing it this way may lead to double-frees if any more 'goto out's get added. But taking into account Jan's comment about dropping the locks first, I guess that's OK.
Quoted 58 lines
Quoted 50 lines
---
Changes in v2:
* Reorder unmaps until after the unlock/unpause (Suggested by Jan)--- xen/arch/x86/mm/paging.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +2
-2@@ -330,8 +330,8 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) {int rv =0 , clean =0 , peek =1 ;unsigned long pages =0 ; -mfn_t *l4, *l3, *l2; -unsigned long *l1; +mfn_t *l4 =NULL , *l3 =NULL , *l2 =NULL ; +unsigned long *l1 =NULL ;int i4, i3, i2;domain_pause(d);xen/arch/x86/mm/paging.c +10
-0@@ -434,6 +434,16 @@ int paging_log_dirty_op(struct domain *d, struct xen_domctl_shadow_op *sc) out:paging_unlock (d );domain_unpause (d); + +if ( l1 ) +unmap_domain_page (l1); +if ( l2 ) +unmap_domain_page (l2); +if ( l3 ) +unmap_domain_page (l3); +if ( l4 ) +unmap_domain_page (l4); +return rv; }Signature · 8 lines
-- 1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel