Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1297124pxj; Fri, 4 Jun 2021 10:38:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRWWkxJS7d2VXdaAE56jJzzbLqxXwNhvwXILUnzMrgwUk8FaqhpAVj5QHcxrkC0AG2YlrA X-Received: by 2002:a17:906:2a8e:: with SMTP id l14mr5234878eje.549.1622828309103; Fri, 04 Jun 2021 10:38:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622828309; cv=none; d=google.com; s=arc-20160816; b=nl8XlocXMykYc9oJXXyJQo2YOvk5eqJGgEw7I5N5/c3VVYoo4OT8NT2MspXGglMqUR 1KXHrGKO2WnCRSaUfNlCl1Afr1zxdB46CI1qq78aKWPHZg/FZN83r4cDd3IL0ZGCy8ii FnPOAwRxntD9m68iEw/kfM1oT+kNYlcFJWldjr3xwHVPqPHG9d+trGsuIfzqeP/McKse hZCfbySz0RAezl4cv9lOwrrcQddlFlVNXTlhQbUmP9mirkR9MDLCoXqzT2xsuruWEgJL lq6ZA/z06S4JDZ7pn5F/mTaw6/Tt6qKQkrJmNPi7ZsOe531mG/FP20ApNx8eWLpzCZNK Rl4g== 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=ScPrT6dq7UFJNtAcHi3Kbb1lZ9AVwXDNeiWLjZz5Hno=; b=sFs8ghoTZWmoxnK3sHfvNUMHlD6Gq0JWt/jOfcd0S3g9LSgCN6denNxMEUFSSHhnV4 oPOjPhGsutk5GAfZfo/haVXQRu6/i2S7z+53isJs1DqS6+xCi7V8jGCd9XCw8Q4GZlHm oC71Q9j5i9VdMHEusZ/5AyqKR4mAtThZQ0AkP5Ls2wtC36ohmArvURND1iajGDjR1SNR /yVegScj0BYhY8sBGwuu3FdLuDnqeN9p9Ux8bFTDx0IygPqUGFS9GfyRkSEkyqUP0/4l AGNtnClrqhPtMLMa8uT7JXTZ9xk2dgE8fgfEtMd5lm7nrmUQR+oKHqRYZvspiY4mnA8H 94xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IFknYVnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n17si5157092edr.161.2021.06.04.10.38.06; Fri, 04 Jun 2021 10:38:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IFknYVnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbhFDRix (ORCPT + 99 others); Fri, 4 Jun 2021 13:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhFDRix (ORCPT ); Fri, 4 Jun 2021 13:38:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 225EAC061766 for ; Fri, 4 Jun 2021 10:37:06 -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=ScPrT6dq7UFJNtAcHi3Kbb1lZ9AVwXDNeiWLjZz5Hno=; b=IFknYVnj7BNmGV8UkYrFPHR9go /U25Wt3qA+aBjWwinMkr5ZcaL1blgrRaaHgmmrJyaI9Mq3Hw49qyfEmiX4BsHyjMiAf9sHDi/UoiM 1IYGGWy+hKDlGkUOAKIZQbSaMtX0jPuT9EIfvlVsMZ/qi/Z4owJpy4ssubuG8GC+36l07hoqB4wRD QSgHGtOGMwJ8pcdWyABdGQW4aostYqvZdGiDPnWrk/KVAq3SBiJF/myIXMevkQJjhmHx1w+5z/ReN lnbtmUQsWFoBe4dNhvF6D5PL3/vdFk/RojcdILzRK8qP9t05CwrAfOWO/+Cmpf/ebqVnPLWhuCMIU 6iZBFu6w==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lpDju-00DQyc-GU; Fri, 04 Jun 2021 17:36:13 +0000 Date: Fri, 4 Jun 2021 18:36:10 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , "Kirill A. Shutemov" , Yang Shi , Wang Yugui , Naoya Horiguchi , Alistair Popple , Ralph Campbell , Zi Yan , Miaohe Lin , Minchan Kim , Jue Wang , Peter Xu , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/7] mm/thp: fix vma_address() if virtual address below file offset Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 03, 2021 at 02:40:30PM -0700, Hugh Dickins wrote: > static inline unsigned long > -__vma_address(struct page *page, struct vm_area_struct *vma) > +vma_address(struct page *page, struct vm_area_struct *vma) > { > - pgoff_t pgoff = page_to_pgoff(page); > - return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > + pgoff_t pgoff; > + unsigned long address; > + > + VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */ > + pgoff = page_to_pgoff(page); > + if (pgoff >= vma->vm_pgoff) { > + address = vma->vm_start + > + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > + /* Check for address beyond vma (or wrapped through 0?) */ > + if (address < vma->vm_start || address >= vma->vm_end) > + address = -EFAULT; > + } else if (PageHead(page) && > + pgoff + compound_nr(page) > vma->vm_pgoff) { I think on 32-bit, you need ... pgoff + compound_nr(page) - 1 >= vma->vm_pgoff ... right? > + address = vma->vm_start; > + } else { > + address = -EFAULT; > + } > + return address; > }