From patchwork Sat Oct 13 00:06:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10639453 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 33B091508 for ; Sat, 13 Oct 2018 00:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2180C2B78F for ; Sat, 13 Oct 2018 00:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154002B7A3; Sat, 13 Oct 2018 00:06:29 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B8C92B78F for ; Sat, 13 Oct 2018 00:06:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EF3A6B026B; Fri, 12 Oct 2018 20:06:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6006B026C; Fri, 12 Oct 2018 20:06:27 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DB3A6B026D; Fri, 12 Oct 2018 20:06:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 65E456B026B for ; Fri, 12 Oct 2018 20:06:27 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id q6-v6so13962098qtb.14 for ; Fri, 12 Oct 2018 17:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=xkQw5bqFc5oVHdL+kJccEryf71PZClBt8QhI7IJ3dac=; b=AvNfl4XVKmMZK4t6qgSqj+CaHYeJ5Ryvvwqrms1afCBnGnu1sNvw7EuyTm232kTwWT nm9+tY+NwdtZGne60Dc+Je84KVfleSpGfm7vwvfmX1zVyorzZl6dSI51+BXTA+Evf7+5 M/BLFDNX1PnHU3MYU4Cnif9wmahKjlxkq88keyFY049pnR7PLoqTg5KkGb+uFlVMIHrv ofsDOLU23RpD/wyNDVgKR+u6rnzVNr1MzxjFaWpR+GojyjkOv7z63XRN2XgMgrtt7Hrx hVCMUwAwLJ6PBHzPHTI3FycH/gs2R5/wfiwWMEy+Ha2AlC/r91Z2g6WvLAeTCmmf6IZ4 bJYg== X-Gm-Message-State: ABuFfojVB1TG5Rs/ruhNr4L78yiTHEpTA2xn9/KkLE9DcIHotBVxiPFs 5RI2us5s/yQAPKun+vLDgkq3fkxanjrI7tp/ethulftBvMljaI8K4IMTu6mvDAt4i85lXwvTexj vJUJ0PdpEmeX99lThGL+YeUNURrVWhVllDfGqKZPdLH2ooCMR2gcQIwbhPinDW/2JOA== X-Received: by 2002:a37:8c42:: with SMTP id o63-v6mr7444481qkd.187.1539389187161; Fri, 12 Oct 2018 17:06:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Gw7ZKTCax2tzpBhyQRkCO7grH2g4XaUh4JkGzSlAbO9U6+tw82MAvxheKD2ZkAoQ4TvxQ X-Received: by 2002:a37:8c42:: with SMTP id o63-v6mr7444453qkd.187.1539389186520; Fri, 12 Oct 2018 17:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539389186; cv=none; d=google.com; s=arc-20160816; b=uLhq+XF7iwTkn9XPzZ9VzvpQgy3R6Z7e0gMM2IZHtaK36qoRHdIuz2U4zHCljFgLU9 RK2vkx97QwhL9+O7dMiau3AOWY+yDTn5xfKRb547BQMzrz6sTHO0iTHogmf6FumOcKuP rLbJ63yhIEGXE5EfoxpNnXEy9GJp22C+VKAsdGaJVn1fopleikmxXNIDtR/6zIcKNO3f 0KeXn7HuzeegZW7/Xi1nn3okccM44qdWgBo/ME+5S8mwx8/c3cHEydP41+luKzF+jU0+ p6TDDN31rSIU3WJCAVZxmzKciKj7ujDqLYBfc9i4Q+wUKWulBU3bWfE1vc7jO6WeUvLe bDiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=xkQw5bqFc5oVHdL+kJccEryf71PZClBt8QhI7IJ3dac=; b=bAx7vd2is3tr179dQYA+CxO0BDE1LjQoYyjbzD39hosC7TIbhWmqQVQJCoY8SugGLG XzMsJE3EQuAaRc/HyrkHvF20NWXYCCCwnxmEjtrn47mDcdzUGTm66msSkqNhel5J/SzQ b0m1cVs0sMP5MAP/Dn7/SXkkJiFDonq6RqGFnfCjtq9u5xCtUrubYqeA+kmGXRfDIpcT AUB98cuRkHTjRkc2KfBJnY5fda2JCwQkEeurDGOF5yTWFkYypjBQBKJwPnVwsANa1vjG xwwF24VxPImpkAzMzMs3UMSihuirqW6hq4SRlHqhXq07OhKXZ2NrqZeU+1hN19OmEM1G DXGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="sy49W/G+"; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id e55-v6si2490465qvd.50.2018.10.12.17.06.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 17:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="sy49W/G+"; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9D03wHN143579; Sat, 13 Oct 2018 00:06:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=xkQw5bqFc5oVHdL+kJccEryf71PZClBt8QhI7IJ3dac=; b=sy49W/G+fFu1XZDyPsSt3TzaneGu0yxpOY6V/+gwG0ny1c60cxENmaAndGNeWQtlHw4E jGrDQa4luQZGOM497reD9HMJRakvuJmgmyUB3TcJ0LsWnJGSf1pRCdeQaOwufq5i2cD+ JroJJEljl+RsiTshmGtJBPxIOhnwOO7mnzi9F3r20eXJDxInQRLpdYLi2R0dZRSexP1+ VZoMm+Zok+iRnMyvH8vR2jv5FIrJoiidrHx0pDCQfEGNhCCEwko5feVxEwnVT8WiEiJo Zf92VDj7hL27ax2ztdY6YnJxJduSOG9ZvKGvg2FMo/04yNwtweTlJXYSzw/yevCOoqoR 1A== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2mxmfudpw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:06:25 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9D06JKH021744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:06:19 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9D06Jgw017650; Sat, 13 Oct 2018 00:06:19 GMT Received: from localhost (/10.159.251.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 13 Oct 2018 00:06:19 +0000 Subject: [PATCH 05/25] vfs: avoid problematic remapping requests into partial EOF block From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Fri, 12 Oct 2018 17:06:17 -0700 Message-ID: <153938917765.8361.15966712047859994604.stgit@magnolia> In-Reply-To: <153938912912.8361.13446310416406388958.stgit@magnolia> References: <153938912912.8361.13446310416406388958.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9044 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=613 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810130000 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong A deduplication data corruption is exposed in XFS and btrfs. It is caused by extending the block match range to include the partial EOF block, but then allowing unknown data beyond EOF to be considered a "match" to data in the destination file because the comparison is only made to the end of the source file. This corrupts the destination file when the source extent is shared with it. The VFS remapping prep functions only support whole block dedupe, but we still need to appear to support whole file dedupe correctly. Hence if the dedupe request includes the last block of the souce file, don't include it in the actual dedupe operation. If the rest of the range dedupes successfully, then reject the entire request. A subsequent patch will enable us to shorten dedupe requests correctly. When reflinking sub-file ranges, a data corruption can occur when the source file range includes a partial EOF block. This shares the unknown data beyond EOF into the second file at a position inside EOF, exposing stale data in the second file. If the reflink request includes the last block of the souce file, only proceed with the reflink operation if it lands at or past the destination file's current EOF. If it lands within the destination file EOF, reject the entire request with -EINVAL and make the caller go the hard way. A subsequent patch will enable us to shorten reflink requests correctly. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/read_write.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index d6e8e242a15f..067ff5698e0b 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1723,6 +1723,7 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); + u64 blkmask = i_blocksize(inode_in) - 1; bool same_inode = (inode_in == inode_out); int ret; @@ -1785,6 +1786,22 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, return -EBADE; } + /* Are we doing a partial EOF block remapping of some kind? */ + if (*len & blkmask) { + /* + * If the dedupe data matches, chop off the partial EOF block + * from the source file so we don't try to dedupe the partial + * EOF block. + * + * If the user is attempting to remap a partial EOF block and + * it's inside the destination EOF then reject it. + */ + if (is_dedupe) + *len &= ~blkmask; + else if (pos_out + *len < i_size_read(inode_out)) + return -EINVAL; + } + return 1; } EXPORT_SYMBOL(vfs_clone_file_prep);