From patchwork Tue Nov 7 20:50:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10047239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C615560360 for ; Tue, 7 Nov 2017 20:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90D3290B0 for ; Tue, 7 Nov 2017 20:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC7FB292C0; Tue, 7 Nov 2017 20:49:22 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 26B92290B0 for ; Tue, 7 Nov 2017 20:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933481AbdKGUtU (ORCPT ); Tue, 7 Nov 2017 15:49:20 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:45853 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932298AbdKGUtT (ORCPT ); Tue, 7 Nov 2017 15:49:19 -0500 Received: by mail-wm0-f66.google.com with SMTP id y80so6419769wmd.0; Tue, 07 Nov 2017 12:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=z49PUq2/KiQZgDeBqRuCgFS+4F++qbfesRmh2dl2zcw=; b=O5z4jUX3t2OsMgC5UP4sfrcJWpgRlPxgWz7COD2cT7konDAWczC6UuhFhTXQCXdOOr ykKXnorhxIs8+uXCHj76iZXHYWeT94jRDGR8WsEFg5zzM0NvvFxB2qSc/wWohzyY8uPn enH+CGyhUt/gMHDzm+ZUPyd53RW9gw6V+riCTqw6lCLPYmQJuDQEaRCNkJUuThfnueAc 5vH64N/Wsz7yoezT6f8UW0eoRZFAaUusp4uteAuS7lrszx/XiILCbAtklgEFrUrZDHG3 f2/Z9LTiJkb+47r8Hi2kcPVsJRzwyEBn7wHhVTOCRJ3Zc7FAWDblB36q7+qNNnieW9kJ DfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z49PUq2/KiQZgDeBqRuCgFS+4F++qbfesRmh2dl2zcw=; b=M3sSf3PNzmvO6O+HFHKxa0ZiL54wolHzo/kUurF+fX8NH47s2ghkeOQOFrsfAx0OMj ByiyzrxfnvqNfIiGwLVbFS2Gb01oQ+NRkrzSk08w9xX5Rt/VLD5Z+MYz4EQtLwjVeBUb OXLjI8SCocyDKzSCMVJzbXySmAXQtAEoWN+v94L1IOyHrZiB+aapNcHM6b3IJM0oBCZd 4sA98JnLlQQFGEyvyVvjeyYIkVNfPepkXs85P6aqXVsiFF6kIbnQHlwOPPM7EJKeBwu5 c2QERzWJDtOZm0NLuuXDEeQNnOTUpuQuNq+WlcieCLZhzmn/53fCVt8M3e8y1JQRbVG1 a/cQ== X-Gm-Message-State: AJaThX7nYnEqVZpf1kL12cZCLHGznZ8+VJB4LOIXxrLXXF6FikAuYSrY LUgQa8lFfCD8/SboLdNWgmQ= X-Google-Smtp-Source: ABhQp+QGf0VG8KiL8kTmg6OtLZr16zkvijfK1bbgrhORedEefps66NA1IyP5+NRMnGqEDryanZbVtQ== X-Received: by 10.28.37.195 with SMTP id l186mr364477wml.144.1510087758070; Tue, 07 Nov 2017 12:49:18 -0800 (PST) Received: from localhost.localdomain ([31.210.182.123]) by smtp.gmail.com with ESMTPSA id 185sm2603441wmq.22.2017.11.07.12.49.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Nov 2017 12:49:16 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Jeff Layton , "J . Bruce Fields" , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hugh Dickins , Al Viro Subject: [PATCH] tmpfs: allow decoding a file handle of an unlinked file Date: Tue, 7 Nov 2017 22:50:01 +0200 Message-Id: <1510087801-20663-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP tmpfs uses the helper d_find_alias() to find a dentry from a decoded inode, but d_find_alias() skips unhashed dentries, so unlinked files cannot be decoded from a file handle. This can be reproduced using xfstests test program open_by_handle: $ open_by handle -c /tmp/testdir $ open_by_handle -dk /tmp/testdir open_by_handle(/tmp/testdir/file000000) returned 116 incorrectly on an unlinked open file! To fix this, use a variant of d_find_alias() that returns any alias, even an unhashed one. Cc: Hugh Dickins Cc: Al Viro Signed-off-by: Amir Goldstein --- mm/shmem.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) Miklos, Please see if that patch looks correct. Bruce and Jeff indicated that the current tmpfs behavior is not desirable for nfsd. It may be uncommon to export a tmpfs, but it is going to become a lot more common when exporting an overlayfs with upper tmpfs. Thanks, Amir. diff --git a/mm/shmem.c b/mm/shmem.c index 07a1d22807be..f7c555ebf0f2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3404,6 +3404,26 @@ static int shmem_match(struct inode *ino, void *vfh) return ino->i_ino == inum && fh[0] == ino->i_generation; } +/* Find any alias of inode, even an unhashed one */ +static struct dentry *shmem_find_alias(struct inode *inode) +{ + struct dentry *alias; + + spin_lock(&inode->i_lock); + hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { + dget(alias); + if (alias->d_inode == inode) { + spin_unlock(&inode->i_lock); + return alias; + } + dput(alias); + } + spin_unlock(&inode->i_lock); + + return NULL; +} + + static struct dentry *shmem_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { @@ -3420,7 +3440,7 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb, inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]), shmem_match, fid->raw); if (inode) { - dentry = d_find_alias(inode); + dentry = shmem_find_alias(inode); iput(inode); }