Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2976335imu; Sun, 9 Dec 2018 14:06:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/V+g2qC5ZdXvQCqyTVasqN9vcu0KocfetgaTPnolMRurBhq+2uh8Y5XWoZi6C1TfqsIGRfL X-Received: by 2002:a63:6b05:: with SMTP id g5mr8585567pgc.15.1544393191648; Sun, 09 Dec 2018 14:06:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393191; cv=none; d=google.com; s=arc-20160816; b=0b0pEUFmjLUjKCnnxKPdD3WtOdeDC60NFluuytL0uejGlghd1M+pMP2nWntYUrp5OI lShvKRHH055CVMtz3DytPYyb1kLJwvTEEyX9GZevol+GdTClp62RnOydlcWGDnQME8Dz ZJxbKpf+JxYN1VkcOyXYdF2+7We29DeEEvXKrl+d9TKEnZ66x+2ujfM2UF7okDlD/5hD KG0Qn0scICCbJgUEqzDVWITb+V9zLUxmA1mO1ONh+LfXL7GtpwQhlnyfM3a3g3fuByOT 69DFmmHtCmpi7K7y8EFHLswb40PwMCX47zy/Ofd+TQ9l/KbOzaaqIjpq0b1JzvSNBk6+ z2tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=2d3LURXkEAgSnSC3x0TGJDCGi550R5wvbv89gb8cuF8=; b=I9yXuTh2h9tf4KjiAZg9WKhc9K1h036oMtHz6SfzWv6D8e/QgegP4iJfVoCcWFuDJA JWzykOys13IRAIVTqB2nzW1PBBosZXfGQbtke16WSbyNjx903SDjh3Wlbw+nTSoPk00m MWPdLUlIhTvPbzrJLiftIHdDY0+ajtp8W/7bjLtJyk1HOBPKzkHMUTv8ICLOA5tqGuwW oBXDvBSFyUnzoEcffD9xxkmmei69Iq2WzAq6nOp3WpLGfbReIuAAKX1K+CRBWyyZHLwI 5L0YsPx27QEjtW1Zx6LgRSPI6+l5UYzDcUXhpTNtoRpe3aMlif2Eo4gH6WtN5PJ7hulq xQiA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si7561828pgv.123.2018.12.09.14.06.16; Sun, 09 Dec 2018 14:06:31 -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; 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 S1727421AbeLIWDr (ORCPT + 99 others); Sun, 9 Dec 2018 17:03:47 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35620 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726589AbeLIVz2 (ORCPT ); Sun, 9 Dec 2018 16:55:28 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72r-0002il-0M; Sun, 09 Dec 2018 21:55:25 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72l-0003h3-Gw; Sun, 09 Dec 2018 21:55:19 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "David Howells" , "Greg Kroah-Hartman" , "Al Viro" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 317/328] cachefiles: fix the race between cachefiles_bury_object() and rmdir(2) In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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. 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 Signed-off-by: Ben Hutchings --- 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);