lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4B87A05A.3010600@redhat.com>
Date:	Fri, 26 Feb 2010 12:20:10 +0200
From:	Avi Kivity <avi@...hat.com>
To:	Joerg Roedel <joerg.roedel@....com>
CC:	Marcelo Tosatti <mtosatti@...hat.com>,
	Alexander Graf <agraf@...e.de>, kvm@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/5] KVM: SVM: Move msrpm offset calculation to seperate
 function

On 02/25/2010 07:15 PM, Joerg Roedel wrote:
> The algorithm to find the offset in the msrpm for a given
> msr is needed at other places too. Move that logic to its
> own function.
>
>   #define MAX_INST_SIZE 15
>
> @@ -417,23 +439,22 @@ err_1:
>   static void set_msr_interception(u32 *msrpm, unsigned msr,
>   				 int read, int write)
>   {
> -	int i;
> +	u8 bit_read, bit_write;
> +	unsigned long tmp;
> +	u32 offset;
>
> -	for (i = 0; i<  NUM_MSR_MAPS; i++) {
> -		if (msr>= msrpm_ranges[i]&&
> -		    msr<  msrpm_ranges[i] + MSRS_IN_RANGE) {
> -			u32 msr_offset = (i * MSRS_IN_RANGE + msr -
> -					  msrpm_ranges[i]) * 2;
> -
> -			u32 *base = msrpm + (msr_offset / 32);
> -			u32 msr_shift = msr_offset % 32;
> -			u32 mask = ((write) ? 0 : 2) | ((read) ? 0 : 1);
> -			*base = (*base&  ~(0x3<<  msr_shift)) |
> -				(mask<<  msr_shift);
> -			return;
> -		}
> -	}
> -	BUG();
> +	offset    = svm_msrpm_offset(msr);
> +	bit_read  = 2 * (msr&  0x0f);
> +	bit_write = 2 * (msr&  0x0f) + 1;
> +
> +	BUG_ON(offset == MSR_INVALID);
> +
> +	tmp = msrpm[offset];
> +
> +	read  ? clear_bit(bit_read,&tmp) : set_bit(bit_read,&tmp);
> +	write ? clear_bit(bit_write,&tmp) : set_bit(bit_write,&tmp);
> +
> +	msrpm[offset] = tmp;
>   }
>    

This can fault - set_bit() accesses an unsigned long, which can be 8 
bytes, while offset can point into the last u32 of msrpm.  So this needs 
either to revert to u32 shift/mask ops or msrpm be changed to a ulong 
array (actually better, since bitmaps in general are defined as arrays 
of ulongs).

btw, the op-level ternary expression is terrible, relying solely on 
*_bit()'s side effects.  Please convert to an ordinary if.

btw2, use __set_bit() which atomic operation is not needed.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ