From patchwork Thu Jun 20 01:44:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 11005665 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 D01EF6C5 for ; Thu, 20 Jun 2019 01:44:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEFCC283B2 for ; Thu, 20 Jun 2019 01:44:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B06D4283EE; Thu, 20 Jun 2019 01:44:36 +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=ham 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 51FB6283B2 for ; Thu, 20 Jun 2019 01:44:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731193AbfFTBof (ORCPT ); Wed, 19 Jun 2019 21:44:35 -0400 Received: from mail-pf1-f177.google.com ([209.85.210.177]:34767 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731147AbfFTBof (ORCPT ); Wed, 19 Jun 2019 21:44:35 -0400 Received: by mail-pf1-f177.google.com with SMTP id c85so688022pfc.1; Wed, 19 Jun 2019 18:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=0zOxBKUCYDOIWhRf58Otm+dLo3EckbJIQoYgCqazd24=; b=l32nv//PIdQ6sTQprdgpqu/QVROQXBFnnpZqHlApr4HhKUtzqHFfj8qTB5yZuj50eC 07z9A/7y8sj0jCEX+DPD0UN5mwf4HRV/NCL340qCxnN2AD8bs1pD61DRndPUMRYSSiJq fqAz/oNvuLaMqHL+u1DeLKqVl5AQYJL1vYhLvmP1EQhqvg2J8zUPUFYV5g3/IzIxJjHJ 20/n4YdtrRMMkCSdELpNGWt3CQ6yR7NqRGxAju/9S4dgHzoeGJgBv5ZPmXKdx7KwpEGa COyUmiLexj+O2560FEwBc5233BAq3XKRCMLNoF1kDBAzffblX50MC5nSJ1kWOo1lwWqi txzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=0zOxBKUCYDOIWhRf58Otm+dLo3EckbJIQoYgCqazd24=; b=MjoMEk2S/7q0yDJEkRgsdLWbG1LwjFgrBV6+hMtW1G0BQyd7vHXB8ec9D8wZ9XheEo IOZzUkjyTEFKcg9rBvrqjLXYdqQXavIyGSsAixJTZtRnFt5HBdMVCiALtMpiAhrpLh0X JRz7NeVr2qYDABCDlUQt0F7G38+UNJicJVQARv1g7nhJceFn3e0zXv+DWn7y0p34phd2 GCiYJbaKnBp/iOg/I477NNfTS4nU9UOD4DLOJpusEG2AgK9nTFwUch6Fy16dmDW5NRyW wU86bvUEF0dyhe9dsreIrN8h2g0+gXwXZoKjsftTuFtha9m7rtbma7FDEbMy9f26XIB9 JMdg== X-Gm-Message-State: APjAAAUOJdbdFpx3VMVPBY55Thw37g0niBJgVPvaDfl3DTN59htw6CZ4 fpjXuk4LpL6xgOmd8s0TvXihMFIQfI6RWlzUA9Dh0Q== X-Google-Smtp-Source: APXvYqweuRogMqI/AyZMce/SUayiDeo6KgbY5HyVeSwFAhYC7CAqdWxtN53Z6M3DE3mV2nMNMQq0/lq0KQU0QUBP6Bw= X-Received: by 2002:a63:d4c:: with SMTP id 12mr10787654pgn.30.1560995073972; Wed, 19 Jun 2019 18:44:33 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Wed, 19 Jun 2019 20:44:22 -0500 Message-ID: Subject: [SMB3][PATCH] fix copy_file_range when copying beyond end of source file To: CIFS , samba-technical , Amir Goldstein , linux-fsdevel , "Darrick J. Wong" 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 Patch attached fixes the case where copy_file_range over an SMB3 mount tries to go beyond the end of file of the source file. This fixes xfstests generic/430 and generic/431 Amir's patches had added a similar change in the VFS layer, but presumably harmless to have the check in cifs.ko as well to ensure that we don't try to copy beyond end of the source file (otherwise SMB3 servers will return an error on copychunk rather than doing the partial copy (up to end of the source file) that copy_file_range expects). Reviewed-by: Ronnie Sahlberg From a3d9033df7bb5206093f00eb037242336ff7ccfb Mon Sep 17 00:00:00 2001 From: Steve French Date: Wed, 19 Jun 2019 15:10:12 -0500 Subject: [PATCH] [SMB3] fix copy file range when beyond size of source file When requesting a copy which would go beyond the end of the source file, only copy to the end of the source file instead of returning an error. Fixes xfstests generic/430 and generic/431 Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 376577cc4159..1cdbeec56453 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1522,6 +1522,7 @@ smb2_copychunk_range(const unsigned int xid, int chunks_copied = 0; bool chunk_sizes_updated = false; ssize_t bytes_written, total_bytes_written = 0; + struct inode *inode = d_inode(srcfile->dentry); pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); @@ -1546,6 +1547,14 @@ smb2_copychunk_range(const unsigned int xid, tcon = tlink_tcon(trgtfile->tlink); while (len > 0) { + if (src_off >= inode->i_size) { + cifs_dbg(FYI, "nothing to do on copychunk\n"); + goto cchunk_out; /* nothing to do */ + } else if (src_off + len > inode->i_size) { + /* consider adding check to see if src oplocked */ + len = inode->i_size - src_off; + cifs_dbg(FYI, "adjust copychunk len %lld less\n", len); + } pcchunk->SourceOffset = cpu_to_le64(src_off); pcchunk->TargetOffset = cpu_to_le64(dest_off); pcchunk->Length = -- 2.20.1