From patchwork Thu Jan 8 09:18:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5591491 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A6693BF6C3 for ; Thu, 8 Jan 2015 09:19:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE71620384 for ; Thu, 8 Jan 2015 09:19:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F14E420382 for ; Thu, 8 Jan 2015 09:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbbAHJS7 (ORCPT ); Thu, 8 Jan 2015 04:18:59 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:64893 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753247AbbAHJS5 (ORCPT ); Thu, 8 Jan 2015 04:18:57 -0500 Received: by mail-pa0-f49.google.com with SMTP id eu11so10603343pac.8 for ; Thu, 08 Jan 2015 01:18:56 -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=Uf8evfAZmnCi0ghDVmUYhWy23p6Hk1RfGcr5Fok5ALI=; b=In9yzx255lo2eY3cAf3g54K1RyXE0vlNh3rwx4MWHs/d9Vegd5Fb09I4P4LLv1quzz zIRzycRefiK5ZmG/TA0ietCeTwE9PwhoLw8thnIVL0RxMmkVYMYBjG2UXuZ12YTNm57r HPkPFLVaCYLquUiv3L7TvSE3UqbcImnADoDVnBfVXPVbIPv5y6YISdg3Xqf1IoAh6mgx +lSd3Bs7FBxt6mxuHPGC9w1ZR2v9snexjyKqrHCJDfWVKBlyOmZpnXREMxQgCnJTFQ9h IjA+hvjze3xIqVAC3dG2wgLjaAsK3YcQHpGG1dhJk8udz6tf3oYIJCJkwqj+m+pTFWL+ S/6Q== X-Gm-Message-State: ALoCoQlPJcd1TQ7cR220jJLKj0zAKr3A1TYOINa0YzJ0ZRdDc/GoPneM6ZeFwLobKslv66/8XQvB X-Received: by 10.70.61.130 with SMTP id p2mr4504409pdr.0.1420708736664; Thu, 08 Jan 2015 01:18:56 -0800 (PST) Received: from mew.localdomain (c-76-104-211-44.hsd1.wa.comcast.net. [76.104.211.44]) by mx.google.com with ESMTPSA id rf7sm3995370pab.3.2015.01.08.01.18.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jan 2015 01:18:56 -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 RESEND] nfs: prevent truncate on active swapfile Date: Thu, 8 Jan 2015 01:18:30 -0800 Message-Id: X-Mailer: git-send-email 2.2.1 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 truncating a swapfile can't possibly be good. Signed-off-by: Omar Sandoval --- Hi, Trond, Now that the holidays are over, could you take a look at this? It was generated against v3.19-rc3. Thanks! 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 */