From patchwork Fri Dec 23 07:24:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 36150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp187471wrn; Thu, 22 Dec 2022 23:33:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvEUDx6nSlV1WO4GNIxt63BEmvpsyFBVwBbBBX+DgJsYeh1hBkTkR0FSMtBAELqfQWRhI1d X-Received: by 2002:aa7:9f90:0:b0:578:795e:c8d3 with SMTP id z16-20020aa79f90000000b00578795ec8d3mr10139096pfr.29.1671780796919; Thu, 22 Dec 2022 23:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671780796; cv=none; d=google.com; s=arc-20160816; b=eEhx8eleGV7aQ44aONCljZyD/L9LJjEjY4qdsLHkn1pGLHQWMmQOP3dIhxO9DqaLp5 ZDlWxI2yJE6L7kuW8LoFUzEooTFSK+XilJds3mHuAs0U3dIwHaom3FYVg1mBwEkJxtfC M3n9RgKaXm0H5V9KleyI0Zyp4BZi2F0/mhm73VK4+6Iprs0V+wTuWE5iVHbN5JBqOvmc 2WQMcKKLad/Ul8CJcn1zjklad1UY4zQIpGBoJYCz4hsJQirrKcHdJQp34eHBmd4pNibo dHgOz5BLqDnIJTn+gvHEvNADZu5GucKRZFTY2aG6vq2nsduRgK+eqEoMsAGBPFjvcdKJ +7KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=7H8Rm6on5tXoDip890AbA5Bve60H1pGugqmW3rlMSSY=; b=G6oBH+JIGdXxZ7rmE0/IQRctEI2AGBGTk+O7JMafaVk9ZU+V+CQpCEH1b3s/q9ZAzM vak1JgtLljYfLf+pcSgIawBYxRKDMTXsRyrvWm38rSxHMt7H+elFJ8zeILUL1Qi8W80W 8Ha1kwcH8rO7UEWt0BZhsMMg9wIZYIfFwJR79wJtvjnfUTn+jLZezmZyG8ia4535Zjzk sQ8Qqa/0TMSAwBwaHlj89shHBN+MhwIaDFl+uxgRlzGw5dZK2nmCTP8/O0GdUvFpZGk/ i50Jv/5aC0hypHb5EOu3Kse46yyCoBUi76kfdp32M4ElGZS79bWxAcBjHr+S7qYBn+rH z69w== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v2-20020a056a00148200b005769b34452fsi3118198pfu.203.2022.12.22.23.33.00; Thu, 22 Dec 2022 23:33:16 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbiLWHYb (ORCPT + 99 others); Fri, 23 Dec 2022 02:24:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbiLWHY2 (ORCPT ); Fri, 23 Dec 2022 02:24:28 -0500 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CBB92658A; Thu, 22 Dec 2022 23:24:27 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 785B51E80DA0; Fri, 23 Dec 2022 15:19:16 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FMh5p-cEkS2V; Fri, 23 Dec 2022 15:19:13 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 419D41E80D96; Fri, 23 Dec 2022 15:19:13 +0800 (CST) From: Li kunyu To: alex.williamson@redhat.com, cohuck@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] vfio_iommu_type1: increase the validity check of function parameters Date: Fri, 23 Dec 2022 15:24:18 +0800 Message-Id: <20221223072418.3728-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752989220495002119?= X-GMAIL-MSGID: =?utf-8?q?1752989220495002119?= Added validity check for count variable, return if count variable does not meet the execution condition (do not execute mutex_lock and mutex_unlock function). Signed-off-by: Li kunyu --- drivers/vfio/vfio_iommu_type1.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 23c24fe98c00..9bdf96d932e4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -3137,6 +3137,9 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova, int ret = 0; size_t done; + if (count <= 0) + return ret; + mutex_lock(&iommu->lock); while (count > 0) { ret = vfio_iommu_type1_dma_rw_chunk(iommu, user_iova, data,