Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1621946ybk; Sun, 10 May 2020 23:39:57 -0700 (PDT) X-Google-Smtp-Source: APiQypI6O1oZbS1uSwtRvMoZ2TabCFgcWoJ/8r0VdGIJ5zBbA2jmdZDUgclNwgm/uEjJXNhHhOS6 X-Received: by 2002:a17:906:a3d1:: with SMTP id ca17mr5999365ejb.174.1589179197503; Sun, 10 May 2020 23:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589179197; cv=none; d=google.com; s=arc-20160816; b=tcXWRqb6Sd1of9tjUZH+ob0GNTWbJ3kiR64Qouedot1+fADUn4GII4vBC6LoTqWwF6 6bYsOKikCKUVqwa/tpNANKd9YvCO0nkkUoTmnQJI0hjdn1be2+h031ATUjHuW8/30U3H brCf3uSJY5/YNOKoFeAFgU8J4xxrW/BgPOpCmvzNLes3T9CUlqo2Z9CQlddnanrmzkRH heRhVtBeufOepWH+v7bnjm4MYl8WbIJF/xbzO8rkXmU/rrheOKWJt8dPRyxw5mjxdinf HYK67+0DNiD4i4jmw+Zvg1ZDaxKH7naMwM39rvo85Z9Ut4WSn0BkRgP6Ig1WAj6hinOC US9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=ncGeH5ZKVwCdh5E0XvEmoml51kA2FhsNgAa3Rpsy93w=; b=MoLeH/rwrIaqTrwZFpySCXolCdID80B7UH0qi/D8+hYNQgTUJpV/p7KirTeJrAOrQx ursgsmltOP2QkTPt6jhsD/bIKR2lZCBaFEML/bteN9tSIIDbjRiLeduOHXLQniG0P35B DO7IcCrvMXFIb8Fv9SN8/pKuDx/SEBAKONlLqo0Nvp6dm4mEP0XGVVWFJ4BHSd5eObzD kCdiLuhwkNfFMZMBTfF8ZuAckuPAwy9k6SiU2HlIpNtNzTwgjLyFnGpq2CDeLAvniK0/ JVuM7262Z7enqs7yKlSxHnuwd+3T45WMTJtqfphcLMWSIiNodZFYCSrpYgadehMfULXV 9zlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d+drW+dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si5241905eja.257.2020.05.10.23.39.34; Sun, 10 May 2020 23:39:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d+drW+dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726934AbgEKGg3 (ORCPT + 99 others); Mon, 11 May 2020 02:36:29 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39324 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725790AbgEKGg3 (ORCPT ); Mon, 11 May 2020 02:36:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589178987; 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=ncGeH5ZKVwCdh5E0XvEmoml51kA2FhsNgAa3Rpsy93w=; b=d+drW+dY+a0K2rgzwHtSX9KWbgWJgLtU2cLs2a+yZMq/aqIIDxyK3ZN0tN9XKX/y3oJjQh 3EKhWhvv6OnhSwgMWjExnQUjO31UL/rGs8tppJC6oohQXdvrlLVcGeWAFjEXn6wdIkXW10 BTbaDDexlt1nHdRgAUSYDV3Om4I4ra8= 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-350-HiHDwdZgPKaiPonLkIwVrA-1; Mon, 11 May 2020 02:35:55 -0400 X-MC-Unique: HiHDwdZgPKaiPonLkIwVrA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE07F107ACCA; Mon, 11 May 2020 06:35:54 +0000 (UTC) Received: from gondolin (ovpn-112-254.ams2.redhat.com [10.36.112.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD81360CD1; Mon, 11 May 2020 06:35:50 +0000 (UTC) Date: Mon, 11 May 2020 08:35:47 +0200 From: Cornelia Huck To: Qian Cai Cc: alex.williamson@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio/pci: fix memory leaks in alloc_perm_bits() Message-ID: <20200511083547.24718bcc.cohuck@redhat.com> In-Reply-To: <20200510161656.1415-1-cai@lca.pw> References: <20200510161656.1415-1-cai@lca.pw> Organization: Red Hat GmbH 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.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 10 May 2020 12:16:56 -0400 Qian Cai wrote: > vfio_pci_disable() calls vfio_config_free() but forgets to call > free_perm_bits() resulting in memory leaks, > > unreferenced object 0xc000000c4db2dee0 (size 16): > comm "qemu-kvm", pid 4305, jiffies 4295020272 (age 3463.780s) > hex dump (first 16 bytes): > 00 00 ff 00 ff ff ff ff ff ff ff ff ff ff 00 00 ................ > backtrace: > [<00000000a6a4552d>] alloc_perm_bits+0x58/0xe0 [vfio_pci] > [<00000000ac990549>] vfio_config_init+0xdf0/0x11b0 [vfio_pci] > init_pci_cap_msi_perm at drivers/vfio/pci/vfio_pci_config.c:1125 > (inlined by) vfio_msi_cap_len at drivers/vfio/pci/vfio_pci_config.c:1180 > (inlined by) vfio_cap_len at drivers/vfio/pci/vfio_pci_config.c:1241 > (inlined by) vfio_cap_init at drivers/vfio/pci/vfio_pci_config.c:1468 > (inlined by) vfio_config_init at drivers/vfio/pci/vfio_pci_config.c:1707 > [<000000006db873a1>] vfio_pci_open+0x234/0x700 [vfio_pci] > [<00000000630e1906>] vfio_group_fops_unl_ioctl+0x8e0/0xb84 [vfio] > [<000000009e34c54f>] ksys_ioctl+0xd8/0x130 > [<000000006577923d>] sys_ioctl+0x28/0x40 > [<000000006d7b1cf2>] system_call_exception+0x114/0x1e0 > [<0000000008ea7dd5>] system_call_common+0xf0/0x278 > unreferenced object 0xc000000c4db2e330 (size 16): > comm "qemu-kvm", pid 4305, jiffies 4295020272 (age 3463.780s) > hex dump (first 16 bytes): > 00 ff ff 00 ff ff ff ff ff ff ff ff ff ff 00 00 ................ > backtrace: > [<000000004c71914f>] alloc_perm_bits+0x44/0xe0 [vfio_pci] > [<00000000ac990549>] vfio_config_init+0xdf0/0x11b0 [vfio_pci] > [<000000006db873a1>] vfio_pci_open+0x234/0x700 [vfio_pci] > [<00000000630e1906>] vfio_group_fops_unl_ioctl+0x8e0/0xb84 [vfio] > [<000000009e34c54f>] ksys_ioctl+0xd8/0x130 > [<000000006577923d>] sys_ioctl+0x28/0x40 > [<000000006d7b1cf2>] system_call_exception+0x114/0x1e0 > [<0000000008ea7dd5>] system_call_common+0xf0/0x278 > > Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver") > Signed-off-by: Qian Cai > --- > drivers/vfio/pci/vfio_pci_config.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c > index 90c0b80f8acf..f9fdc72a5f4e 100644 > --- a/drivers/vfio/pci/vfio_pci_config.c > +++ b/drivers/vfio/pci/vfio_pci_config.c > @@ -1728,6 +1728,7 @@ void vfio_config_free(struct vfio_pci_device *vdev) > vdev->vconfig = NULL; > kfree(vdev->pci_config_map); > vdev->pci_config_map = NULL; > + free_perm_bits(vdev->msi_perm); > kfree(vdev->msi_perm); > vdev->msi_perm = NULL; > } Seems to be the only perm bits that were missed. Reviewed-by: Cornelia Huck