Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp607989img; Fri, 22 Mar 2019 05:04:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOtP7MDkaRK8JHF/QHopMw613eiPWadLRby+kmCXPpZoa/IXCjNro+n0rOckpib16UWz2L X-Received: by 2002:a62:5385:: with SMTP id h127mr8562111pfb.10.1553256297160; Fri, 22 Mar 2019 05:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256297; cv=none; d=google.com; s=arc-20160816; b=m9KFlkfURM7bX1tj5FwE/Y+1Pey0HMRG63jitkSuUr6p456kJVaN2q9fE0B8GowCPb IH62yyQ0wlwD/ZEPYbUllXfFf+3mvRRzJp2Hhov0B7Gigv1ybsGieFq2c+AABTa3Y5lu itN02eVtVd+iPMjjBRWtHQzMbchxcN6WqTsmuSM2PzXvct4sWBUHusTO+6cam2klnsGf n4dDHK2ABCrXZYIHEEJD0dn/5AgKzCdoZFp6KmAoikOZ06NdUe/F47HCWePCTPlDUmY1 n1swuumQoh2oxp5Km45jYtHpH5FJmeTp3ZSUggqN+AD2+ObAkR6vCSFnUwQIlgJx0FJL uTNA== 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=Blbd+I6HqsWtliT3/qBadM6kOYsYL2Vu/DkiQ2wTwGI=; b=RSHPnO+fnSQ+QYTLB0QiDsw98mnE7fDOMThc7qDocawiBo1RkMzYhksn3fh1gPF6p1 0IyPg1YW+4HQWkCChCBcBRwD9NfTBiw+qjUHk4iOv7YgMMpLeMLjejt1vb8nOlnGPdtM BRtwgD8fL+TLXjqFCKLYuZxv4DXnfRJ90t7yhJe9QYLlOiSC8fybzX+oPyyl6Y2O+XMt 9oqJmsIqltmjOgyWmlXKk48N45cDWsHRST7Bml7JcwU/JO3nRzquisX4aVCh86o8ZidL TG2IBxEXMJA869WRNzWY6sljpYlZ3ZMs+9jV/MW8uY2tMiYIiNKmcFTzUH946LfjyP0F bBPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RBPJ/JZh"; 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 f2si6671626pgv.10.2019.03.22.05.04.40; Fri, 22 Mar 2019 05:04:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b="RBPJ/JZh"; 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 S2388022AbfCVMDY (ORCPT + 99 others); Fri, 22 Mar 2019 08:03:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:41722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388043AbfCVMDX (ORCPT ); Fri, 22 Mar 2019 08:03:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 D13D5204FD; Fri, 22 Mar 2019 12:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256202; bh=UJ2ahH+WU3dxFLgJ1mQZA3nDylyzrYmxPX5KT0Apu3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RBPJ/JZhvxIg5upGSbIOWu0Tcf20v6zORYjJlizq57n17exl5Uzuaz6RBN/SYeNbG l/o2Rl8xgbXZzhj147XouKV/bAhPZjybNkDNrSBcEvNXfxYnEMPz6lvjnorBAhV0ap mEVmrFYeyfApj7v/AnQwR1rH1+lEC+ZPeoF9wr5s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Al Viro Subject: [PATCH 4.19 121/280] fix cgroup_do_mount() handling of failure exits Date: Fri, 22 Mar 2019 12:14:34 +0100 Message-Id: <20190322111315.074443430@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Al Viro commit 399504e21a10be16dd1408ba0147367d9d82a10c upstream. same story as with last May fixes in sysfs (7b745a4e4051 "unfuck sysfs_mount()"); new_sb is left uninitialized in case of early errors in kernfs_mount_ns() and papering over it by treating any error from kernfs_mount_ns() as equivalent to !new_ns ends up conflating the cases when objects had never been transferred to a superblock with ones when that has happened and resulting new superblock had been dropped. Easily fixed (same way as in sysfs case). Additionally, there's a superblock leak on kernfs_node_dentry() failure *and* a dentry leak inside kernfs_node_dentry() itself - the latter on probably impossible errors, but the former not impossible to trigger (as the matter of fact, injecting allocation failures at that point *does* trigger it). Cc: stable@kernel.org Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/kernfs/mount.c | 8 ++++++-- kernel/cgroup/cgroup.c | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -196,8 +196,10 @@ struct dentry *kernfs_node_dentry(struct return dentry; knparent = find_next_ancestor(kn, NULL); - if (WARN_ON(!knparent)) + if (WARN_ON(!knparent)) { + dput(dentry); return ERR_PTR(-EINVAL); + } do { struct dentry *dtmp; @@ -206,8 +208,10 @@ struct dentry *kernfs_node_dentry(struct if (kn == knparent) return dentry; kntmp = find_next_ancestor(kn, knparent); - if (WARN_ON(!kntmp)) + if (WARN_ON(!kntmp)) { + dput(dentry); return ERR_PTR(-EINVAL); + } dtmp = lookup_one_len_unlocked(kntmp->name, dentry, strlen(kntmp->name)); dput(dentry); --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -1998,7 +1998,7 @@ struct dentry *cgroup_do_mount(struct fi struct cgroup_namespace *ns) { struct dentry *dentry; - bool new_sb; + bool new_sb = false; dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, &new_sb); @@ -2008,6 +2008,7 @@ struct dentry *cgroup_do_mount(struct fi */ if (!IS_ERR(dentry) && ns != &init_cgroup_ns) { struct dentry *nsdentry; + struct super_block *sb = dentry->d_sb; struct cgroup *cgrp; mutex_lock(&cgroup_mutex); @@ -2018,12 +2019,14 @@ struct dentry *cgroup_do_mount(struct fi spin_unlock_irq(&css_set_lock); mutex_unlock(&cgroup_mutex); - nsdentry = kernfs_node_dentry(cgrp->kn, dentry->d_sb); + nsdentry = kernfs_node_dentry(cgrp->kn, sb); dput(dentry); + if (IS_ERR(nsdentry)) + deactivate_locked_super(sb); dentry = nsdentry; } - if (IS_ERR(dentry) || !new_sb) + if (!new_sb) cgroup_put(&root->cgrp); return dentry;