Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2671223rwo; Sun, 23 Jul 2023 22:07:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlG272RSwRZnahjo254YSPDP6hdS4lDPgdOsjke/qO1tMEBGitgFMG64hRZssHuN2mcSzlIR X-Received: by 2002:a17:902:d4c2:b0:1b8:936f:c346 with SMTP id o2-20020a170902d4c200b001b8936fc346mr13043799plg.30.1690175259009; Sun, 23 Jul 2023 22:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690175258; cv=none; d=google.com; s=arc-20160816; b=pHw8jBlxAjHOL5W41ooLjRq5f8BD33ocXyP/l6SwBbkSrrEHTKF1Z9ZsVdKmnHqbJc K/k1SVckP/YORKF+Ifh2kdvfBiFjfQyt9xh1xN0T4bw+Xei580OVaQo50zYKSW1LpAdv ydG/VaGGtP87m5Ztrf+TyxnSJoL6RUW1MkIIK3PC71hpoT4iK0ap37vE1zMlOqU5gSjk DtnCmH4vgM/2yvw9skdgudPsuQQMRLcxp2nIZQdHRQ+MCpir/Xasv73GpUZ1ywdVYDXK kDE5UE0vy7QN3APtCMvww9dMMfOMDbwv30nhVYBA4n+OYEVd5BZie8rpdBGYe7PjKjyO ZoLg== 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:dkim-signature; bh=rD2o03oywrQbl03nygg5NeYhEzEaqLbdSS7VHYFYy9w=; fh=r2GUvXMVY/B/sYke8hIkwjUxCFDf4bjcG3etlbWUNV8=; b=xEs26VEPIzUVEakgNqFAq16OnG+3Gv17wHcmPAdsegWDFIqXdC5i39v/Vg+ddjxpPQ MtoEr7tzz2SrqaBI03O21U7ntJBWdtV+6Y/wo+nyfGhnL8bLk/pVk3de2C9KglfMfYz2 U/rXFuBjs/dWRndKrE/71DD9mmeBOCFJnsz6CoSS71/Wncbxea8O32/m+mLzEm4ENNer tzHKjORBfL4XqYKrCayv5YzCFtm1hB6qD7EDkAkXNFjUMSL5lNMpwlo72txwthFDiQ+0 bStoiqqhiJLyC/Q484P55Rn6fQgaGqNWCfNzijRBjALlFNLCoJZ5193BwFpFWqzLb0/B piBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LfM3ELlr; 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 x63-20020a638642000000b0053f228ce43csi8222152pgd.547.2023.07.23.22.07.25; Sun, 23 Jul 2023 22:07:38 -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=@infradead.org header.s=casper.20170209 header.b=LfM3ELlr; 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 S229964AbjGXDsP (ORCPT + 99 others); Sun, 23 Jul 2023 23:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjGXDsG (ORCPT ); Sun, 23 Jul 2023 23:48:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96CF7DD for ; Sun, 23 Jul 2023 20:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rD2o03oywrQbl03nygg5NeYhEzEaqLbdSS7VHYFYy9w=; b=LfM3ELlrfQ44a5QhE4f8IlLt4J pqhy94V9ujXzJO0JWGNlp5zfCtXFBJ9LiZ18EudChMCbDbe5nkHDXLSZPFvUxtrNzYXiql0lz2abW juQHJ+qZCJGrxzjxANsYvrf0Dw9tr8odFnYLJf2JB9hN+WWOOGZV41VhTm7HIr8hjchcrfstkBjYr H3hMr6QW5fu0m6DOpnzFQ6k/nHyW65lEqps2Y3WRVHX7odGb3JiBDBAClo2elqw+kz+aK46uzpAYg 0aIGeqmdUMr0bJD5kNMCr0NCKqULbf/jhR/JBMwz7aJwQOE79LjFbIAizyXnnl5T/+Js9GaGb7ysI 39mBamkg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qNmXl-003x0r-9s; Mon, 24 Jul 2023 03:47:33 +0000 Date: Mon, 24 Jul 2023 04:47:33 +0100 From: Matthew Wilcox To: Linke Li Cc: linux-mm@kvack.org, mike.kravetz@oracle.com, muchun.song@linux.dev, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, dan.carpenter@linaro.org, Linke Li Subject: Re: [PATCH v3] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Thu, Jul 20, 2023 at 10:49:52PM +0800, Linke Li wrote: > +++ b/fs/hugetlbfs/inode.c > @@ -154,10 +154,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) > if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT)) > return -EINVAL; > > - vma_len = (loff_t)(vma->vm_end - vma->vm_start); > - len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); > - /* check for overflow */ > - if (len < vma_len) > + if (check_add_overflow(vma_len, (loff_t)vma->vm_pgoff << PAGE_SHIFT, &len)) > return -EINVAL; Doesn't this check duplicate that performed by file_mmap_ok()? Can't we just delete the check, or is there a code path that leads here while avoiding file_mmap_ok()?