[kernel-hardening] Re: [PATCH v3 4/4] KVM: VMX: Simplify segment_base

Andy Lutomirski
2017-02-15T03:57:21Z

On Tue, Feb 14, 2017 at 11:42 AM, Thomas Garnier <thgarnie@google.com> wrote:
> The KVM segment_base function is confusing. This patch replaces integers
> with appropriate flags, simplify constructs and add comments.

It could pay to put this first in the series, but last is probably fine, too.

>
> Signed-off-by: Thomas Garnier <thgarnie@google.com>
> ---
> Based on next-20170213
> ---
> arch/x86/kvm/vmx.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 99167f20bc34..edb8326108dd 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2062,25 +2062,35 @@ static unsigned long segment_base(u16 selector)
> struct desc_struct *d;
> unsigned long table_base;

This should go away IMO. It should be struct desc_struct *table;

> + table_base = get_current_gdt_rw_vaddr();

Then this can go away, too, and you can stop having the silly
get_current_gdt_rw_vaddr() function at all.

> + d = (struct desc_struct *)table_base + (selector >> 3);

And this cast goes away too.