Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp431713imu; Tue, 27 Nov 2018 14:52:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/U2iY/mw0dC5efmzT2uuoAIUOCqfRdO0ec9TbnwNF/v74vUG9J+ViPg5/wQcN06nNoyZ/jo X-Received: by 2002:a63:604f:: with SMTP id u76mr28042377pgb.401.1543359166799; Tue, 27 Nov 2018 14:52:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543359166; cv=none; d=google.com; s=arc-20160816; b=yk2GkVIpqhpztXwgaPGC7rFgs9lnJ6o8Naz+XZaThyb2oEaJD8r5piKTm1mv+8h4c/ BRH/0CTtzC6cB5Hifrw9dGm9ni3RkioS2jzuJzeOp2qIkSQRfstcIbydG/C/+QEXnYQz SR02IoUepq40rN8FPrSJdhUN8VG1ePSD1vnLH7vITgabGhF2m3hUism2CaW5h22YDw4E 9nCJpiA6S5c8KkHb4hzTGWeS6PFxGSxE6hlWF427J46w3YgQ9+rlkdJdVKWgBrmnPY35 I7diqo4TiEMzQz4kpgOjYM1MCYjdyiQR4c5Gkvw/Ch/bewvYZNPRE2glqpRh0oqMzh5y rUVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=LvQlih+XsNfr/zaQsJbJUbFklRROtBgGaFjCqPNwIps=; b=xhepkx50lODfPP1rieUbFTRLVFU4tEPleZGlSQdENiCSiScdekbBs79+8vmz2GVZvq Ab15+KB2hDTeeo8OGimkZIFORG/urQseqMfObDm9R/17Lk2NbOOxvM1mhCBVcOjcZRYl qBHVf25lQ52sN31eaR1cKs+7mP1vrJENuLCsZDtQGC2E6KxlNzAmqFT3AloXAJ2EEaTB ZG+WkGC1AUX4I/SNT/FhgA4dfAItIsijWIWUgOy8+21n83cFNtY0CsQ+4Ns93isJSlO4 zar/UUJW8wI4fssx2bNrwbm46enlVYjXohYQoBKJNvJzBJv4X7KuvT8ZFnqpiYKEAiTu QaDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fQoW4lE9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb2si5801578plb.298.2018.11.27.14.52.32; Tue, 27 Nov 2018 14:52:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fQoW4lE9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726457AbeK1JvL (ORCPT + 99 others); Wed, 28 Nov 2018 04:51:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:41620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbeK1JvK (ORCPT ); Wed, 28 Nov 2018 04:51:10 -0500 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB6B120873; Tue, 27 Nov 2018 22:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543359105; bh=7ks0Z5a4qG0YPKLmL7FSHpy6vSPf16HXs/hKveqSqkc=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=fQoW4lE99X61DGhmCOKkVMg/xvx9+nGvubQUGKmxuGVBQsAwadW+QzcSzv7/Dgi6p KJgc6QqITLd/1jAkQuK6iIjGZ3iuXSTe1s0B72V65pUaKglFhL1JZL7Yi4HM39DNel b+pihFX9GcidOHZJXhqgWnJzpRtywbndqWiolgwc= Date: Tue, 27 Nov 2018 14:51:42 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: Boris Ostrovsky cc: Stefano Stabellini , PanBian , Juergen Gross , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [Xen-devel] [PATCH] pvcalls-front: fixes incorrect error handling In-Reply-To: Message-ID: References: <1542852432-30019-1-git-send-email-bianpan2016@163.com> <1f765e81-ed89-d110-74b1-cc8029a4555f@oracle.com> <20181127005823.GB125510@bp> <0af126ad-1a74-e4c7-d74f-658a46757b9d@oracle.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Nov 2018, Boris Ostrovsky wrote: > On 11/27/18 4:08 PM, Stefano Stabellini wrote: > > On Tue, 27 Nov 2018, Boris Ostrovsky wrote: > >> On 11/27/18 3:37 PM, Stefano Stabellini wrote: > >>> On Tue, 27 Nov 2018, PanBian wrote: > >>>> On Mon, Nov 26, 2018 at 03:31:39PM -0500, Boris Ostrovsky wrote: > >>>>> On 11/21/18 9:07 PM, Pan Bian wrote: > >>>>>> kfree() is incorrectly used to release the pages allocated by > >>>>>> __get_free_page() and __get_free_pages(). Use the matching deallocators > >>>>>> i.e., free_page() and free_pages(), respectively. > >>>>>> > >>>>>> Signed-off-by: Pan Bian > >>>>>> --- > >>>>>> drivers/xen/pvcalls-front.c | 4 ++-- > >>>>>> 1 file changed, 2 insertions(+), 2 deletions(-) > >>>>>> > >>>>>> diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c > >>>>>> index 2f11ca7..77224d8 100644 > >>>>>> --- a/drivers/xen/pvcalls-front.c > >>>>>> +++ b/drivers/xen/pvcalls-front.c > >>>>>> @@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn) > >>>>>> out_error: > >>>>>> if (*evtchn >= 0) > >>>>>> xenbus_free_evtchn(pvcalls_front_dev, *evtchn); > >>>>>> - kfree(map->active.data.in); > >>>>>> - kfree(map->active.ring); > >>>>>> + free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER); > >>>>> Is map->active.data.in guaranteed to be NULL when entering this routine? > >>>> I am not sure yet. Sorry for that. I observed the mismatches between > >>>> __get_free_page and kfree, and submitted the patch. > >>>> > >>>> But I think your consideration is reasonable. A better solution is to > >>>> directly free bytes, a local variable that holds __get_free_pages return > >>>> value. If you agree, I will rewrite the patch. > >>> Like Boris said, map->active.ring and map->active.data.in are not > >>> guaranteed to be NULL or != NULL here. For instance,map->active.ring can > >>> be != NULL and map->active.data.in can be NULL. However, free_pages and > >>> free_page should be able to cope with it, the same way that kfree is > >>> able to cope with it? > >> If map->active.data.in can be non-NULL on entry to this routine then I > >> think this has been a problem all along. Pan's suggestion to use bytes > >> for freeing is going to solve this (assuming bytes will be initialized > >> to NULL). > > Why is it a problem? map->active.data.in and map->active.ring are only > > != NULL if they need to be freed. Otherwise, they are NULL. > > That was my question --- I wasn't sure about it, and I read your > previous message as if it was possible to be calling create_active() > with map->active.data.in pointing somewhere non-NULL. > > If it is NULL *upon entry* to calling_create() then Pan's original patch > is fine. Right, I think it is fine too. Reviewed-by: Stefano Stabellini > > All structs > > are always initialized to zero. I don't think there are any issues. >