From patchwork Wed Nov 27 15:18:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11264371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CB9D6C1 for ; Wed, 27 Nov 2019 15:18:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4180F20722 for ; Wed, 27 Nov 2019 15:18:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MTwMRqNu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727156AbfK0PSb (ORCPT ); Wed, 27 Nov 2019 10:18:31 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:38553 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727138AbfK0PSa (ORCPT ); Wed, 27 Nov 2019 10:18:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574867910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MKRMqYZcMSPOI1ZGGK/kSwrsQZTCaWDdryNtYrwk8A4=; b=MTwMRqNu+MeR4QaIT5ScdTi3FY3q4TIbuScZCw7D1Q/tdgkXeTHJIgVCon5MbH5HY3Smfk kwpurQunGpQ/srUNR5GqysQLb5Cd1g5u2UjmQ4/O/Ads1THgydWuoyLyKy2gV5YnApSEIr nAjbrGSucYE0aWx0G5+mXCDgafrGAco= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-147-GM3JGt2IPoeXL76p6qeU6w-1; Wed, 27 Nov 2019 10:18:26 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA8C11007271; Wed, 27 Nov 2019 15:18:22 +0000 (UTC) Received: from max.com (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 477BF1001DE1; Wed, 27 Nov 2019 15:18:14 +0000 (UTC) From: Andreas Gruenbacher To: Linus Torvalds Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, Alexander Viro , Jeff Layton , Sage Weil , Ilya Dryomov , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Richard Weinberger , Artem Bityutskiy , Adrian Hunter , ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org Subject: [PATCH] fs: Fix page_mkwrite off-by-one errors Date: Wed, 27 Nov 2019 16:18:11 +0100 Message-Id: <20191127151811.9229-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: GM3JGt2IPoeXL76p6qeU6w-1 X-Mimecast-Spam-Score: 0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Fix a check in block_page_mkwrite meant to determine whether an offset is within the inode size. This error has spread to several filesystems and to iomap_page_mkwrite, so fix those instances as well. Signed-off-by: Andreas Gruenbacher Reviewed-by: Darrick J. Wong --- This patch has a trivial conflict with commit "iomap: Fix overflow in iomap_page_mkwrite" in Darrick's iomap pull request for 5.5: https://lore.kernel.org/lkml/20191125190907.GN6219@magnolia/ --- fs/buffer.c | 2 +- fs/ceph/addr.c | 2 +- fs/ext4/inode.c | 2 +- fs/f2fs/file.c | 2 +- fs/iomap/buffered-io.c | 2 +- fs/ubifs/file.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 86a38b979323..152d391858d4 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2465,7 +2465,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, lock_page(page); size = i_size_read(inode); if ((page->mapping != inode->i_mapping) || - (page_offset(page) > size)) { + (page_offset(page) >= size)) { /* We overload EFAULT to mean page got truncated */ ret = -EFAULT; goto out_unlock; diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 7ab616601141..9fa0729ece41 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1575,7 +1575,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) do { lock_page(page); - if ((off > size) || (page->mapping != inode->i_mapping)) { + if ((off >= size) || (page->mapping != inode->i_mapping)) { unlock_page(page); ret = VM_FAULT_NOPAGE; break; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 516faa280ced..6dd4efe2fb63 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -6224,7 +6224,7 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) lock_page(page); size = i_size_read(inode); /* Page got truncated from under us? */ - if (page->mapping != mapping || page_offset(page) > size) { + if (page->mapping != mapping || page_offset(page) >= size) { unlock_page(page); ret = VM_FAULT_NOPAGE; goto out; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 29bc0a542759..3436be01af45 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -71,7 +71,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) down_read(&F2FS_I(inode)->i_mmap_sem); lock_page(page); if (unlikely(page->mapping != inode->i_mapping || - page_offset(page) > i_size_read(inode) || + page_offset(page) >= i_size_read(inode) || !PageUptodate(page))) { unlock_page(page); err = -EFAULT; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e25901ae3ff4..d454dbab5133 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1041,7 +1041,7 @@ 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)) { + (page_offset(page) >= size)) { /* We overload EFAULT to mean page got truncated */ ret = -EFAULT; goto out_unlock; diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index cd52585c8f4f..ca0148ec77e6 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1564,7 +1564,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf) lock_page(page); if (unlikely(page->mapping != inode->i_mapping || - page_offset(page) > i_size_read(inode))) { + page_offset(page) >= i_size_read(inode))) { /* Page got truncated out from underneath us */ goto sigbus; }