From patchwork Tue Jul 11 08:21:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13308244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0E05EB64DC for ; Tue, 11 Jul 2023 08:21:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6080710E334; Tue, 11 Jul 2023 08:21:14 +0000 (UTC) Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2149510E334 for ; Tue, 11 Jul 2023 08:21:13 +0000 (UTC) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4fb761efa7aso8334225e87.0 for ; Tue, 11 Jul 2023 01:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689063671; x=1691655671; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JxKFYbOeCPJfNoXrqBvsNS7aUlyz8/ToZjQNETQXPms=; b=dryEFzZ8771JS+Yz/dl8licnIGIt8/TaieUZTo0dhTADBi5ZZqEDWzTFcVSZW69cg/ mte2HvFAYmplwn1fBsdMb+RWFF48RZQvnQUBSK6yI0MffjBx6rI3seun21yOv6kvRD8E vmiZwUPuOprz76Ocv/+VsASegG9eiN6uEbI2Z//moFEHtC8cvy7ZUhGNtso7/Umcx/kS LQ+jB49gBpqdD6Ad3FL3RFij4OL+kGLjV28h2RJhrFqpSP8qB0yVIehwgyCEd5/qMqx+ t7JANG/W5CdKOH1Z5N+A9Kqraq/860FoFfc5hx7jh+lyr4VV1DJbxou5WR5DXDeBuj1b /8Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689063671; x=1691655671; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JxKFYbOeCPJfNoXrqBvsNS7aUlyz8/ToZjQNETQXPms=; b=WHV2n0bkc3mrkwzvhT9J/1va+zgmHIpiKdRKlq4+DOgM8GtnbhfLhJeUDquvV/qpex FCQHLRPUimZc81s6HrWe/q2TkHQ/M+m6ao5MOijyLmKM/tvi4PzqiqbhzrVzcVoo5SnG lWm7tZmIgf3Be/UecVFba26ivfluombnbf1H7j+SlaUFhDURRgEKfxyrraZNTCyXpvkY 3WPHlJM18bt/RWL15wC9wZxovaU7XCFXATLPzlu74tXpsqdYw60bHg3xkA0kWqZbNSxs 1v0jJ3gTy9X7W0NvLWuxIJrIj1Y/OT8Xv/aJQPF1v8jG4oa0dizDfJ6VGbVj+szWnxFT TgFw== X-Gm-Message-State: ABy/qLZzDbV8ubJpDJJl4zqXi7iBekda2x/XTSC43cM+l8PSOt5DyKx7 inP7UiHuLwA2ELttMK4Jg+aVQg== X-Google-Smtp-Source: APBJJlHWUMrcVV3AYfFcvmBu9p2eYaCi43r7UtCO6sh8OlRoN1RLLiuy84UaeWKCcjPqImedBSZb8w== X-Received: by 2002:a05:6512:3f3:b0:4fb:772a:af19 with SMTP id n19-20020a05651203f300b004fb772aaf19mr10748069lfq.34.1689063670997; Tue, 11 Jul 2023 01:21:10 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id o6-20020a5d4a86000000b0030e5bd253aasm1567187wrq.39.2023.07.11.01.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 01:21:10 -0700 (PDT) Date: Tue, 11 Jul 2023 11:21:06 +0300 From: Dan Carpenter To: Jeffrey Hugo Subject: [PATCH 4/5 v4] accel/qaic: move and expand integer overflow checks for map_user_pages() Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <6e935c70-5bd2-4808-bdd9-d664f892b0b5@moroto.mountain> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, Oded Gabbay , kernel-janitors@vger.kernel.org, dri-devel@lists.freedesktop.org, Pranjal Ramajor Asha Kanojiya , Carl Vanderlip , Jacek Lawrynowicz Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The integer overflow checking for find_and_map_user_pages() was done in encode_dma(). Presumably this was to do it before the allocation. But it's not super important that the failure path is a fast path and it hurts readability to put the check so far from the where the variable is used. Move the check to find_and_map_user_pages() instead and add some more additional potential integer overflow checks. Fixes: 129776ac2e38 ("accel/qaic: Add control path") Signed-off-by: Dan Carpenter --- no change drivers/accel/qaic/qaic_control.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/accel/qaic/qaic_control.c b/drivers/accel/qaic/qaic_control.c index 23680f5f1902..d5ce36cb351f 100644 --- a/drivers/accel/qaic/qaic_control.c +++ b/drivers/accel/qaic/qaic_control.c @@ -402,6 +402,12 @@ static int find_and_map_user_pages(struct qaic_device *qdev, xfer_start_addr = in_trans->addr + resources->xferred_dma_size; + if (in_trans->size == 0 || + in_trans->addr + in_trans->size < in_trans->addr || + in_trans->addr + resources->xferred_dma_size < in_trans->addr || + in_trans->size + offset_in_page(xfer_start_addr) < resources->xferred_dma_size) + return -EINVAL; + need_pages = DIV_ROUND_UP(in_trans->size + offset_in_page(xfer_start_addr) - resources->xferred_dma_size, PAGE_SIZE); @@ -564,9 +570,6 @@ static int encode_dma(struct qaic_device *qdev, void *trans, struct wrapper_list QAIC_MANAGE_EXT_MSG_LENGTH) return -ENOMEM; - if (in_trans->addr + in_trans->size < in_trans->addr || !in_trans->size) - return -EINVAL; - xfer = kmalloc(sizeof(*xfer), GFP_KERNEL); if (!xfer) return -ENOMEM;