From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Tim Deegan <tim@xen.org>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
keir@xen.org, David Binderman <dcb314@hotmail.com>,
jbeulich@suse.com
Subject: Re: [PATCH] Re: xen-4.3.1:hvm.c: 2 * possible bad if tests ?
Date: Thu, 21 Nov 2013 15:07:07 +0000 [thread overview]
Message-ID: <528E219B.6060801@citrix.com> (raw)
In-Reply-To: <20131121150355.GC89770@deinos.phlegethon.org>
On 21/11/13 15:03, Tim Deegan wrote:
> At 11:54 +0000 on 21 Nov (1385031246), Andrew Cooper wrote:
>> On 21/11/13 11:45, David Binderman wrote:
>>> Hello there,
>>>
>>> I just ran the source code of xen-4.3.1 through the static analyser "cppcheck".
>>>
>>> It said
>>>
>>> 1.
>>>
>>> [hvm.c:2190]: (style) Expression '(X & 0xc00) != 0x6' is always true.
>>>
>>> Source code is
>>>
>>> if ( ((desc.b & (6u<<9)) != 6) && (dpl != rpl) )
>>> goto unmap_and_fail;
>>>
>>> You might be better off with
>>>
>>> if ( ((desc.b & (6u<<9))) && (dpl != rpl) )
>>> goto unmap_and_fail;
>>>
>>> 2.
>>>
>>> [hvm.c:2210]: (style) Expression '(X & 0xc00) != 0x6' is always true.
>>>
>>> Source code is
>>>
>>> if ( ((desc.b & (6u<<9)) != 6) && ((dpl < cpl) || (dpl < rpl)) )
>>> goto unmap_and_fail;
>> These have both been flagged up by our Coverity scanning, but I haven't
>> had enough time to pour over the manuals workout out the correct
>> expression should be.
>>
>> The prevailing style for all other checks in this area is "(X & (6u<<9))
>> != (6u<<9)" , which is rather different to the result you came up with.
>>
>> As this is the security checks for segment selectors in the emulation
>> code, leaving it in its current "too many operations are failed" is
>> safer than being uncertain with the fix and introducing a vulnerability.
> Looking at the manual and the comment, I think the right change is:
>
> x86/hvm: fix test for non-conforming segments.
>
> Reported-by: David Binderman <dcb314@hotmail.com>
> Signed-off-by: Tim Deegan <tim@xen.org>
>
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -2278,7 +2278,7 @@ static int hvm_load_segment_selector(
> if ( !(desc.b & (1u<<11)) )
> goto unmap_and_fail;
> /* Non-conforming segment: check DPL against RPL. */
> - if ( ((desc.b & (6u<<9)) != 6) && (dpl != rpl) )
> + if ( !(desc.b & (1u<<10)) && (dpl != rpl) )
> goto unmap_and_fail;
> break;
> case x86_seg_ss:
>
There is another example higher in the switch statement for the code
segment selector.
Also, the commit should probably have CID 1055180 referenced ?
~Andrew
next prev parent reply other threads:[~2013-11-21 15:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 11:45 xen-4.3.1:hvm.c: 2 * possible bad if tests ? David Binderman
2013-11-21 11:54 ` Andrew Cooper
2013-11-21 15:03 ` [PATCH] " Tim Deegan
2013-11-21 15:07 ` Andrew Cooper [this message]
2013-11-21 15:13 ` Tim Deegan
2013-11-21 15:19 ` Keir Fraser
2013-11-21 15:32 ` Tim Deegan
2013-11-21 18:56 ` Andrew Cooper
2013-11-22 11:50 ` Jan Beulich
2013-11-22 11:54 ` Tim Deegan
2013-11-22 14:20 ` [PATCH v4 1/2] x86/hvm: fix segment validation Jan Beulich
2013-11-22 14:25 ` Andrew Cooper
2013-11-22 14:21 ` [PATCH v4 2/2] x86/hvm: clean up " Jan Beulich
2013-11-22 14:27 ` Andrew Cooper
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=528E219B.6060801@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=dcb314@hotmail.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=tim@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.