From patchwork Fri Jan 24 20:47:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 3536001 Return-Path: X-Original-To: patchwork-ocfs2-devel@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 946689F1C3 for ; Fri, 24 Jan 2014 20:48:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74B032011B for ; Fri, 24 Jan 2014 20:48:32 +0000 (UTC) Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B368E2015D for ; Fri, 24 Jan 2014 20:48:27 +0000 (UTC) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s0OKm1oM027202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 24 Jan 2014 20:48:02 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0OKm10K029502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 24 Jan 2014 20:48:01 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1W6nfV-0003nP-50; Fri, 24 Jan 2014 12:48:01 -0800 Received: from ucsinet21.oracle.com ([156.151.31.93]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1W6nef-0003hx-HX for ocfs2-devel@oss.oracle.com; Fri, 24 Jan 2014 12:47:09 -0800 Received: from userp1020.oracle.com (userp1020.oracle.com [156.151.31.79]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0OKl8Cx029874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 24 Jan 2014 20:47:09 GMT Received: from mail-ie0-f202.google.com (mail-ie0-f202.google.com [209.85.223.202]) by userp1020.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s0OKl7N9002290 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 24 Jan 2014 20:47:08 GMT Received: by mail-ie0-f202.google.com with SMTP id x13so626832ief.1 for ; Fri, 24 Jan 2014 12:47:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:cc:from:date:mime-version :content-type:content-transfer-encoding:message-id; bh=hjww6R9WvhWOQiQow3yDYtlp/cOp7w8EkpelWKO+w4k=; b=HdC9D8boDZSfzNENR78YZx4K1ijg7yw2fZo6Ry+AKUg6AoOxzE9BlDbwKujhvCk0wn Vv+SmsR5Koc1BoD80hO+7aM7WwkRjKdELnNsLy9zrk7MflV/TsT+2vOX1+cQzNHbKI9v JkT+midHE8L9d0zMMhnr0eCwb76HUFJcvzF3jCbLH7amb3b7bsW4Ze4zymf7/xrlYilj xZgIon2DZx0BXMgaP97tLr5hCkzi9XYl6Zr0X6z4ZsUlf6DxR+lYAXCWkA1xvU5arbkT 0GeYGYQEsuct0ILTl13i85YeaTWrWOKJh8vg5VIhWrenDRaNUsljjAAjrcBaBR0YcxLE R7CA== X-Gm-Message-State: ALoCoQk0n/+q2VcBDRLH5sIIc8pzjQrluxRfAZ0PpfClJ9zkhU0MKNtPVSz9KCf3V77Cz9TrVZA2 X-Received: by 10.43.78.135 with SMTP id zm7mr100493icb.27.1390596427795; Fri, 24 Jan 2014 12:47:07 -0800 (PST) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id m69si144806yhc.7.2014.01.24.12.47.07 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jan 2014 12:47:07 -0800 (PST) Received: from localhost.localdomain (akpm3.mtv.corp.google.com [172.17.131.127]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 2470E5A4203; Fri, 24 Jan 2014 12:47:07 -0800 (PST) To: ocfs2-devel@oss.oracle.com From: akpm@linux-foundation.org Date: Fri, 24 Jan 2014 12:47:06 -0800 MIME-Version: 1.0 Message-Id: <20140124204707.2470E5A4203@corp2gmr1-2.hot.corp.google.com> X-Flow-Control-Info: class=Pass-to-MM reputation=ipRisk-All ip=209.85.223.202 ct-class=R5 ct-vol1=-78 ct-vol2=7 ct-vol3=6 ct-risk=56 ct-spam1=89 ct-spam2=9 ct-bulk=14 rcpts=1 size=2327 X-SPF-Info: PASS::mail-ie0-f202.google.com X-Sendmail-CM-Score: 0.00% X-Sendmail-CM-Analysis: v=2.1 cv=YfaEuWhf c=1 sm=1 tr=0 a=0QG7fH4k8TRlhTEV/OxrCw==:117 a=r2HxzhWH0FAA:10 a=NEiEQogP1MkA:10 a=os2CZ2fo8YAA:10 a=Z4Rwk6OoAAAA:8 a=1XWaLZrsAAAA:8 a=yPCof4ZbAAAA:8 a=5bH_KOMe22MA:10 a=i0EeH86SAAAA:8 a=IXr_WNlcAAAA:8 a=iox4zFpeAAAA:8 a=VER7GWbB_1zR0UNmpRAA:9 a=e4xtJxf3HDoA:10 a=hPjdaMEvmhQA:10 a=T5ZRoNnfl4MA:10 a=n9GBPR9yFnkA:10 a=jbrJJM5MRmoA:10 X-Sendmail-CT-Classification: not spam X-Sendmail-CT-RefID: str=0001.0A090207.52E2D14C.00EB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 Cc: mfasheh@suse.com Subject: [Ocfs2-devel] [patch 07/11] ocfs2: check existence of old dentry in ocfs2_link() X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Xue jiufei Subject: ocfs2: check existence of old dentry in ocfs2_link() System call linkat first calls user_path_at(), check the existence of old dentry, and then calls vfs_link()->ocfs2_link() to do the actual work. There may exist a race when Node A create a hard link for file while node B rm it. Node A Node B user_path_at() ->ocfs2_lookup(), find old dentry exist rm file, add inode say inodeA to orphan_dir call ocfs2_link(),create a hard link for inodeA. rm the link, add inodeA to orphan_dir again When orphan_scan work start, it calls ocfs2_queue_orphans() to do the main work. It first tranverses entrys in orphan_dir, linking all inodes in this orphan_dir to a list look like this: inodeA->inodeB->...->inodeA When tranvering this list, it will fall into loop, calling iput() again and again. And finally trigger BUG_ON(inode->i_state & I_CLEAR). Signed-off-by: joyce Cc: Joel Becker Cc: Mark Fasheh Signed-off-by: Andrew Morton Signed-off-by: Mark Fasheh --- fs/ocfs2/namei.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff -puN fs/ocfs2/namei.c~ocfs2-check-existence-of-old-dentry-in-ocfs2_link fs/ocfs2/namei.c --- a/fs/ocfs2/namei.c~ocfs2-check-existence-of-old-dentry-in-ocfs2_link +++ a/fs/ocfs2/namei.c @@ -644,6 +644,7 @@ static int ocfs2_link(struct dentry *old struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); struct ocfs2_dir_lookup_result lookup = { NULL, }; sigset_t oldset; + u64 old_de_ino; trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno, old_dentry->d_name.len, old_dentry->d_name.name, @@ -665,6 +666,18 @@ static int ocfs2_link(struct dentry *old err = -ENOENT; goto out; } + + err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name, + old_dentry->d_name.len, &old_de_ino); + if (err) { + err = -ENOENT; + goto out; + } + + if (old_de_ino != OCFS2_I(inode)->ip_blkno) { + err = -ENOENT; + goto out; + } err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, dentry->d_name.len);