From patchwork Mon Apr 23 20:25:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10358099 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 A2DB36038F for ; Mon, 23 Apr 2018 20:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9448128C2F for ; Mon, 23 Apr 2018 20:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88E9A28C42; Mon, 23 Apr 2018 20:25:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 3CAA428C2F for ; Mon, 23 Apr 2018 20:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755165AbeDWUZy (ORCPT ); Mon, 23 Apr 2018 16:25:54 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:32945 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbeDWUZx (ORCPT ); Mon, 23 Apr 2018 16:25:53 -0400 Received: by mail-yw0-f196.google.com with SMTP id g16-v6so1905000ywk.0; Mon, 23 Apr 2018 13:25:53 -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:cc; bh=7fDqoZJlfbn43cxC8VVcxtN/5bqUIV4zu8hKxuiBgUY=; b=jbbI9qGXDhNgjsEBwvPopPSt6ZxGhqzlvyJizUtYdaHsCp5A8PKkbmDXVjFKlHe5lV i11QYHubeysWTnaat/ZZd1N/nQlCoBv0nvqqc99dnQawoUzieCvT9ZXjJi/HaRdekkxJ cI8/zO+SlQBhYvbNoSgKTYrN5vIYG01qrtGX3/hZG6rT1b9dQXVxbPBJ+L5JlgLnazyX 3qb1UwGGCFgD2F3IqnYfNwRIiHwYJai8ynAfOD52YXYfPHE0jqT43IYdMWEnJKVc+V9Q qpouo6urHuZcYoLrhnKYGZ1JgxBvr4g74dzhI72N3N+j7agn8otBJ37cBi/dYjoNHx1Q KITA== 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:cc; bh=7fDqoZJlfbn43cxC8VVcxtN/5bqUIV4zu8hKxuiBgUY=; b=XljQm09yBQWxIhkkURILBsorrD/pbDOy1/wZm3j4ormOXXUrpGw582nhUxZDjKgdEA 5Kum8kp5IDEwY7CFHA/Gva+xA/HJZBWYF/ZSxgsUbhxRLmWHTVpsrTlNUZXNctONf1qj Oieu09yrZ90bgP2u+zkVk2ohmB/OwmpgD8ViTPX10zC+uYoVNJjb0FUEwnAwO/ne3k7J 6Y1j0nhfxmLl7gSoy+P3kNmJQey+e5ysMbLkKCK+X/iWbkrY00npoCWavlu39jkKQ2xu pZVc4ZGjH2RlLG8LL1+VW+EldVlc1rlwsbEZ+w/90k09nd5DgbcdVcxlSz253Axsp1NC p5Ww== X-Gm-Message-State: ALQs6tDkCL5kt4oKA45DO69BWDn3BJCYU0XQKD01NSMlnKbkY9GW0gNx 8yo4o49LWd3I1/S3jm76aPUZ70Yi/zJrvc/Lif+8Pg== X-Google-Smtp-Source: AIpwx4/im+C4ptcLmlBDdlzYwManTJkHmq066GM6Mt3evsdPT5aNwIDb3DyU6HU3Yce/TLXNqVmxt+zzKMMjNrOJQ3c= X-Received: by 2002:a0d:e801:: with SMTP id r1-v6mr8744156ywe.294.1524515153130; Mon, 23 Apr 2018 13:25:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.37.209 with HTTP; Mon, 23 Apr 2018 13:25:52 -0700 (PDT) From: Amir Goldstein Date: Mon, 23 Apr 2018 13:25:52 -0700 Message-ID: Subject: [RESEND PATCH v2] tmpfs: allow decoding a file handle of an unlinked file To: Andrew Morton Cc: Neil Brown , Hugh Dickins , linux-fsdevel , Linux NFS Mailing List , Jeff Layton , "J. Bruce Fields" , Al Viro 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, if d_find_alias() can't find a hashed alias, call d_find_any_alias() to return an unhashed one. Cc: Hugh Dickins Cc: Al Viro Signed-off-by: Amir Goldstein Reviewed-by: NeilBrown --- Hi Andrew, I was nudging Hugh over at LSF/MM about this patch and he has suggested that I send it to you, because he has no idea about the exportfs parts. The test for decoding a file handle of an unlinked file has already been merged to xfstest generic/467 and the test is failing on tmpfs without this change. Can you please take this patch. Thanks, Amir. mm/shmem.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/mm/shmem.c b/mm/shmem.c index 07a1d22807be..5d3fa4099f54 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3404,6 +3404,15 @@ static int shmem_match(struct inode *ino, void *vfh) return ino->i_ino == inum && fh[0] == ino->i_generation; } +/* Find any alias of inode, but prefer a hashed alias */ +static struct dentry *shmem_find_alias(struct inode *inode) +{ + struct dentry *alias = d_find_alias(inode); + + return alias ?: d_find_any_alias(inode); +} + + static struct dentry *shmem_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { @@ -3420,7 +3429,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); }