Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp45768imu; Thu, 8 Nov 2018 14:29:58 -0800 (PST) X-Google-Smtp-Source: AJdET5d64tjEkiv4kSuBMhF5PIAABilOwcY5eVZ74r9hm3UxKBbF1SOqcxxNrFdI/23ffcbHBnR4 X-Received: by 2002:a62:9316:: with SMTP id b22-v6mr6551496pfe.193.1541716198445; Thu, 08 Nov 2018 14:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716198; cv=none; d=google.com; s=arc-20160816; b=OCHqXvw+P5iOL0yk79IyKgvgxej8h4UU9garYYOj5BsK4N0Ex/zO9kBS+1KffLPyl/ GGFUIQrGjzDHDOXfbAEw05iThTAk8eZNzbU9iTqXJCT5KEp0M1Nm8C6+U7u3TinFFiF6 lqXnbKBtcXc7LsXutPAyd1eJ+GEEziQ9ExPPN8xWutDCziojZIXOS/GBm+3K3w7MWfGn nSIZw1HuM9Hr8pLXNY+q9oR3uPHbMmA3QLXXbcKJBKvmNt6GOhmvtVEKAKUciZkg3lQM Y2FdtJ9E598xrQoaAthf598oSo4jOnIUucUiorCTMl86mvXPXKfyUWy5P2uj/AWcIqkw 4/qg== 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:subject:cc:to :from:dkim-signature; bh=IFbNuJ38oq/jTlCzgEkbUVNIxrBDdEvGpN74VZ7RATI=; b=OIsF2PYlRWoXEIhmViRPOWD6rrDcfN9vJHig4VPn44Wkh1oDW+kFP97CUvYDLxGIcg irCgHXJxfG7M1zrRQZl/Rj68ayeYzwvHF7DyBV3HW7TELfW6kT/waHKxNOxAFeS7xZci tAsvvwOPG2Jqd9All3q29n2omevlMbDyNAvb3yV2BCbxA2T4Zi2iwOjxyTJDcgBmXDXL QbT6FXli/rDP4ZFi7GIk0yBvM12mjfJ8vdjn4GPhNVq0kjzP1VSocgPmZ5pipEeHmuT2 QTmVhc+IGOiFVYhS+04v54lcUzT2H4LhDUYFe+vJ5LVL1qyJJPPETRiu/qHx34IoytvD XrWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1nLL8Gll; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si4941411pgg.1.2018.11.08.14.29.39; Thu, 08 Nov 2018 14:29:58 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=1nLL8Gll; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730808AbeKIHih (ORCPT + 99 others); Fri, 9 Nov 2018 02:38:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:57990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728491AbeKIHig (ORCPT ); Fri, 9 Nov 2018 02:38:36 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E478521019; Thu, 8 Nov 2018 22:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714468; bh=ZZmmqm4tgWLLx5WwXOmvqZxIiPdwvpFg2Agi+5J9BUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1nLL8GllJiOwoDrHPmV+Ff2azBLnj/FLjCdFxQV6mQt1VHwVkd0UNvggI30Y7vs98 xyAXUpXoY1RB1OcEamJSVLcAabalMqws/RpxOItAq4u2HzCw26NNESvwxXECooDCZP D3lH677nd82FyGRMteMQTgEQ2G0C3Nt6bKmWqJNI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , David Howells Subject: [PATCH 4.4 104/114] cachefiles: fix the race between cachefiles_bury_object() and rmdir(2) Date: Thu, 8 Nov 2018 13:51:59 -0800 Message-Id: <20181108215110.180957173@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Al Viro commit 169b803397499be85bdd1e3d07d6f5e3d4bd669e upstream. 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 Signed-off-by: Greg Kroah-Hartman --- fs/cachefiles/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -317,7 +317,7 @@ try_again: 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);