Received: by 10.213.65.68 with SMTP id h4csp1748061imn; Mon, 19 Mar 2018 12:10:04 -0700 (PDT) X-Google-Smtp-Source: AG47ELsqXgD5OYKI1t/3/bi54JlYfYnkhWJgyn9Z7okvDGL3nYMauZHvyN6zYF+DOP+djT0zMBm/ X-Received: by 2002:a17:902:2e:: with SMTP id 43-v6mr13543981pla.282.1521486603978; Mon, 19 Mar 2018 12:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521486603; cv=none; d=google.com; s=arc-20160816; b=vChOGGwSbsgRQ4Rxtb26txP/K3hVN9+wIx/Ij0gYYmlnfV4O9SVn/ruNeGFZgjk3b1 GpU/PoiwTjHF6smn59/oUskW3NBbOzgEvey5ZYQpkhgZS+bchAIRZjI8xdC4Z0kTcuZs Dc4L3kOj/pbJOocmX+uyYn/o12CgGhDfcEz1MPeKsw1McMBIoBwM1nP1j9ntR3Ssxn+c ID6veoPkpBnwX8ebHuzGLKNuXSeQ6/W/co58z9l4v4rgClL2BeD9P1bC9mK/cQgVoaG5 33M7rvCUKfaslePb28vtvegyaFzzZC/ky9/GtCpjC3d2qW/U1h72aHJgMxfZaURjTneK kG3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3PBwZxUWfXZB+lcNJQn1OddHiOPSO8breKmQo+NxhzQ=; b=PAURcmjXTHlhLzJy6MDq0ykSamhSOyS1WObxt9vU/MbheyaVa6lj9tfnSIbGTZCllh 41OxSd8GN9YFfLs8SU0BgUoKaslSWeMesoqL/+7qhAtr1Dz/+zB2KKLRse+IGOimqfxn 83jPPLY2tbwdr6sKXO/FVO3fYfCaNUTPcTgoKbgVgOtsPff3aoyGg7SifBfuehScW4Ar 2U57NuMXXDgY+gs6CXmC2KV535M8/6kNcEJRwLzsG/6mdoiy8NP3mIIkLltWvk409uli RDP2qR6jOcG8ZeE1il0mu+A1tXC04Gcqixwtu08e8OBZBgWUxL7gAakBuY/zVi1pw4Qx 7nXQ== 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 y3si373027pgc.601.2018.03.19.12.09.48; Mon, 19 Mar 2018 12:10:03 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031735AbeCSS2Q (ORCPT + 99 others); Mon, 19 Mar 2018 14:28:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51536 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970098AbeCSS2L (ORCPT ); Mon, 19 Mar 2018 14:28:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A108312AB; Mon, 19 Mar 2018 18:28:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro Subject: [PATCH 4.9 229/241] lock_parent() needs to recheck if dentry got __dentry_killed under it Date: Mon, 19 Mar 2018 19:08:14 +0100 Message-Id: <20180319180800.652668687@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Al Viro commit 3b821409632ab778d46e807516b457dfa72736ed upstream. In case when dentry passed to lock_parent() is protected from freeing only by the fact that it's on a shrink list and trylock of parent fails, we could get hit by __dentry_kill() (and subsequent dentry_kill(parent)) between unlocking dentry and locking presumed parent. We need to recheck that dentry is alive once we lock both it and parent *and* postpone rcu_read_unlock() until after that point. Otherwise we could return a pointer to struct dentry that already is rcu-scheduled for freeing, with ->d_lock held on it; caller's subsequent attempt to unlock it can end up with memory corruption. Cc: stable@vger.kernel.org # 3.12+, counting backports Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/dcache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/fs/dcache.c +++ b/fs/dcache.c @@ -637,11 +637,16 @@ again: spin_unlock(&parent->d_lock); goto again; } - rcu_read_unlock(); - if (parent != dentry) + if (parent != dentry) { spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); - else + if (unlikely(dentry->d_lockref.count < 0)) { + spin_unlock(&parent->d_lock); + parent = NULL; + } + } else { parent = NULL; + } + rcu_read_unlock(); return parent; }