Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1683907pxj; Fri, 18 Jun 2021 12:35:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Tw8GAQewfJ+xwSvst7/vbIxPUkKXua+V1gRdKSP0OhUMiKLMCirQ83Ri5AROYZCeeQJG X-Received: by 2002:a05:6402:520b:: with SMTP id s11mr7136645edd.111.1624044921592; Fri, 18 Jun 2021 12:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044921; cv=none; d=google.com; s=arc-20160816; b=bRSfYnANEK85zZLvpPQCJPDgvaDqgHIqjLpeTZSLzIBNT8KaLeLnfRJNcP8yduT5qz Ram8gc3nR+sL/NLwtdCqZYgUPgMlypjtZbdrjFdscyc0XPe6dp0QWe07Q7xMIUnt1pJL TpvUXbSQSxyKtGCGBcV9CqDkjTHk+aEDPGJNBmOvWbWpJZyECTy60S7BVyV0xEzEv7K0 Z3N2gH1QFokOKznSc83a1l88xtE9Z32aH6+SNfDmUJN5Mj1lSy9ZngZusvA3Qcgibb4K SqntTwEt7AEG4UEQPa74EvVeNXby2JZ9KcXJ1mbEcKohy1GhFaJiWK80bnwWJ1vCo315 3S+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=LDeXJAMIrd7Bzszgl+66ueq612J8mydZvMkXyfHiR/c=; b=XmU5+DGZM2qw9rLh7fqNyMZkAougX5oh3cBz9uw+z7zIkrIiYav8jekEL6np0hSNac crMcvUfCT0th81/EpOdlSaqe/Ed7gwqcfBc1iW6huiL5XiPePnxxv6+zOgztCRPLQgp1 0mldmdMONP7K2ONe7vvRmyDDQJBXOKRDtMb6LiMIZrWfiiA3IdIO2uhltN24sNkvl44s BQkVKkheAcZjVJ2lYaxaki0jkVGIMp6m12F8duzRA3l2CmktLlQImZiD/OZJOcMSqjS0 npUTXm2xqYaKnmmUSxEYW3Ka0i2bmpvN+x8AOlto5T92fb3UvG4LZxaxK+/0UDNE9PF/ 5z0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=hVSrh+Jh; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si9620649edb.203.2021.06.18.12.34.59; Fri, 18 Jun 2021 12:35:21 -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=@ibm.com header.s=pp1 header.b=hVSrh+Jh; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233966AbhFRSNh (ORCPT + 99 others); Fri, 18 Jun 2021 14:13:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:12794 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbhFRSNh (ORCPT ); Fri, 18 Jun 2021 14:13:37 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15II2Yud118785; Fri, 18 Jun 2021 14:11:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=LDeXJAMIrd7Bzszgl+66ueq612J8mydZvMkXyfHiR/c=; b=hVSrh+Jht8KCJPKS3LnXXjyez+P+NqEzSEo4TGrZrVSso1gmK1wCxEQ6XfBg+s7j6qlk 0dDPbbvEbVaCnHgosefb4PfUA0vYQxor+Pm1cU/4vWxDf6qriDoF0QdSCfpwb/SLLWP/ p76DsN/MmtLh5Ro9bEL/tuMprsSzPBD7HSFxCsPV+F5+wzNl4sT/jL8kNbJvfKMD0TdH sb6S2IDWLT/oTDNuiV8gK56KWsVCSwTHYYOugyU1YTexh2BQuLCpjTAMyKds/Dp4ogYw dzlMoHXDXIp0wIJwnVioQvTcqQi+Zh+LqcfbrcEvFROOytXS8Z0f0dxBIrPIHFhQuADC UA== Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 398xtp2wbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Jun 2021 14:11:25 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15II8SsV001921; Fri, 18 Jun 2021 18:11:24 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 3980b9rfhw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Jun 2021 18:11:24 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15IIBNNI12518384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jun 2021 18:11:23 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4307AE060; Fri, 18 Jun 2021 18:11:23 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9295DAE05C; Fri, 18 Jun 2021 18:11:23 +0000 (GMT) Received: from cpe-172-100-179-72.stny.res.rr.com (unknown [9.85.128.252]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 18 Jun 2021 18:11:23 +0000 (GMT) Subject: Re: [PATCH v2] s390/vfio-ap: Fix module unload memory leak of matrix_dev To: "Jason J. Herne" , linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pasic@linux.ibm.com, jgg@nvidia.com References: <20210618171255.2025-1-jjherne@linux.ibm.com> From: Tony Krowiak Message-ID: Date: Fri, 18 Jun 2021 14:11:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210618171255.2025-1-jjherne@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: OGz9te48wsybWvLCzreZE7cm2VZGxwly X-Proofpoint-GUID: OGz9te48wsybWvLCzreZE7cm2VZGxwly X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-18_10:2021-06-18,2021-06-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 adultscore=0 suspectscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106180104 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/18/21 1:12 PM, Jason J. Herne wrote: > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with a NULL > pointer. Driver data for the matrix device is never set and so > dev_get_drvdata() always returns NULL. When release is called we end up > not freeing matrix_dev. The fix is to remove the shadow variable and get > the correct pointer from the device using container_of. We'll also NULL > the global to prevent any future use. > > Signed-off-by: Jason J. Herne > --- > drivers/s390/crypto/vfio_ap_drv.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c > index 7dc72cb718b0..40e66cb363d1 100644 > --- a/drivers/s390/crypto/vfio_ap_drv.c > +++ b/drivers/s390/crypto/vfio_ap_drv.c > @@ -82,9 +82,8 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev) > > static void vfio_ap_matrix_dev_release(struct device *dev) > { > - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); > - > - kfree(matrix_dev); > + kfree(container_of(dev, struct ap_matrix_dev, device)); I suppose if we're not going to assume that the release is being called to free the global matrix_dev, then if you are going to retrieve it using container_of(), then maybe we should verify the retrieved pointer is the same as the global matrix_dev? > + matrix_dev = NULL; > } > > static int matrix_bus_match(struct device *dev, struct device_driver *drv)