Received: by 10.213.65.68 with SMTP id h4csp39515imn; Mon, 19 Mar 2018 18:50:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELvB9WnGn1ttHjU9Pi9Fk5Fur98MwqIcrIgH0/uuh8rddZvdmhXo8D87AXYRZ+nGv/gxvOJZ X-Received: by 10.98.6.133 with SMTP id 127mr11915289pfg.28.1521510633887; Mon, 19 Mar 2018 18:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510633; cv=none; d=google.com; s=arc-20160816; b=sK83akHNkIGOTsZXqeF2QcJiVRfg4KrTv9sqTnkG2Ve/SVKxrVWR8T+2sO5YzlstOV jJFQXc+4TDvWxTHH9U2EpU3fsQ2Uc8gbRAMU8UWRy0NIGZEpJqdpZf2dzU8p3NSWIwKo HknU6KluxcdnAqdNlFpWt1cJ7Cc8Td2DJrL0sCBQAtQBjAgHK15+PoSbwwXc/rcbY/8g lsn9jAQ6uNZdT7sCLwxtRYBA6vSQo0qZNn5aKbq8SS1FtkZb5C6QVc064KkKcy54/P/o JrDS1szneW8uKYsXZGoXHjqhpb1gyj9/ugWZ2HgsGijmZk60+n/3rpDMihX0fK5eSxgI yhIw== 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=sXcV1SxBDmsp4OSHhQBRIArNmByV77pkosOC2gTJFeE=; b=N0QHuMhUivGHKPxayTvUl48DN3y0GABo53+z6bYbbvCpNjnA1LkO1xMTH6puE0eIvv US0IDMVbzGBmdngakbu7TKcg8EM8r0QuMjf9pu/UasvkFVsXVjUTZyIgIKLjCVPQeQy7 6z0sJiYI3vFOfKz88y7sUGCTJ+qsHJD/iZx21OGygiAWwSG/SKA4/ZSnuxCIpcF8D0TH 6J0wdRn43yVUwNlcMp51YQXlM3DyNqWVT8q9wt+iW1f+o+SkVUQsUR4MROpygaT1tSDe dst0gWc1K/5KKA0fqLJNLZvwPyZK5DIniMMtHuxxrhlKvo30RIFU7XGw02vbD35gtBCw OKEA== 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 g92-v6si495111plg.256.2018.03.19.18.50.20; Mon, 19 Mar 2018 18:50:33 -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 S971100AbeCSUJD (ORCPT + 99 others); Mon, 19 Mar 2018 16:09:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45456 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969110AbeCSSRL (ORCPT ); Mon, 19 Mar 2018 14:17: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 782B0123B; Mon, 19 Mar 2018 18:17: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.4 122/134] lock_parent() needs to recheck if dentry got __dentry_killed under it Date: Mon, 19 Mar 2018 19:06:45 +0100 Message-Id: <20180319171906.890740695@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-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 @@ -634,11 +634,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; }