Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3284136rwl; Sun, 9 Apr 2023 12:02:35 -0700 (PDT) X-Google-Smtp-Source: AKy350ZIcfy7FI2mLxxFQ0+TPzI1OlybuCjdu3QOey3tNGXojZpnv6Zr83RFqFHJ8JA9dVELzrhK X-Received: by 2002:a17:906:7cc8:b0:933:1702:a12b with SMTP id h8-20020a1709067cc800b009331702a12bmr6232339ejp.17.1681066954767; Sun, 09 Apr 2023 12:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681066954; cv=none; d=google.com; s=arc-20160816; b=ywmNwHGR25F5LFtF58gIWcpXltlJ7HWHbZBRBpycxE8EWIGRGEs7N9nveEc9XCh0r8 vpi+dyZpv4gWwITw5e8ypfbYnB7i1/dfC6KLnjHrJFhMR94/8sMSO/09ex8Xv8BVmzNO b8TQsRNvwR2Ym2yw4MjTYqDEnHdq2aRa9G1pzn+oBLa+3RJVp3i4J9yWUe/XmTg+jLH1 fNcJ+Ko9CjdYpgiiEVWqzAQPjzPWPEhmyQrZW3TH0Cu2nsFmIYCJGdxdNFAZnfLh+s2L 1fb5aibhODUsgW4276BrOln38hbbqthU/2LzbqeEOjquwGjdCAldPYy/lz6ywSDtgDgN 2kLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=CbkAOGdtvtnwqGRrwMSF8jAQAGnOlEwbF+SCF6w1W1E=; b=ITHbuKFQKo+nCFdTbNCaF1LLrCJHNapuQDi150xrB0ocEfYMYSAdmPJwN6xaaH6/jk eSZux1isAqFJGnXazGwPXtA76VIFwgcA/joJTUQJ8/E3woYuUPxjmEXm0PSz7u99p42a +QT7SQABHnqOpPQk36xbabKdx3DG/Nq9mzVeyt82jjgKrECWL3C59iqg3yJboqmxJBEz 2xgEX/elyemf/MCdkQSe3H7kSdD/vXiUtK0NgGKBfOxa9wXq0o5tMG3FXTKxeP90M27j lzaWydQG/gNsZyDVQIpN+Po7buKxCIIcQGcN0C+olw/FkrhbPIRk2shOXyhz86aJHnub vETw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=h0DPVci2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020aa7d356000000b0050494d883c9si2709491edr.538.2023.04.09.12.02.00; Sun, 09 Apr 2023 12:02:34 -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=@gmail.com header.s=20210112 header.b=h0DPVci2; 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 S229535AbjDITAd (ORCPT + 99 others); Sun, 9 Apr 2023 15:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjDITAc (ORCPT ); Sun, 9 Apr 2023 15:00:32 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F9F30F7; Sun, 9 Apr 2023 12:00:28 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-50489d2f5e0so765494a12.3; Sun, 09 Apr 2023 12:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681066826; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=CbkAOGdtvtnwqGRrwMSF8jAQAGnOlEwbF+SCF6w1W1E=; b=h0DPVci2IbEjLzd9n+q0OGY+ug7P9W3pfyNWIzcYxUpqSA74e3eaisnpc6R69c5Nx2 Wd/VKB+HLqawuHBw3dPMQqxDFdmiDl2JVqW/XpEkQ/l4Z746iDX6CNchhUsoDq3hQGCv 5fQCTgme+r4xPKQV5HJpQDdDxOgiVFI3XEOc+f11gPti/OGgyaUMyS1GheUpxg7sPn2x MpQXM9RCqouUKZub6YZzx61WP1bUnCWw33y+TMjY+SVJA0NhZA7xLIVbWI3r6Xrf4x8t 3U8RMyW8P/OWG+sf/78fCBza37szYkdTrKssCEYO2eZkC18PZ4V2UT814cH7Q0yKW/r5 9r8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681066826; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CbkAOGdtvtnwqGRrwMSF8jAQAGnOlEwbF+SCF6w1W1E=; b=XYktXB1O8jIE6fQw+2Onk/cxrl/fnv1zmUoWFp3keFwFm7ImJt5ugxXlVwXmTvB7vs 3VhnT9zyUHGAvu/5JDG3I5HLiVt2WXrC61UlSoNfOkfPW4GTWgSt5VZOrUHRUVbdoe7X Q5vhDJhQ4e4sbuva3gd98vSaglg5VBbEwE0i4/MnZlBbAt39EIOKiSBzJTLApfltLqc5 totxAMLQUWCawFYJ/tcdQA9iTlye/31jCaG1uRGjXPgP3CVmt9c9h63v7XhBf0CkfiTn 8dS3mVaHIBj42i3XdCuUPm7jNA2Skvf1oQeW6BGohRWubCHD0n8yPir00pOKp+4BbwIj pe2w== X-Gm-Message-State: AAQBX9fBz4886mXzvZXPGDRzCsLpWRwD1sn0aJYoImdfAqlNIQ65jtq+ 8gihr9wSov9aY1LhI4UxKEg= X-Received: by 2002:a05:6402:12c9:b0:4a0:e305:a0de with SMTP id k9-20020a05640212c900b004a0e305a0demr9248329edx.19.1681066826116; Sun, 09 Apr 2023 12:00:26 -0700 (PDT) Received: from eldamar.lan (c-82-192-242-114.customer.ggaweb.ch. [82.192.242.114]) by smtp.gmail.com with ESMTPSA id l18-20020a50c112000000b004fc01b0aa55sm4148969edf.4.2023.04.09.12.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Apr 2023 12:00:25 -0700 (PDT) Sender: Salvatore Bonaccorso Received: by eldamar.lan (Postfix, from userid 1000) id E550BBE2DE0; Sun, 9 Apr 2023 21:00:24 +0200 (CEST) Date: Sun, 9 Apr 2023 21:00:24 +0200 From: Salvatore Bonaccorso To: Xu Yilun , Sangsup Lee Cc: k1rh4.lee@gmail.com, Wu Hao , Tom Rix , Moritz Fischer , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fpga: dfl-afu-region: Add overflow checks for region size and offset Message-ID: References: <20230206054326.89323-1-k1rh4.lee@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS 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 Hi, On Fri, Feb 10, 2023 at 04:21:37PM +0800, Xu Yilun wrote: > On 2023-02-05 at 21:43:26 -0800, k1rh4.lee@gmail.com wrote: > > From: Sangsup Lee > > > > The size + offset is able to be integer overflow value and it lead to mis-allocate region. > > But I didn't see the memory allocation. > > > > > Signed-off-by: Sangsup Lee > > --- > > drivers/fpga/dfl-afu-region.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/fpga/dfl-afu-region.c b/drivers/fpga/dfl-afu-region.c > > index 2e7b41629406..82b530111601 100644 > > --- a/drivers/fpga/dfl-afu-region.c > > +++ b/drivers/fpga/dfl-afu-region.c > > @@ -151,12 +151,17 @@ int afu_mmio_region_get_by_offset(struct dfl_feature_platform_data *pdata, > > struct dfl_afu_mmio_region *region; > > struct dfl_afu *afu; > > int ret = 0; > > + u64 region_size = 0; > > Reverse Xmax tree please. > > > > > mutex_lock(&pdata->lock); > > + if (check_add_overflow(offset, size, ®ion_size)) { > > I'm not sure if the check is necessary. > > The offset comes from: offset = vma->vm_pgoff << PAGE_SHIFT > The size comes from: size = vma->vm_end - vma->vm_start > Is it possible the upper mm layer passes invalid vma? > > Thanks, > Yilun Did you saw the comments on your patch by Yilun? Did it felt trough the cracks? Regards, Salvatore