Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1013638iob; Fri, 13 May 2022 19:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAzIotwrCRe9ps35B99lRPte3TJ1Sz3GmIStpdcQSWa4Ei0LjNj1j6rJK2LHOz9D5YXalM X-Received: by 2002:a05:600c:c8:b0:395:a97c:c458 with SMTP id u8-20020a05600c00c800b00395a97cc458mr6939241wmm.119.1652495929632; Fri, 13 May 2022 19:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652495929; cv=none; d=google.com; s=arc-20160816; b=JTjJBh+bs1pmzmtv6uwt7Zgaw8rh89GzD/5lKb7SWGFUP5Ei9ca00xofGMO3vavDQt H1O8O4B30M47vKvZmX/8EjFSsf+eAzy3zmwvxJsbFL9ispzSEIfRQJhQMRZBXoEO4dP0 7zmCr+mSFLQQUk49ImlOyesPCEO8X1XnjZQBEiZv2IjXZWHExREAa6sjvTIdZjht4MH7 wRYxffLLTp0jc401uFOH5EeWXaClp3g4OQNbKVvycSWh1z3P1kwIIvnKAwZ0czUBMX27 jhE7DnBaAbNb4/seFcbzI7+U4C/dkxT5pkbkUidkCLOVmjyE/RC6r2bQS9D0iQqZLvYI 5xiw== 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=VJkNPzPQr/xDpbrda18CXpYkCA7d/rit6Nn2CeVPxyo=; b=A9MueH3bl5PUD6jNvyKr3z9s/t+rTUlXq8VuBfzx8/oGw7YFjwqXgGp+fgjqyaDpJQ grWsx2i3BrrCU2EQSgweRb5qWBB5Hz2BQzgbvhmsgdMApsFZnnTA7fxZQjkrhfuzQFC3 FBAevWJq2WUefCqTa9SYjuDeQAjCU85XUGI8ajJsj8cJPmMJCshGXe9WmLlms4fqz0YV IqxonQBBLddFWUg1p6TT7jH5HBAI32kYB9oXSEql/NxIjqNfg+rO2rE/Bu4dhfkPHWXx sww15mmT0tJTJylEQ/UdYf/N9kfpiqi/kxklAQbl7wJtDBktj5eGcVssZCRfH386Oha6 STgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PZ86+6+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t127-20020a1c4685000000b0038f20d955ebsi3488937wma.154.2022.05.13.19.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PZ86+6+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E9CB4FB405; Fri, 13 May 2022 17:50:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382158AbiEMPkM (ORCPT + 99 others); Fri, 13 May 2022 11:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382153AbiEMPkJ (ORCPT ); Fri, 13 May 2022 11:40:09 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A84B0FD0A for ; Fri, 13 May 2022 08:40:06 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24DEqLoJ038771; Fri, 13 May 2022 15:39:53 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=VJkNPzPQr/xDpbrda18CXpYkCA7d/rit6Nn2CeVPxyo=; b=PZ86+6+1tOfLwrSK//+kikGRtsfqr1bESKzcMyYD0i1scY4ErzNZPdWMw7SXk0ppvapd pfNAvrY5023dKKNJVw2Eeoqf7lFDKcBXxxzJOoHp0ZuC5xGgyRih4FwngeqxX7IHA/WX CV1ArVNQpnPg5ip9l7TVlg5D/eUHQpsMSIH7nXj5DjuOJNXTrW0N2TRBEpQwXXlakPxd ss6imUz0mnV3s8HpBDRXLb5lVzs776TbkBsmaWEmy1v6df97qOa8lhfbpoUWqM2PNpWn OhzUKlQWwbxqNnRd9i3+jT4+SV73ZJH8Gqi/Z+nYwrYAerSiSDOUdZFH5wB453sAS5dR eA== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g1sfh1365-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 15:39:53 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24DFPhuf024078; Fri, 13 May 2022 15:39:51 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3fwgd90v8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 15:39:50 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24DFQ7c143647434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 May 2022 15:26:07 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B221611C04C; Fri, 13 May 2022 15:39:48 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A63111C04A; Fri, 13 May 2022 15:39:48 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 13 May 2022 15:39:48 +0000 (GMT) From: Niklas Schnelle To: Joerg Roedel , Will Deacon Cc: Christoph Hellwig , Jason Gunthorpe , Robin Murphy , Matthew Rosato , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [PATCH] iommu/dma: Fix check for error return from iommu_map_sg_atomic() Date: Fri, 13 May 2022 17:39:48 +0200 Message-Id: <20220513153948.310119-1-schnelle@linux.ibm.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: wu5F4ZrMpZS-T-ZZMSg_cagycVwFvEs6 X-Proofpoint-ORIG-GUID: wu5F4ZrMpZS-T-ZZMSg_cagycVwFvEs6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-13_04,2022-05-13_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=895 priorityscore=1501 mlxscore=0 phishscore=0 clxscore=1011 malwarescore=0 spamscore=0 bulkscore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205130069 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org In __iommu_dma_alloc_noncontiguous() the value returned by iommu_map_sg_atomic() is checked for being smaller than size. Before commit ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped. After that commit iommu_map_sg_atomic() may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of type size_t while the return type of iommu_map_sg_atomic() is now of type ssize_t the latter gets converted to size_t and negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast to ssize_t. Fixes: ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()") Cc: stable@vger.kernel.org Signed-off-by: Niklas Schnelle --- drivers/iommu/dma-iommu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 09f6e1c0f9c0..b4fcf1d92994 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -776,6 +776,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev, unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap; struct page **pages; dma_addr_t iova; + ssize_t mapped; if (static_branch_unlikely(&iommu_deferred_attach_enabled) && iommu_deferred_attach(dev, domain)) @@ -813,8 +814,8 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev, arch_dma_prep_coherent(sg_page(sg), sg->length); } - if (iommu_map_sg_atomic(domain, iova, sgt->sgl, sgt->orig_nents, ioprot) - < size) + mapped = iommu_map_sg_atomic(domain, iova, sgt->sgl, sgt->orig_nents, ioprot); + if (mapped < (ssize_t)size) goto out_free_sg; sgt->sgl->dma_address = iova; -- 2.32.0