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: 1119089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="l32nv//P"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45Tl450lSFz9s5c for ; Thu, 20 Jun 2019 11:44:36 +1000 (AEST) 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 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