From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 873BBC43460 for ; Tue, 18 May 2021 21:46:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C92D60FF3 for ; Tue, 18 May 2021 21:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352608AbhERVsQ (ORCPT ); Tue, 18 May 2021 17:48:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54660 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236298AbhERVsQ (ORCPT ); Tue, 18 May 2021 17:48:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621374417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FuWvlQIHVtiLs5PcrSK5tHyRzGUj0cP2/B1i7ADxOx4=; b=brydax1kmvY9U9u9aJPf5KQJ4vNHLzkdzKqZr7EAznMTOx5WybeQ3/mjmkJPEPer3B8WFB oJnpMeEamxXGKtH1fRuTWC/DVuERK/3vliql+ezDdSymk4yrIiuKGbxYzPOoSnniyWYk8w A7LNza704PswBBDvwIS6aliydIVvqyg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-7fhLPdPRPAaQAtUZ5nyfNA-1; Tue, 18 May 2021 17:46:55 -0400 X-MC-Unique: 7fhLPdPRPAaQAtUZ5nyfNA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 466A88186E1; Tue, 18 May 2021 21:46:54 +0000 (UTC) Received: from redhat.com (ovpn-113-225.phx2.redhat.com [10.3.113.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FF2960877; Tue, 18 May 2021 21:46:47 +0000 (UTC) Date: Tue, 18 May 2021 15:46:47 -0600 From: Alex Williamson To: Yang Yingliang Cc: , , Subject: Re: [PATCH -next] vfio: platform: reset: add missing iounmap() on error in vfio_platform_amdxgbe_reset() Message-ID: <20210518154647.6541bac2.alex.williamson@redhat.com> In-Reply-To: <20210513050924.627625-1-yangyingliang@huawei.com> References: <20210513050924.627625-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 May 2021 13:09:24 +0800 Yang Yingliang wrote: > Add the missing iounmap() before return from vfio_platform_amdxgbe_reset() > in the error handling case. > > Fixes: 0990822c9866 ("VFIO: platform: reset: AMD xgbe reset module") > Reported-by: Hulk Robot > Signed-off-by: Yang Yingliang > --- > drivers/vfio/platform/reset/vfio_platform_amdxgbe.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c b/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c > index abdca900802d..c6d823a27bd6 100644 > --- a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c > +++ b/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c > @@ -61,8 +61,10 @@ static int vfio_platform_amdxgbe_reset(struct vfio_platform_device *vdev) > if (!xpcs_regs->ioaddr) { > xpcs_regs->ioaddr = > ioremap(xpcs_regs->addr, xpcs_regs->size); > - if (!xpcs_regs->ioaddr) > + if (!xpcs_regs->ioaddr) { > + iounmap(xgmac_regs->ioaddr); > return -ENOMEM; > + } > } > > /* reset the PHY through MDIO*/ This actually introduces multiple bugs. vfio-platform has common code for calling iounmap when the device is released and the struct vfio_platform_region ioaddr member is re-used throughout the code. Performing an iounmap() without setting the value to NULL essentially introduces use-after-free and double free bugs. There's no bug in the original afaict, the iounmap occurs lazily on release. Thanks, Alex