Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp882675pxk; Thu, 17 Sep 2020 20:15:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOxjnaI5WBOg4+Z2EKY/nokrAlUAeoTzVrt/TUpGeSH3I4FgnD8TGMxG/435rnUaj7xFbE X-Received: by 2002:a17:906:fb8f:: with SMTP id lr15mr33253665ejb.25.1600398914759; Thu, 17 Sep 2020 20:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398914; cv=none; d=google.com; s=arc-20160816; b=zmrmiqHz6GkwmJGbpH6BXEjOzDoVBUtwBfyl+x5+p4dx2mnjby4PjW5LsA77G7SyVu zMtRVX6jYb0WPcVmP2P2gnlu0hqeUNhZyRLwqOw0C36jdDIjWk+aT4jcWRAlO4LshMPz 0Aq5ioJKf7jwmhdNtL6A5UQ9LSQW/RNI5FWmPJwy0CpJxGnP4nj6oZyoOd47WbwwYqWI loWg3SJeTNQTv342ZbSa1+TaIZlQ91kcnL5GP6DHgSDJOif3ak4ObO3tbpGi3ydSUpkV GHdc65hoSmB7dCT8xvz9PmYNgP4kZebY2CyqVX/3EPHA4/Y3D9vdWw0r3Top0RKUOZbb pEZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z/E62DRnOh+M5j5oK3nqZYTmVd0Vsj05IqayqylTnP4=; b=pleJ8p71sfQ8taYfBT+TXWRenVtpvxBkzT5b3S3E3PFyim3rdfjjA2lTeVcPmbKqXK EY+TDxvK4eJDOLlKBBRAUH/A4mOWOh4RNOEFMw6LSBX83BgYT4y7wCwmRDMyGt+eoVtL FzfrgJQITm3annpRdiFG3iIpz5eqXB1dgljoWXM2zcIcpFzSr5/NguixSyxpijqxJVSY 1upXY0myrYEE08WY6qKO5B5fogJZLOzyXarfsM9P9OhrJ0+qWp0LeeDUyQ+lMK+ilnC5 aNdh/NVDLr6Th8GoT3DAhGtt0/PdGU+fg+xNINF3Dkg0uML+KLWmiKNqu6juNBau2ojf qt6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U0F6aGqP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si1233662ejt.286.2020.09.17.20.14.51; Thu, 17 Sep 2020 20:15:14 -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=@kernel.org header.s=default header.b=U0F6aGqP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728592AbgIRDOA (ORCPT + 99 others); Thu, 17 Sep 2020 23:14:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:46470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgIRCBu (ORCPT ); Thu, 17 Sep 2020 22:01:50 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD0C721D92; Fri, 18 Sep 2020 02:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394510; bh=N3ynWYmdV/p1XabRsM2S+M0ftLt27a+Mcw8vF35vnIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0F6aGqP5HdwE0/PgAgCr+ISvwwzxxfebH1MnYuh4o+G3JVvXFAgAyo6BajaGUwh8 9nV9sHa39DBpNf/m5ogGqkpYdE9rOUvWqPZDGzXTUc4/58d3vKnE2kfWUnrpGhhzMq +4T8Mlt3Sf0egKdJrRHzDdp8dtIze0yMlqh90fE8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andreas Gruenbacher , Christoph Hellwig , "Darrick J . Wong" , Sasha Levin Subject: [PATCH AUTOSEL 5.4 033/330] iomap: Fix overflow in iomap_page_mkwrite Date: Thu, 17 Sep 2020 21:56:13 -0400 Message-Id: <20200918020110.2063155-33-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andreas Gruenbacher [ Upstream commit add66fcbd3fbe5aa0dd4dddfa23e119c12989a27 ] On architectures where loff_t is wider than pgoff_t, the expression ((page->index + 1) << PAGE_SHIFT) can overflow. Rewrite to use the page offset, which we already compute here anyway. Signed-off-by: Andreas Gruenbacher Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/iomap/buffered-io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e25901ae3ff44..a30ea7ecb790a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1040,20 +1040,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops) lock_page(page); size = i_size_read(inode); - if ((page->mapping != inode->i_mapping) || - (page_offset(page) > size)) { + offset = page_offset(page); + if (page->mapping != inode->i_mapping || offset > size) { /* We overload EFAULT to mean page got truncated */ ret = -EFAULT; goto out_unlock; } /* page is wholly or partially inside EOF */ - if (((page->index + 1) << PAGE_SHIFT) > size) + if (offset > size - PAGE_SIZE) length = offset_in_page(size); else length = PAGE_SIZE; - offset = page_offset(page); while (length > 0) { ret = iomap_apply(inode, offset, length, IOMAP_WRITE | IOMAP_FAULT, ops, page, -- 2.25.1