All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] XENMEM_add_to_physmap handling adjustments
@ 2017-11-27  8:34 Jan Beulich
  2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Jan Beulich @ 2017-11-27  8:34 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, Wei Liu, Konrad Rzeszutek Wilk,
	George Dunlap, Andrew Cooper, Ian Jackson, Tim Deegan,
	Julien Grall

I'd like to put up the following three changes for consideration of
inclusion in 4.10. Especially when taking only release builds into
account (relevant to patch 1), they're not much more than
cosmetic changes, but imo they still are an overall improvement to
code quality.

1: x86: replace bad ASSERT() in xenmem_add_to_physmap_one()
2: x86: check paging mode earlier in xenmem_add_to_physmap_one()
3: improve XENMEM_add_to_physmap_batch address checking

Signed-off-by: Jan Beulich <jbeulich@suse.com>


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one()
  2017-11-27  8:34 [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Jan Beulich
@ 2017-11-27  9:11 ` Jan Beulich
  2017-11-27 11:39   ` Andrew Cooper
  2017-11-27 14:08   ` George Dunlap
  2017-11-27  9:12 ` [PATCH 2/3] x86: check paging mode earlier " Jan Beulich
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Jan Beulich @ 2017-11-27  9:11 UTC (permalink / raw)
  To: xen-devel
  Cc: George Dunlap, Andrew Cooper, Julien Grall, Konrad Rzeszutek Wilk

There are no locks being held, i.e. it is possible to be triggered by
racy hypercall invocations. Subsequent code doesn't really depend on the
checked values, so this is not a security issue.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
I'm up for to better suggestions for the EXDEV I've used; I certainly
don't want to use -EINVAL, and -EAGAIN (afaik) generally is meant as a
hint to re-invoke with the same arguments (which wouldn't help here).

--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -4143,8 +4143,12 @@ int xenmem_add_to_physmap_one(
     /* Unmap from old location, if any. */
     old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
     ASSERT( old_gpfn != SHARED_M2P_ENTRY );
-    if ( space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range )
-        ASSERT( old_gpfn == gfn );
+    if ( (space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range) &&
+         old_gpfn != gfn )
+    {
+        rc = -EXDEV;
+        goto put_both;
+    }
     if ( old_gpfn != INVALID_M2P_ENTRY )
         rc = guest_physmap_remove_page(d, _gfn(old_gpfn), mfn, PAGE_ORDER_4K);
 




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] x86: check paging mode earlier in xenmem_add_to_physmap_one()
  2017-11-27  8:34 [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Jan Beulich
  2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
@ 2017-11-27  9:12 ` Jan Beulich
  2017-11-27 11:07   ` George Dunlap
  2017-11-27 11:40   ` Andrew Cooper
  2017-11-27  9:12 ` [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking Jan Beulich
  2017-11-27 12:16 ` [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Julien Grall
  3 siblings, 2 replies; 10+ messages in thread
From: Jan Beulich @ 2017-11-27  9:12 UTC (permalink / raw)
  To: xen-devel; +Cc: George Dunlap, Andrew Cooper, Julien Grall

There's no point in deferring this until after some initial processing,
and it's actively wrong for the XENMAPSPACE_gmfn_foreign handling to not
have such a check at all.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -4081,6 +4081,9 @@ int xenmem_add_to_physmap_one(
     mfn_t mfn = INVALID_MFN;
     p2m_type_t p2mt;
 
+    if ( !paging_mode_translate(d) )
+        return -EACCES;
+
     switch ( space )
     {
         case XENMAPSPACE_shared_info:
@@ -4117,7 +4120,7 @@ int xenmem_add_to_physmap_one(
             break;
     }
 
-    if ( !paging_mode_translate(d) || mfn_eq(mfn, INVALID_MFN) )
+    if ( mfn_eq(mfn, INVALID_MFN) )
     {
         rc = -EINVAL;
         goto put_both;




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking
  2017-11-27  8:34 [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Jan Beulich
  2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
  2017-11-27  9:12 ` [PATCH 2/3] x86: check paging mode earlier " Jan Beulich
@ 2017-11-27  9:12 ` Jan Beulich
  2017-11-27 11:41   ` Andrew Cooper
  2017-11-27 12:16 ` [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Julien Grall
  3 siblings, 1 reply; 10+ messages in thread
From: Jan Beulich @ 2017-11-27  9:12 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, Wei Liu, Konrad Rzeszutek Wilk,
	George Dunlap, Andrew Cooper, Ian Jackson, Tim Deegan,
	Julien Grall

As a follow-up to XSA-212 we should have addressed a similar issue here:
The handles being advanced at the top of xenmem_add_to_physmap_batch()
means we allow hypervisor space accesses (in particular, for "errs",
writes) with suitably crafted input arguments. This isn't a security
issue in this case because of the limited width of struct
xen_add_to_physmap_batch's size field: It being 16-bits wide, only the
r/o M2P area can be accessed. Still we can and should do better.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -823,6 +823,11 @@ static int xenmem_add_to_physmap_batch(s
     guest_handle_add_offset(xatpb->errs, start);
     xatpb->size -= start;
 
+    if ( !guest_handle_okay(xatpb->idxs, xatpb->size) ||
+         !guest_handle_okay(xatpb->gpfns, xatpb->size) ||
+         !guest_handle_okay(xatpb->errs, xatpb->size) )
+        return -EFAULT;
+
     while ( xatpb->size > done )
     {
         xen_ulong_t idx;
@@ -1141,10 +1146,7 @@ long do_memory_op(unsigned long cmd, XEN
         if ( start_extent != (typeof(xatpb.size))start_extent )
             return -EDOM;
 
-        if ( copy_from_guest(&xatpb, arg, 1) ||
-             !guest_handle_okay(xatpb.idxs, xatpb.size) ||
-             !guest_handle_okay(xatpb.gpfns, xatpb.size) ||
-             !guest_handle_okay(xatpb.errs, xatpb.size) )
+        if ( copy_from_guest(&xatpb, arg, 1) )
             return -EFAULT;
 
         /* This mapspace is unsupported for this hypercall. */




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] x86: check paging mode earlier in xenmem_add_to_physmap_one()
  2017-11-27  9:12 ` [PATCH 2/3] x86: check paging mode earlier " Jan Beulich
@ 2017-11-27 11:07   ` George Dunlap
  2017-11-27 11:40   ` Andrew Cooper
  1 sibling, 0 replies; 10+ messages in thread
From: George Dunlap @ 2017-11-27 11:07 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: George Dunlap, Andrew Cooper, Julien Grall

On 11/27/2017 09:12 AM, Jan Beulich wrote:
> There's no point in deferring this until after some initial processing,
> and it's actively wrong for the XENMAPSPACE_gmfn_foreign handling to not
> have such a check at all.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: George Dunlap <george.dunlap@citrix.com>

I also agree that this should be considered for inclusion for 4.10.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one()
  2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
@ 2017-11-27 11:39   ` Andrew Cooper
  2017-11-27 14:08   ` George Dunlap
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Cooper @ 2017-11-27 11:39 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: George Dunlap, Julien Grall, Konrad Rzeszutek Wilk

On 27/11/17 09:11, Jan Beulich wrote:
> There are no locks being held, i.e. it is possible to be triggered by
> racy hypercall invocations. Subsequent code doesn't really depend on the
> checked values, so this is not a security issue.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

> ---
> I'm up for to better suggestions for the EXDEV I've used; I certainly
> don't want to use -EINVAL, and -EAGAIN (afaik) generally is meant as a
> hint to re-invoke with the same arguments (which wouldn't help here).

I can't offer a better suggestion.

>
> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -4143,8 +4143,12 @@ int xenmem_add_to_physmap_one(
>      /* Unmap from old location, if any. */
>      old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
>      ASSERT( old_gpfn != SHARED_M2P_ENTRY );
> -    if ( space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range )
> -        ASSERT( old_gpfn == gfn );
> +    if ( (space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range) &&
> +         old_gpfn != gfn )
> +    {
> +        rc = -EXDEV;
> +        goto put_both;
> +    }
>      if ( old_gpfn != INVALID_M2P_ENTRY )
>          rc = guest_physmap_remove_page(d, _gfn(old_gpfn), mfn, PAGE_ORDER_4K);
>  
>
>
>


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] x86: check paging mode earlier in xenmem_add_to_physmap_one()
  2017-11-27  9:12 ` [PATCH 2/3] x86: check paging mode earlier " Jan Beulich
  2017-11-27 11:07   ` George Dunlap
@ 2017-11-27 11:40   ` Andrew Cooper
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Cooper @ 2017-11-27 11:40 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: George Dunlap, Julien Grall

On 27/11/17 09:12, Jan Beulich wrote:
> There's no point in deferring this until after some initial processing,
> and it's actively wrong for the XENMAPSPACE_gmfn_foreign handling to not
> have such a check at all.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking
  2017-11-27  9:12 ` [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking Jan Beulich
@ 2017-11-27 11:41   ` Andrew Cooper
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Cooper @ 2017-11-27 11:41 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: Stefano Stabellini, Wei Liu, Konrad Rzeszutek Wilk,
	George Dunlap, Tim Deegan, Ian Jackson, Julien Grall

On 27/11/17 09:12, Jan Beulich wrote:
> As a follow-up to XSA-212 we should have addressed a similar issue here:
> The handles being advanced at the top of xenmem_add_to_physmap_batch()
> means we allow hypervisor space accesses (in particular, for "errs",
> writes) with suitably crafted input arguments. This isn't a security
> issue in this case because of the limited width of struct
> xen_add_to_physmap_batch's size field: It being 16-bits wide, only the
> r/o M2P area can be accessed. Still we can and should do better.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] XENMEM_add_to_physmap handling adjustments
  2017-11-27  8:34 [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Jan Beulich
                   ` (2 preceding siblings ...)
  2017-11-27  9:12 ` [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking Jan Beulich
@ 2017-11-27 12:16 ` Julien Grall
  3 siblings, 0 replies; 10+ messages in thread
From: Julien Grall @ 2017-11-27 12:16 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: Stefano Stabellini, Wei Liu, Konrad Rzeszutek Wilk,
	George Dunlap, Andrew Cooper, Ian Jackson, Tim Deegan,
	Julien Grall



On 27/11/17 08:34, Jan Beulich wrote:
> I'd like to put up the following three changes for consideration of
> inclusion in 4.10. Especially when taking only release builds into
> account (relevant to patch 1), they're not much more than
> cosmetic changes, but imo they still are an overall improvement to
> code quality.
> 
> 1: x86: replace bad ASSERT() in xenmem_add_to_physmap_one()
> 2: x86: check paging mode earlier in xenmem_add_to_physmap_one()
> 3: improve XENMEM_add_to_physmap_batch address checking
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Release-acked-by: Julien Grall <julien.grall@linaro.org>

Cheers,

> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
> 

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one()
  2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
  2017-11-27 11:39   ` Andrew Cooper
@ 2017-11-27 14:08   ` George Dunlap
  1 sibling, 0 replies; 10+ messages in thread
From: George Dunlap @ 2017-11-27 14:08 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: George Dunlap, Andrew Cooper, Julien Grall, Konrad Rzeszutek Wilk

On 11/27/2017 09:11 AM, Jan Beulich wrote:
> There are no locks being held, i.e. it is possible to be triggered by
> racy hypercall invocations. Subsequent code doesn't really depend on the
> checked values, so this is not a security issue.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: George Dunlap <george.dunlap@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-11-27 14:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27  8:34 [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Jan Beulich
2017-11-27  9:11 ` [PATCH 1/3] x86: replace bad ASSERT() in xenmem_add_to_physmap_one() Jan Beulich
2017-11-27 11:39   ` Andrew Cooper
2017-11-27 14:08   ` George Dunlap
2017-11-27  9:12 ` [PATCH 2/3] x86: check paging mode earlier " Jan Beulich
2017-11-27 11:07   ` George Dunlap
2017-11-27 11:40   ` Andrew Cooper
2017-11-27  9:12 ` [PATCH 3/3] improve XENMEM_add_to_physmap_batch address checking Jan Beulich
2017-11-27 11:41   ` Andrew Cooper
2017-11-27 12:16 ` [PATCH 0/3] XENMEM_add_to_physmap handling adjustments Julien Grall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.