Received: by 10.213.65.68 with SMTP id h4csp892249imn; Tue, 20 Mar 2018 19:10:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELts0JFMdNlhyW8NT28tQSvQPHJWtRQ5aBkkQiJT9Km1AxRyDbGYfYn89/67sCwKrI2L/s7M X-Received: by 2002:a17:902:9009:: with SMTP id a9-v6mr18393262plp.272.1521598244734; Tue, 20 Mar 2018 19:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521598244; cv=none; d=google.com; s=arc-20160816; b=kkOBTZ5i+9kwJQ2tPY0//JV9BK3ohnxdSzrslrmP00goNiKn/7vnoXmdry5UE2B5QZ fwjM+ZHcF/FOQfqvRPj5cjr01qgsk1ybXuDY2RWPYDSSkQhWxeyBYkZus8YvOp+slcuh 5n2JBGoUzigtkP+YFMesCcUNsWZcZYXxcz4pkpZmYcOE1TXk2mQum8WOVdJbjRKEtjje lfkhIGOMYG2TormUL6QmFoTLd6ck67ObJgCrhHnUC/SGb4EWkf05ydzhox9bENJPPaz3 ro6KWp11MN9BqTxHzhJRn35kKUookEhxTNtYOsybDaSL1lSovCJb+hlz7aAcsOC6CZha RD0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=DqH0L6JyEETxYlShMJkYjjmCYAolAzcPD4gXR3MKDQk=; b=hw+kpx2qoc06pHwOIZEq9K5ZNOHd6OCbs2PfqiCa/tM7Rxw6mnD4KeNVry5yH0evet xFffWZHuruWFmzC1Awm2DXUolqK6QZM1AFy76Q1Yq9wflcuTlh7qsN8elgaiWWiPNo0A jwrdriGxe5xEHbQbCQlVbiDLRCI5noVxYByPZkJWjwl6Rz9kONlJFyVTo9iKRef6B4Vn n6tAR+TGBNm+wiRZ8DfqJesVeLVGneFYNmkMs7cDiDTyQ6lkg8aweJ7DvvjC8M3aflG4 WrzqIqjWQOD2QAvnlOrF5lJ8/2O4k4Rd3hYwZlZm62pny6gu80i191baLLyK/zWpH1Lb 3KpQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si2851419plz.360.2018.03.20.19.10.31; Tue, 20 Mar 2018 19:10:44 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751978AbeCUCJS (ORCPT + 99 others); Tue, 20 Mar 2018 22:09:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40260 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751788AbeCUCIi (ORCPT ); Tue, 20 Mar 2018 22:08:38 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2L25mwM068922 for ; Tue, 20 Mar 2018 22:08:37 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gu98ysq3s-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 20 Mar 2018 22:08:37 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Mar 2018 20:08:36 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Mar 2018 20:08:34 -0600 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2L28YVW10092930; Tue, 20 Mar 2018 19:08:34 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EEB456A03F; Tue, 20 Mar 2018 20:08:33 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 888F96A03B; Tue, 20 Mar 2018 20:08:32 -0600 (MDT) From: Dong Jia Shi To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org Cc: cohuck@redhat.com, borntraeger@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com Subject: [PATCH 3/4] vfio: ccw: set ccw->cda to NULL defensively Date: Wed, 21 Mar 2018 03:08:21 +0100 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180321020822.86255-1-bjsdjshi@linux.vnet.ibm.com> References: <20180321020822.86255-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18032102-0008-0000-0000-0000097C4BFB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008713; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.01006058; UDB=6.00512229; IPR=6.00785341; MB=3.00020153; MTD=3.00000008; XFM=3.00000015; UTC=2018-03-21 02:08:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032102-0009-0000-0000-0000467954FF Message-Id: <20180321020822.86255-4-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-21_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803210024 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's avoid free on ccw->cda that points to a guest address or a already freed memory area by setting it to NULL if memory allocation didn't happen or failed. Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_cp.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 3abc9770910a..5958c35ab343 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -491,7 +491,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, struct ccw1 *ccw; struct pfn_array_table *pat; unsigned long *idaws; - int idaw_nr; + int idaw_nr, ret; ccw = chain->ch_ccw + idx; @@ -511,18 +511,20 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, * needed when translating a direct ccw to a idal ccw. */ pat = chain->ch_pat + idx; - if (pfn_array_table_init(pat, 1)) - return -ENOMEM; - idaw_nr = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, + ret = pfn_array_table_init(pat, 1); + if (ret) + goto out_init; + + idaw_nr = ret = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, ccw->cda, ccw->count); - if (idaw_nr < 0) - return idaw_nr; + if (ret < 0) + goto out_init; /* Translate this direct ccw to a idal ccw. */ idaws = kcalloc(idaw_nr, sizeof(*idaws), GFP_DMA | GFP_KERNEL); if (!idaws) { - pfn_array_table_unpin_free(pat, cp->mdev); - return -ENOMEM; + ret = -ENOMEM; + goto out_unpin; } ccw->cda = (__u32) virt_to_phys(idaws); ccw->flags |= CCW_FLAG_IDA; @@ -530,6 +532,12 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, pfn_array_table_idal_create_words(pat, idaws); return 0; + +out_unpin: + pfn_array_table_unpin_free(pat, cp->mdev); +out_init: + ccw->cda = 0; + return ret; } static int ccwchain_fetch_idal(struct ccwchain *chain, @@ -559,7 +567,7 @@ static int ccwchain_fetch_idal(struct ccwchain *chain, pat = chain->ch_pat + idx; ret = pfn_array_table_init(pat, idaw_nr); if (ret) - return ret; + goto out_init; /* Translate idal ccw to use new allocated idaws. */ idaws = kzalloc(idaw_len, GFP_DMA | GFP_KERNEL); @@ -591,6 +599,8 @@ static int ccwchain_fetch_idal(struct ccwchain *chain, kfree(idaws); out_unpin: pfn_array_table_unpin_free(pat, cp->mdev); +out_init: + ccw->cda = 0; return ret; } -- 2.13.5