From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] kvm: Fix off by one in kvm_for_each_vcpu iteration Date: Sun, 17 Apr 2011 12:11:44 +0300 Message-ID: <4DAAAED0.6090905@redhat.com> References: <4DA4FCA9.9070508@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Marcelo Tosatti , Neil Brown To: Jeff Mahoney Return-path: Received: from mx1.redhat.com ([209.132.183.28]:12669 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489Ab1DQJLz (ORCPT ); Sun, 17 Apr 2011 05:11:55 -0400 In-Reply-To: <4DA4FCA9.9070508@suse.com> Sender: kvm-owner@vger.kernel.org List-ID: On 04/13/2011 04:30 AM, Jeff Mahoney wrote: > This patch avoids gcc issuing the following warning when KVM_MAX_VCPUS=1: > warning: array subscript is above array bounds > > kvm_for_each_vcpu currently checks to see if the index for the vcpu is > valid /after/ loading it. We don't run into problems because the address > is still inside the enclosing struct kvm and we never deference or write > to it, so this isn't a security issue. > > The warning occurs when KVM_MAX_VCPUS=1 because the increment portion of > the loop will *always* cause the loop to load an invalid location since > ++idx will always be> 0. > > This patch moves the load so that the check occurs before the load and > we don't run into the compiler warning. Applied, thanks. -- error compiling committee.c: too many arguments to function