Received: by 10.213.65.68 with SMTP id h4csp1736194imn; Mon, 19 Mar 2018 11:51:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELsqFrGkeHMOXX2cEGltR4qEi8bQFZ62QO7QykWmamcbp3q5pGQZBHO8O8PXLgjG8WUB8aHB X-Received: by 2002:a17:902:8212:: with SMTP id x18-v6mr3593055pln.372.1521485499909; Mon, 19 Mar 2018 11:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521485499; cv=none; d=google.com; s=arc-20160816; b=NLiutIS+pvVsOvFJULcxnofROqixWhJ2eWgqgZo1BRkvHHpZzREm5kLPqnOtKGcqUv XsdMbWTyNCrWrYRxgKDrJBVWg10RrLWGkvQ9U3T26et1ulbjdELdt1a3bus0gcN/ozpL +SJwxv4tbnG7GnsiOz4DRXGCRRd2AUJGU3c1BnT+t3/NhLbUljIusfbgGXCHSxS2n1gT PjOrXsDKoEWiiCrUKJjGJyKW3RZcw3HhViXKi/C0HHTArfYXlzD19OLZHbuMYYlEWF2Y Wt+JAIG4vpAOS58KdpunRcuYYGRJe9rB/i3wXI9mf6jWrRdP64GOEwOnYPUNTOpENbUW KhSw== 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=YT5+8kgjGuKUW2Ev+0yFFgmIHyvR362RKl5fggnN33w=; b=PlDU/pDLJPdL9wKYSq+Pj8GLq5AejcCNiuorAvBH6MSUE8g/pXVpVMeOFdMQUl0PIO U2CZs1KktRQZQouTZMIXFmcdIbxy8XEiV13rVMjbpCG5/5bPgLMJbjRiSlrNPy8rUfSg uCDpymiFileVUUdPnmpsWf2d7/a2JDDGisI8eqNeIawhsnoeRCDXvoxepcvcdnUiaSV7 S59bdBV9NItpHswvGfxgZsTtTpV+rVnCwvWsnd7nYhjYzZYnwtJXNZ8au7qNZ6Fpy/Hk 79965rlFhrdzWvl0Hxl7RjkoNEjvkEfEs6HjizYxFevYCox2eNa0N7Bm1ZKlzUoVji87 xhIQ== 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 t9-v6si444606plr.558.2018.03.19.11.51.25; Mon, 19 Mar 2018 11:51:39 -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 S970471AbeCSSt5 (ORCPT + 99 others); Mon, 19 Mar 2018 14:49:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53322 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032008AbeCSSat (ORCPT ); Mon, 19 Mar 2018 14:30:49 -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 97F13127F; Mon, 19 Mar 2018 18:30:48 +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.14 25/41] lock_parent() needs to recheck if dentry got __dentry_killed under it Date: Mon, 19 Mar 2018 19:08:25 +0100 Message-Id: <20180319180733.882419104@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180732.195217948@linuxfoundation.org> References: <20180319180732.195217948@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.14-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 @@ -644,11 +644,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; }