From patchwork Wed Oct 24 19:58:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10654955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7755913A9 for ; Wed, 24 Oct 2018 19:58:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68FA228481 for ; Wed, 24 Oct 2018 19:58:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CB3D2B224; Wed, 24 Oct 2018 19:58:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B9AB28481 for ; Wed, 24 Oct 2018 19:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbeJYE2P (ORCPT ); Thu, 25 Oct 2018 00:28:15 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:37685 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726221AbeJYE2P (ORCPT ); Thu, 25 Oct 2018 00:28:15 -0400 Received: by mail-qt1-f194.google.com with SMTP id d14-v6so7108416qto.4; Wed, 24 Oct 2018 12:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+0fsrlOq/dSjaEtkyCmz/HyRHi0zkd/mUP3yrg/KeN8=; b=EULgr7097K2Ned1BR7S+KHDiMM+5pTQXBi+/v10X8ADiQzLQl/hB68Nh11aCmZH1+z 9TMxogvhuGvmH1QtWRTAAGDMjGqV8SwD21HpH8gBJD9ojphTdHCJYvgCSJK6ZDedbrTl hBh5DTRVxp9k7LuJQvplERe2NZbWCp7EvhvxLNexVtw2WHqZaxRtVp2/vg5w+tnZ1U55 s0MSjWZ329QH1iUPKqs9gOmOOeNtXHA7ZNuFX8tIOnMMETzgwaMnvaU8jV/iT5EiSkEM N8xEzOSMjcxgZauWmm6FjRagSHNMyyQisVoYEuPLUhCMVr0AFdRdeG5fDdMzOZtxOce4 D1MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+0fsrlOq/dSjaEtkyCmz/HyRHi0zkd/mUP3yrg/KeN8=; b=o4UngGN+KiDHd2dqR/h5T9Sw9qK293q5R12SCXML914mSODoBsrtHL1GOOTuJkmhee vf0/DnLwyqG7o+K/n0McW+rjSwEJJqFPAN06cBnLUFA0X1t1sEYBi4qy/XbOBsFcyy1d Q6mm32ADZpGdrLkVN7jiBu9mVFEUdoUbhEaKFwZnkHzCkFuAOJCUZfHjr8Z8eL05Xny9 2Pz9rG0gum5te4Z2phX9nBgQZ+M9SiuSaSKUdvMEcfVCXb70OYdouLR4noJZaeTWp1vd hCRYl8OtEi3E+JcLGrYPhV+NOTfJJboh7o4xfGlt0pBMc0J+NDxiEZWRCCDyVzOjOEgC +i6w== X-Gm-Message-State: AGRZ1gIeDB1oP9HWBI2BqkhMDRcBGM+gOO88apGvLHhsXA4UmpmQzKyR vN+3ixFJM/Pfv5Yuio1Jlq/sUT9v X-Google-Smtp-Source: AJdET5foZ7hC57QxWf9Wc6rH2HTULwU9uUkA9F0tcrzg6Xcsf/l6e2MUB6hAs4jrF9fqe4ExAC+7ag== X-Received: by 2002:ac8:550e:: with SMTP id j14-v6mr3936452qtq.139.1540411128393; Wed, 24 Oct 2018 12:58:48 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id d124-v6sm3872380qkf.85.2018.10.24.12.58.46 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 24 Oct 2018 12:58:47 -0700 (PDT) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, viro@zeniv.linux.org.uk, smfrench@gmail.com, miklos@szeredi.hu Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-man@vger.kernel.org Subject: [PATCH v2 05/13] VFS: Don't copy beyond the end of the file Date: Wed, 24 Oct 2018 15:58:29 -0400 Message-Id: <20181024195837.35532-7-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181024195837.35532-1-olga.kornievskaia@gmail.com> References: <20181024195837.35532-1-olga.kornievskaia@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Enforce the check that source offset can't be beyond the end of the file. Signed-off-by: Anna Schumaker --- fs/read_write.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index fb4ffca..7bdbf39 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1570,6 +1570,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (unlikely(ret)) return ret; + if (pos_in >= i_size_read(inode_in)) + return -EINVAL; + if (!(file_in->f_mode & FMODE_READ) || !(file_out->f_mode & FMODE_WRITE) || (file_out->f_flags & O_APPEND))