From patchwork Fri Dec 19 06:29:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5517591 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5B67E9F1CD for ; Fri, 19 Dec 2014 06:29:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B63F20121 for ; Fri, 19 Dec 2014 06:29:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE457200ED for ; Fri, 19 Dec 2014 06:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751621AbaLSG3e (ORCPT ); Fri, 19 Dec 2014 01:29:34 -0500 Received: from mail-pd0-f173.google.com ([209.85.192.173]:65418 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751243AbaLSG3d (ORCPT ); Fri, 19 Dec 2014 01:29:33 -0500 Received: by mail-pd0-f173.google.com with SMTP id ft15so583260pdb.4 for ; Thu, 18 Dec 2014 22:29:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3iiYIkL3VEq9RadfIItybt0kLeKGJfc/8HSY49V9fqM=; b=anjZU78BjJ1LCcXfxdaoB8ePzWsHMuPyxuiJ8ZFFWGSBQVNNM7khPFidZG+E+Yf3AT 73YWis7vxjWdijcN0weaeMtL4fUzT9dzGRxG1g1swlwIAYeq/mEZhzQNYg1RfkxPncLL 3dfiWU6OSPEihdd/3vDOFMvfuMSBEHnfjjuNKbb1Lwu9R7Ttczdq1Zs845Uy27ZSZJCk +paBPsLG53U+6YUVpmpCO53aQx4elADGHEhOvU8iwdNCyLeb0stFzssSu9EMVz/pQS1h +ovxVO/zfggsB/gANMiGYc4Q+zv3X+WPJ11b266cR8fvIc2mVOLArzbkGIG4nEEfSpmQ 5XfA== X-Gm-Message-State: ALoCoQmvXAIGxUh+dEX10qfbIxuZMu6UwdN3zmgnuw4mI/yrgX4UY3JHqcs/tOrR04E0GbQ+7uTD X-Received: by 10.68.194.106 with SMTP id hv10mr8509527pbc.50.1418970572997; Thu, 18 Dec 2014 22:29:32 -0800 (PST) Received: from mew.localdomain ([72.192.100.38]) by mx.google.com with ESMTPSA id eo4sm8421786pbb.87.2014.12.18.22.29.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Dec 2014 22:29:32 -0800 (PST) From: Omar Sandoval To: Trond Myklebust , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Al Viro , linux-fsdevel@vger.kernel.org, Omar Sandoval Subject: [PATCH] nfs: prevent truncate on active swapfile Date: Thu, 18 Dec 2014 22:29:18 -0800 Message-Id: <13e8abe52a18c4e46ce497ff299774700cd7e1d0.1418970310.git.osandov@osandov.com> X-Mailer: git-send-email 2.2.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most filesystems prevent truncation of an active swapfile by way of inode_newsize_ok, called from inode_change_ok. NFS doesn't call either from nfs_setattr, presumably because most of these checks are expected to be done server-side. However, the IS_SWAPFILE check can only be done client-side, and not doing so is dangerous. Signed-off-by: Omar Sandoval --- fs/nfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 4bffe63..9205513 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -506,10 +506,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~ATTR_MODE; if (attr->ia_valid & ATTR_SIZE) { + loff_t i_size; + BUG_ON(!S_ISREG(inode->i_mode)); - if (attr->ia_size == i_size_read(inode)) + i_size = i_size_read(inode); + if (attr->ia_size == i_size) attr->ia_valid &= ~ATTR_SIZE; + else if (attr->ia_size < i_size && IS_SWAPFILE(inode)) + return -ETXTBSY; } /* Optimization: if the end result is no change, don't RPC */