Message ID | 20230315153932.165031-1-akrowiak@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2406897wrd; Wed, 15 Mar 2023 08:55:11 -0700 (PDT) X-Google-Smtp-Source: AK7set8ErYAtbHKNbg6mb5S0iZgVcSiJui9YK9p6vPoEmWGf5lc/BwconCGXlX+wM69u9uxydKnG X-Received: by 2002:a05:6a20:4412:b0:d5:e107:bd19 with SMTP id ce18-20020a056a20441200b000d5e107bd19mr311097pzb.31.1678895711469; Wed, 15 Mar 2023 08:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678895711; cv=none; d=google.com; s=arc-20160816; b=wGZhJxBr/y1e21XMeDe52X04oOgSZvpK+6HHtWKzJE+1p1wCG5vPdj4g8oMeZ1p144 yAVJbrD4RE2B5MwjnmwTwpQEeg9a5v7qFS8sYEZ6WeFL6QJUIq9Wo7xS8VwlCIjPFIcK baDsaJ/E2/yrx37l04fhnXenBLGrXRhHCVEELinZeSrV8Y943+2doK9DNXA+KtxLHT6t eST7mxedti47SqYybSatCD7KtuVN4gfxytACU+lLImKPrLgIN/6OYtCyBLrsrvTYildC QsHpD3hQOGgBMBE6fmt7IKS/Ow0jKGHzz28JyQntE35mZLQ89T7gkqPy81flkcRSOkRB mGZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3xUWNiOWu0OLHScxxfQ9Ow098huewhYupa4YwoKoKMs=; b=M5c2EG7ZiEjks/O9YXQLk3JkeCuXvDoOxOerbSixktjnZcODRtz+7xQFOiklEzP5WN v6ZtJVvY8560yajQXU1fUio6tbLfXyalqRH1QS2/TG61nuOgPsLbKP2gqzOdQ85C1bw3 C4Ytbp3RMF4jfNhKWoHBM8I6KTYqxVK0jh/+bb35zRMtm+jZVxMtujGnndhd61VIb7Im ACG++sdzqf+BhGKdIPytkbMeOUkenFZsINFyij1kLE1bcXamegb0pO5G7rKq3d9lKxf4 BUBeBgjoywe2sNJSS30GmaM8S5k78GzXrj9yG7ld4yVeLQ9l9xQ0OXviN/Fyt8D50zvb pW/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qiB1RGj1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k189-20020a6384c6000000b0050beaf431a2si19357pgd.337.2023.03.15.08.54.56; Wed, 15 Mar 2023 08:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qiB1RGj1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjCOPjq (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Wed, 15 Mar 2023 11:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbjCOPjj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Mar 2023 11:39:39 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E9ED11679; Wed, 15 Mar 2023 08:39:37 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32FFCTt1032675; Wed, 15 Mar 2023 15:39:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=3xUWNiOWu0OLHScxxfQ9Ow098huewhYupa4YwoKoKMs=; b=qiB1RGj1beJvEwGvCBA77XIVtjAXN2ZOHiECO8vNp7YcxMmU2+EPjgi0qYIAIMjZiTX7 GpsrudCT2o/DoiH/raQBWKwbEYK4XBFezRfT+pyrCp/nWlh2LgPO/ZSeaCefA/epRjQU Caj8YEW2w8mgq4SD1v1AaGpW7WYy5xUdBtwxWqxHcQXNM8BC9o1YouPylwQhdDWYpTUK UR4eeL+Zu2Kfg8iYAQfKJo82Kj4GnFnLrPoSff8mVVBvmnbiRPLgK/UmJnRbGF0E8bZi hAFNr473kjFav4tBNwFV7o0/YqvE4qucphF7iNyVDWJCl0nHp7/ZdQMrwv+oKAmNG8WC 6w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pbgey0u34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Mar 2023 15:39:36 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32FFCjY9000979; Wed, 15 Mar 2023 15:39:36 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pbgey0u2s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Mar 2023 15:39:36 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32FE65hT024417; Wed, 15 Mar 2023 15:39:35 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([9.208.129.117]) by ppma02dal.us.ibm.com (PPS) with ESMTPS id 3pb29rcym2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Mar 2023 15:39:35 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32FFdXc718940590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Mar 2023 15:39:33 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2325258057; Wed, 15 Mar 2023 15:39:33 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96E1758059; Wed, 15 Mar 2023 15:39:32 +0000 (GMT) Received: from li-2c1e724c-2c76-11b2-a85c-ae42eaf3cb3d.endicott.ibm.com (unknown [9.60.85.43]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Mar 2023 15:39:32 +0000 (GMT) From: Tony Krowiak <akrowiak@linux.ibm.com> To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jjherne@linux.ibm.com, pasic@linux.ibm.com, alex.williamson@redhat.com, borntraeger@linux.ibm.com Subject: [PATCH] s390/vfio_ap: fix memory leak in vfio_ap device driver Date: Wed, 15 Mar 2023 11:39:32 -0400 Message-Id: <20230315153932.165031-1-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: AA4axdwSoKQ9Zy6Def57-tSYAB1ZZcez X-Proofpoint-ORIG-GUID: L0VakZDhgEUIrW0zeLH_ZwqmdC82nQc3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-15_08,2023-03-15_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1011 malwarescore=0 impostorscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2302240000 definitions=main-2303150131 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760449749757277707?= X-GMAIL-MSGID: =?utf-8?q?1760449749757277707?= |
Series |
s390/vfio_ap: fix memory leak in vfio_ap device driver
|
|
Commit Message
Anthony Krowiak
March 15, 2023, 3:39 p.m. UTC
The device release callback function invoked to release the matrix device
uses the dev_get_drvdata(device *dev) function to retrieve the
pointer to the vfio_matrix_dev object in order to free its storage. The
problem is, this object is not stored as drvdata with the device; since the
kfree function will accept a NULL pointer, the memory for the
vfio_matrix_dev object is never freed.
Since the device being released is contained within the vfio_matrix_dev
object, the container_of macro will be used to retrieve its pointer.
Fixes: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver")
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_drv.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On 2023-03-15 16:39, Tony Krowiak wrote: > The device release callback function invoked to release the matrix > device > uses the dev_get_drvdata(device *dev) function to retrieve the > pointer to the vfio_matrix_dev object in order to free its storage. The > problem is, this object is not stored as drvdata with the device; since > the > kfree function will accept a NULL pointer, the memory for the > vfio_matrix_dev object is never freed. > > Since the device being released is contained within the vfio_matrix_dev > object, the container_of macro will be used to retrieve its pointer. > > Fixes: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP > device driver") > Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> > --- > drivers/s390/crypto/vfio_ap_drv.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/s390/crypto/vfio_ap_drv.c > b/drivers/s390/crypto/vfio_ap_drv.c > index 997b524bdd2b..15e9de9f4574 100644 > --- a/drivers/s390/crypto/vfio_ap_drv.c > +++ b/drivers/s390/crypto/vfio_ap_drv.c > @@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = { > > static void vfio_ap_matrix_dev_release(struct device *dev) > { > - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); > - > + struct ap_matrix_dev *matrix_dev = container_of(dev, > + struct ap_matrix_dev, > + device); > kfree(matrix_dev); > } I needed some indirections to follow what exactly happens here and how you fix it, but finally I got it. Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
snip ... > I needed some indirections to follow what exactly happens here and how > you > fix it, but finally I got it. > Reviewed-by: Harald Freudenberger <freude@linux.ibm.com> Sorry about the indirections. Thanks for the review.
On Wed, Mar 15, 2023 at 11:39:32AM -0400, Tony Krowiak wrote: > The device release callback function invoked to release the matrix device > uses the dev_get_drvdata(device *dev) function to retrieve the > pointer to the vfio_matrix_dev object in order to free its storage. The > problem is, this object is not stored as drvdata with the device; since the > kfree function will accept a NULL pointer, the memory for the > vfio_matrix_dev object is never freed. > > Since the device being released is contained within the vfio_matrix_dev > object, the container_of macro will be used to retrieve its pointer. > > Fixes: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver") > Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> > --- > drivers/s390/crypto/vfio_ap_drv.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c > index 997b524bdd2b..15e9de9f4574 100644 > --- a/drivers/s390/crypto/vfio_ap_drv.c > +++ b/drivers/s390/crypto/vfio_ap_drv.c > @@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = { > > static void vfio_ap_matrix_dev_release(struct device *dev) > { > - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); > - > + struct ap_matrix_dev *matrix_dev = container_of(dev, > + struct ap_matrix_dev, > + device); > kfree(matrix_dev); Could you keep this code more readable, including adding the missing blank line after the declaration, please? Something like: static void vfio_ap_matrix_dev_release(struct device *dev) { struct ap_matrix_dev *matrix_dev; matrix_dev = container_of(dev, struct ap_matrix_dev, device); kfree(matrix_dev); } Thanks!
On 3/16/23 4:39 AM, Heiko Carstens wrote: > On Wed, Mar 15, 2023 at 11:39:32AM -0400, Tony Krowiak wrote: >> The device release callback function invoked to release the matrix device >> uses the dev_get_drvdata(device *dev) function to retrieve the >> pointer to the vfio_matrix_dev object in order to free its storage. The >> problem is, this object is not stored as drvdata with the device; since the >> kfree function will accept a NULL pointer, the memory for the >> vfio_matrix_dev object is never freed. >> >> Since the device being released is contained within the vfio_matrix_dev >> object, the container_of macro will be used to retrieve its pointer. >> >> Fixes: 1fde573413b5 ("s390: vfio-ap: base implementation of VFIO AP device driver") >> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> >> --- >> drivers/s390/crypto/vfio_ap_drv.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c >> index 997b524bdd2b..15e9de9f4574 100644 >> --- a/drivers/s390/crypto/vfio_ap_drv.c >> +++ b/drivers/s390/crypto/vfio_ap_drv.c >> @@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = { >> >> static void vfio_ap_matrix_dev_release(struct device *dev) >> { >> - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); >> - >> + struct ap_matrix_dev *matrix_dev = container_of(dev, >> + struct ap_matrix_dev, >> + device); >> kfree(matrix_dev); > Could you keep this code more readable, including adding the missing > blank line after the declaration, please? Something like: > > static void vfio_ap_matrix_dev_release(struct device *dev) > { > struct ap_matrix_dev *matrix_dev; > > matrix_dev = container_of(dev, struct ap_matrix_dev, device); > kfree(matrix_dev); > } > > Thanks! Will do.
diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c index 997b524bdd2b..15e9de9f4574 100644 --- a/drivers/s390/crypto/vfio_ap_drv.c +++ b/drivers/s390/crypto/vfio_ap_drv.c @@ -54,8 +54,9 @@ static struct ap_driver vfio_ap_drv = { static void vfio_ap_matrix_dev_release(struct device *dev) { - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); - + struct ap_matrix_dev *matrix_dev = container_of(dev, + struct ap_matrix_dev, + device); kfree(matrix_dev); }