Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp726362imm; Wed, 17 Oct 2018 07:24:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV61kmvRsUW8riDrWqTrNIi0LRqCPHGI0KEF2HsdHIFAxBOKSG+rRnj+etb7cr286wsQmPNbp X-Received: by 2002:a63:40c2:: with SMTP id n185-v6mr24958657pga.116.1539786263973; Wed, 17 Oct 2018 07:24:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539786263; cv=none; d=google.com; s=arc-20160816; b=R/asWQenK6IGjvycYby7tmhKevNOm8o8/vSbZCuXTnt6hP441SyHF5r60eZoKZ9WEy At1ANS/vUYWXPvZbY/rq4NFGFar/7L3Ib9kp4UjjMnkldURVhDUvERlzMHP2+1lx6GHW lauo9hdB1BR/AV3gLjVpVWThG117Cu00CETuxFCTzLQC5/uToPDwYDURCUzYwFru1Rgp BpyA1NtIGRPUoVfockFFhl58avX6EZZ4kj6V/MU+O/UPdpQK74pnHbj/FVm3zLolaU7B n7L210yvQ6L0yZqTrsKzKcpElatj+KgAIaUykHniHW40C8k6I85ny9dNB1Xe8bAWPq24 GIHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=8a2N8SPFfvaxO0Y5LNfSPKKTq4A0AC6cctVlhOYnsEc=; b=bmTl0F9IRTIQy95n5IJQN5Tgl9/R/gs2nu1QIFnf2nwkzG46xnJ6b/oSG8LZpVGDwf rr0TKnncZoo0dMmtQe+J3VZHvQu9dZV6/J1c9Hixa6/MOtaYYjyD2s4PtSt10+KWy4Xw LUY/Dzvp1G20CRoXGIp74LxeKTRLtKpyEIG2lnnjuMPOGeRNKJdsNCPOCIec+uqzTVl8 vWdXcvs363IS8Pnga3tPMOa4o7c5PHDr5vZf6i8s92qlCt7t4ETNHs1irIbWMPAP6IeH GJUB4TAKuYRdTV+Qdzi0smIV3DLJ9bEsNhzw31jMa7RlktkOGrXIjA1bzMJgblbKTi0h KmFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6-v6si18445785plf.164.2018.10.17.07.24.07; Wed, 17 Oct 2018 07:24:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727708AbeJQWT2 (ORCPT + 99 others); Wed, 17 Oct 2018 18:19:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3428 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbeJQWT2 (ORCPT ); Wed, 17 Oct 2018 18:19:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBBB630820D1; Wed, 17 Oct 2018 14:23:32 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-250.rdu2.redhat.com [10.10.120.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E45A2B5AC; Wed, 17 Oct 2018 14:23:27 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/4] cachefiles: fix the race between cachefiles_bury_object() and rmdir(2) From: David Howells To: gregkh@linux-foundation.org Cc: stable@vger.kernel.org, Al Viro , viro@zeniv.linux.org.uk, sandeen@redhat.com, dhowells@redhat.com, linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 17 Oct 2018 15:23:26 +0100 Message-ID: <153978620674.8478.12752931380482175663.stgit@warthog.procyon.org.uk> In-Reply-To: <153978619457.8478.3813964117489247515.stgit@warthog.procyon.org.uk> References: <153978619457.8478.3813964117489247515.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 17 Oct 2018 14:23:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro the victim might've been rmdir'ed just before the lock_rename(); unlike the normal callers, we do not look the source up after the parents are locked - we know it beforehand and just recheck that it's still the child of what used to be its parent. Unfortunately, the check is too weak - we don't spot a dead directory since its ->d_parent is unchanged, dentry is positive, etc. So we sail all the way to ->rename(), with hosting filesystems _not_ expecting to be asked renaming an rmdir'ed subdirectory. The fix is easy, fortunately - the lock on parent is sufficient for making IS_DEADDIR() on child safe. Cc: stable@vger.kernel.org Fixes: 9ae326a69004 (CacheFiles: A cache that backs onto a mounted filesystem) Signed-off-by: Al Viro Signed-off-by: David Howells --- fs/cachefiles/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index af2b17b21b94..95983c744164 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -343,7 +343,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache, trap = lock_rename(cache->graveyard, dir); /* do some checks before getting the grave dentry */ - if (rep->d_parent != dir) { + if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) { /* the entry was probably culled when we dropped the parent dir * lock */ unlock_rename(cache->graveyard, dir);