From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754290AbcKUSxD (ORCPT ); Mon, 21 Nov 2016 13:53:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59304 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754103AbcKUSxB (ORCPT ); Mon, 21 Nov 2016 13:53:01 -0500 Subject: Re: [PATCH] vfio: fix vfio_info_cap_add/shift To: Eric Auger , eric.auger.pro@gmail.com, alex.williamson@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <1479709262-4707-1-git-send-email-eric.auger@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <1863bc64-6647-47dd-c499-52e9125c9382@redhat.com> Date: Mon, 21 Nov 2016 19:52:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1479709262-4707-1-git-send-email-eric.auger@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 21 Nov 2016 18:53:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 21.11.2016 um 07:21 schrieb Eric Auger: > Capability header next field is an offset relative to the start of > the INFO buffer. tmp->next is assigned the proper value but iterations > implemented in vfio_info_cap_add and vfio_info_cap_shift use next > as an offset between the headers. When coping with multiple capabilities > this leads to an Oops. > > Signed-off-by: Eric Auger > --- > drivers/vfio/vfio.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > index d1d70e0..1e838d1 100644 > --- a/drivers/vfio/vfio.c > +++ b/drivers/vfio/vfio.c > @@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, > header->version = version; > > /* Add to the end of the capability chain */ > - for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next) > + for (tmp = buf; tmp->next; tmp = buf + tmp->next) > ; /* nothing */ > Looks sane to me, tmp->next is always set to the old size, which corresponds to the offset from the start of the buffer. > tmp->next = caps->size; > @@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add); > void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset) > { > struct vfio_info_cap_header *tmp; > + void *buf = (void *)caps->buf; > > - for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) > + for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset) > tmp->next += offset; Reviewed-by: David Hildenbrand -- David