Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3744176pxk; Tue, 29 Sep 2020 05:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt3/NgS4AZUhVw4zJCOPlQnVY9hzhfeFKibddSgkAS78CE4+OggF8iphpJ/JD2YlW14ZOj X-Received: by 2002:a17:906:71cc:: with SMTP id i12mr3515989ejk.507.1601381986624; Tue, 29 Sep 2020 05:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601381986; cv=none; d=google.com; s=arc-20160816; b=xo8d5N5yVjRf19ndil8luIy4291S2SejcC8m3RSH7/m6viFtG0kCnOTKKIeN3qhdk3 qX2bi0hRfEO5aEXyRNngiqeltRWoePUvWMgDvJqbzF4DaXRyLdnd0AvXOg8m6LXkdaEO 1mQP6mdE+B8ffke7/Je46gtEkFSX8NFmM0uPxhtUx0ZWjTXSMha/poPrkDwX+Vt1Mu/s N4MDjZKQjvkK7aFl6cxvX8SobsLzIJqEA0/ak48iDiIl18OqbdzvACz/IcSjS6kKFhgs cvq0gf5vWWZQAb1siYFESGW5LU0420n+Xf9wDUen4dVLMH9aYhIcNfdv88bKGs/0XAtB 2xWA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z/E62DRnOh+M5j5oK3nqZYTmVd0Vsj05IqayqylTnP4=; b=pmd2o/a3hpYMM1/9f9D90NphCjB3GpQDcNfJpIak9bVPaAJ3tkaj9TNrcdHv2Cw06u JV0d0Hes++GE5jLqBjePauhNBgO/eD/ewaOAulC3fSrExX52O0Atq7C0Q35N9+vDEMKT DyR0Oi38YgWuiqv/6nJY+HcnjxNay6lfjrvWP+Ae8SUQjxNpXnmTxweXLZuAdcPxQJAg 1mWxtOTu9m3/gCmZKlybbYd117gdKxzZR2cB8TP1NacM/vb4ENFiF9RkWTkKjyyC9ioi hpj86iWAsdgC2rIRGmFZik93W0IpCleAX+24U63u42Um1hEzpeNNQ81lo6Jy5YWKJQLh YKPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gNS8d15x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si3025469edl.58.2020.09.29.05.19.23; Tue, 29 Sep 2020 05:19:46 -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=gNS8d15x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730146AbgI2MQ0 (ORCPT + 99 others); Tue, 29 Sep 2020 08:16:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:49134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730043AbgI2LhA (ORCPT ); Tue, 29 Sep 2020 07:37:00 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB63E23EB2; Tue, 29 Sep 2020 11:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379139; bh=N3ynWYmdV/p1XabRsM2S+M0ftLt27a+Mcw8vF35vnIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNS8d15xRQWGg1keVZyXsfATBeqvdY7p6jC3kSLogTQZeqNpjCrVRtifolrVBN8Xo q/ZEjwENOiN4hctiH2s5pEQZMZTED3hqZ2+uJC+uyquhGIbvDYcr5EkQdv/d5+r6mJ JNA+YsPw3TXEGZYVWdSZKyGGjHLMweMX6PwTdQd4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Gruenbacher , Christoph Hellwig , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 5.4 031/388] iomap: Fix overflow in iomap_page_mkwrite Date: Tue, 29 Sep 2020 12:56:02 +0200 Message-Id: <20200929110011.994771088@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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