From patchwork Tue Mar 22 13:17:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 8642441 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C428F9F3D1 for ; Tue, 22 Mar 2016 13:16:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D619B202A1 for ; Tue, 22 Mar 2016 13:16:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9E932012D for ; Tue, 22 Mar 2016 13:16:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759103AbcCVNQe (ORCPT ); Tue, 22 Mar 2016 09:16:34 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35066 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758705AbcCVNQY (ORCPT ); Tue, 22 Mar 2016 09:16:24 -0400 Received: by mail-wm0-f46.google.com with SMTP id l68so152425540wml.0 for ; Tue, 22 Mar 2016 06:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=7VPPoTY+DqJHc+p94aVt9eFxuTXyHwGkfxlQ4RdC33Y=; b=l9q7UwLadTOLg3Vm6Awecc8rSy7DnLvtslFk62GNIILw5zRd68+Kt6r+3qM3btTUAY Z1vm9ydFx3SxZ7zfGPe8docOvPOQMsbBA42/TmOVWPnjHTH0RKLsTg5ydwNev+7r4i94 /Yfo48fB4mz6OtjDpoAFPWbaJA/YL94Pwvp7U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=7VPPoTY+DqJHc+p94aVt9eFxuTXyHwGkfxlQ4RdC33Y=; b=AoWC9/MgS4PK569YmZL8BiK4/baxGXW4u1/UCo+hvItoguaCL2yF5pPeGRTdJI9aik XgWPpBIX6p1GFJDIIEjGRh+Njsf5700alMG6ji2ycRoFvrESztt8KATzuno+zMHT24zx XRkMFQwQM70xOJ50chwgbqHZn02xn9Ego2AvYpfcTqoOkNih5166a5X8syLN97sxgwIo dxJ2m4uyXJzbtGY3jgmwqSrDjlP4Bmkj4V5851o6CLsv3QboemoE/HAbZ7EXaQyHVuZy VNWZ1uU2X7CgnFBAnImwQczDBp12DFCJvrbq0Doz11w1nXHJrwLLk2fX/NoUbp1fkK7a hhMA== X-Gm-Message-State: AD7BkJKLe3wD2dqaYmd/Lj7hjFRV23CiQZQYkK+WJ91kMQ0CzzE3vuhM88qblYXy5Qyp3w== X-Received: by 10.28.131.141 with SMTP id f135mr19963057wmd.33.1458652582725; Tue, 22 Mar 2016 06:16:22 -0700 (PDT) Received: from tucsk (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id i5sm30163063wja.23.2016.03.22.06.16.21 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 06:16:22 -0700 (PDT) Date: Tue, 22 Mar 2016 14:17:42 +0100 From: Miklos Szeredi To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH] vfs: rename: check backing inode being equal Message-ID: <20160322131742.GC11906@tucsk> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,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 If a file is renamed to a hardlink of itself POSIX specifies that rename(2) should do nothing and return success. This condition is checked in vfs_rename(). However it won't detect hard links on overlayfs where these are given separate inodes on the overlayfs layer. Overlayfs itself detects this condition and returns success without doing anything, but then vfs_rename() will proceed as if this was a successful rename (detach_mounts(), d_move()). The correct thing to do is to detect this condition before even calling into overlayfs. This patch does this by checking for DCACHE_OP_SELECT_INODE and getting the underlying inode in that case. Signed-off-by: Miklos Szeredi Cc: # v4.2+ --- fs/namei.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/fs/namei.c +++ b/fs/namei.c @@ -4150,6 +4150,17 @@ SYSCALL_DEFINE2(link, const char __user return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0); } +static struct inode *backing_inode(struct dentry *dentry) +{ + struct inode *inode = d_inode(dentry); + + if (inode && dentry->d_flags & DCACHE_OP_SELECT_INODE) { + inode = dentry->d_op->d_select_inode(dentry, 0); + WARN_ON(IS_ERR(inode)); + } + return inode; +} + /** * vfs_rename - rename a filesystem object * @old_dir: parent of source @@ -4211,7 +4222,7 @@ int vfs_rename(struct inode *old_dir, st bool new_is_dir = false; unsigned max_links = new_dir->i_sb->s_max_links; - if (source == target) + if (backing_inode(old_dentry) == backing_inode(new_dentry)) return 0; error = may_delete(old_dir, old_dentry, is_dir);