All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Alexandru Stefan ISAILA <aisaila@bitdefender.com>
Cc: "Petre Ovidiu PIRCALABU" <ppircalabu@bitdefender.com>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Tamas K Lengyel" <tamas@tklengyel.com>, "Wei Liu" <wl@xen.org>,
	"Razvan COJOCARU" <rcojocaru@bitdefender.com>,
	"George Dunlap" <george.dunlap@eu.citrix.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Jun Nakajima" <jun.nakajima@intel.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH V5 1/4] x86/mm: Add array_index_nospec to guest provided index values
Date: Fri, 20 Dec 2019 10:39:44 +0100	[thread overview]
Message-ID: <fcfd9555-9e02-5405-443a-e3f981f06494@suse.com> (raw)
In-Reply-To: <9f1b936d-8a3c-8ef3-a184-c0846b01d250@bitdefender.com>

On 20.12.2019 10:09, Alexandru Stefan ISAILA wrote:
> 
> 
> On 19.12.2019 12:43, Jan Beulich wrote:
>> On 19.12.2019 10:42, Alexandru Stefan ISAILA wrote:
>>> This patch aims to sanitize indexes, potentially guest provided
>>> values, for altp2m_eptp[] and altp2m_p2m[] arrays.
>>>
>>> Requested-by: Jan Beulich <jbeulich@suse.com>
>>> Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
>>> ---
>>> CC: Razvan Cojocaru <rcojocaru@bitdefender.com>
>>> CC: Tamas K Lengyel <tamas@tklengyel.com>
>>> CC: Petre Pircalabu <ppircalabu@bitdefender.com>
>>> CC: George Dunlap <george.dunlap@eu.citrix.com>
>>> CC: Jan Beulich <jbeulich@suse.com>
>>> CC: Andrew Cooper <andrew.cooper3@citrix.com>
>>> CC: Wei Liu <wl@xen.org>
>>> CC: "Roger Pau Monné" <roger.pau@citrix.com>
>>> CC: Jun Nakajima <jun.nakajima@intel.com>
>>> CC: Kevin Tian <kevin.tian@intel.com>
>>> ---
>>> Changes since V4:
>>> 	- Change bounds check from MAX_EPTP to MAX_ALTP2M
>>> 	- Move array_index_nospec() closer to the bounds check.
>>> ---
>>>   xen/arch/x86/mm/mem_access.c | 15 +++++++++------
>>>   xen/arch/x86/mm/p2m.c        | 20 ++++++++++++++------
>>>   2 files changed, 23 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c
>>> index 320b9fe621..33e379db8f 100644
>>> --- a/xen/arch/x86/mm/mem_access.c
>>> +++ b/xen/arch/x86/mm/mem_access.c
>>> @@ -367,10 +367,11 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
>>>       if ( altp2m_idx )
>>>       {
>>>           if ( altp2m_idx >= MAX_ALTP2M ||
> 
> Ok, so have if ( altp2m_idx >=  min(ARRAY_SIZE(d->arch.altp2m_eptp), 
> MAX_EPTP) ||
> here and then...
> 
>>> -             d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) )
>>> +             d->arch.altp2m_eptp[array_index_nospec(altp2m_idx, MAX_ALTP2M)] ==
> 
> have MAX_EPTP here and ...
> 
>>
>> As implied by a reply to v4, this is still latently buggy: There's
>> no guarantee anyone will notice the issue here when bumping
>> MAX_ALTP2M past MAX_EPTP. The only future proof thing to do here
>> is, as suggested, using some form of min(MAX_ALTP2M, MAX_EPTP) in
>> the actual bounds check. Then each array access itself can be made
>> use the correct bound. In fact you'd probably have noticed this if
>> you had made use of array_access_nospec() where possible (which
>> also would help readability) - apparently not here, but ... >
>>> +             mfn_x(INVALID_MFN) )
>>>               return -EINVAL;
>>>   
>>> -        ap2m = d->arch.altp2m_p2m[altp2m_idx];
>>> +        ap2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, MAX_ALTP2M)];
> 
> MAX_ALTP2M here ?

Yes, that's how I think it ought to be. Give others a chance to
disagree with me, though.

Jan

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

  reply	other threads:[~2019-12-20  9:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  9:42 [Xen-devel] [PATCH V5 1/4] x86/mm: Add array_index_nospec to guest provided index values Alexandru Stefan ISAILA
2019-12-19  9:42 ` [Xen-devel] [PATCH V5 2/4] x86/altp2m: Add hypercall to set a range of sve bits Alexandru Stefan ISAILA
2019-12-19 10:52   ` Jan Beulich
2019-12-19  9:42 ` [Xen-devel] [PATCH V5 3/4] x86/mm: Pull out the p2m specifics from p2m_init_altp2m_ept Alexandru Stefan ISAILA
2019-12-19  9:43 ` [Xen-devel] [PATCH V5 4/4] x86/mm: Make use of the default access param from xc_altp2m_create_view Alexandru Stefan ISAILA
2019-12-19 10:43 ` [Xen-devel] [PATCH V5 1/4] x86/mm: Add array_index_nospec to guest provided index values Jan Beulich
2019-12-20  9:09   ` Alexandru Stefan ISAILA
2019-12-20  9:39     ` Jan Beulich [this message]
2019-12-20 11:49       ` Alexandru Stefan ISAILA
2019-12-20 12:24         ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fcfd9555-9e02-5405-443a-e3f981f06494@suse.com \
    --to=jbeulich@suse.com \
    --cc=aisaila@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=ppircalabu@bitdefender.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=roger.pau@citrix.com \
    --cc=tamas@tklengyel.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.