From patchwork Wed Jan 2 19:37:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 10746657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9472C14DE for ; Wed, 2 Jan 2019 19:38:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 825E427E01 for ; Wed, 2 Jan 2019 19:38:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7606827F94; Wed, 2 Jan 2019 19:38:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1799B27E01 for ; Wed, 2 Jan 2019 19:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729800AbfABTiA (ORCPT ); Wed, 2 Jan 2019 14:38:00 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42912 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726788AbfABTh7 (ORCPT ); Wed, 2 Jan 2019 14:37:59 -0500 Received: by mail-pg1-f195.google.com with SMTP id d72so14964969pga.9; Wed, 02 Jan 2019 11:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p+5I9DnwcdyPy/DbT58M8zEXLlzj5K5+Ojfg4Kockd4=; b=pQHoNiSIUGlWmeodOUbNo5okEBjA75KEJc8+BiKI4uAGiq/shQkbQcsSVH1uMy7C0Y 18I2zqcj559eAQpjJ2GbCxPzvbJUM1639yMBg+PXLq8Yy5tbxmlewUnD1WKqJHzVhMLs D380vuDg2CJ7qcHC4d6GzR5PT2nheA/7x4uqPKx1B4TZZsBzlL0WLbZ2nHbset3E6Fng QJxR2E/tpcMk1nFxnzjlqAUA9+oXQ52zigIvfRO7C5+64eU7mTjgXcwsdBSC4v3dAqZs 9VYcTTVusE28lgeaTkv2Uv5yRD8DseVtQry+OkxaV3dQPNnVPRjjQ8LFjE6Kr7neBR0T SYHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p+5I9DnwcdyPy/DbT58M8zEXLlzj5K5+Ojfg4Kockd4=; b=UPz6Ego78dogBteD6NLI7Bc0DTXpLHMmFtAJyEOC9aAA4OXcTwuoIb+PNG6ZM9jZMB dujregLAq4WUsAmX0yna9wl+Uo9emBvb+bjvI/zZLmG3GSzlcrdjQ08j2w5MbhN5smOM TTpaUUZbKcgbvDM66lXbOFEkKe7wvqW0q3G0qeE5MYSpgmQcEm+IZVPQxcZjFzfgGFhw dFaFgdz8QAvax66Oc2wcPaAcY+beBkajaW7txKASBl9/m+6Gr9GXh86R19nZBtSq6/Sk ICVk6kYYu2PAK8hGISuwt1f1HL1okBqBk78G1WVTrOIMgMgP9RqNEReVWicexL1IyrCp r28A== X-Gm-Message-State: AJcUukfY2/jcYh6/bw73oH3fWNL6aXAFfnp+OfOSI0ei6ZfnqjTUS5xf bHY9v/z14F/X7e853LAcUOc= X-Google-Smtp-Source: ALg8bN54hmbpi3XTEjK7VlLXm4oRoDaDUqV+lqCo/vGMfQheIH4qkYtD8DzyoSkXpC9+/jaNR3PNeQ== X-Received: by 2002:a65:50c1:: with SMTP id s1mr14251684pgp.350.1546457879079; Wed, 02 Jan 2019 11:37:59 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:78b4:3a07:980a:287b]) by smtp.gmail.com with ESMTPSA id b9sm76790795pfi.118.2019.01.02.11.37.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Jan 2019 11:37:58 -0800 (PST) From: Andrei Vagin To: Alexander Viro , David Howells Cc: linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, Andrei Vagin , Li Zefan Subject: [PATCH vfs/for-next v4] cgroup: fix top cgroup refcnt leak Date: Wed, 2 Jan 2019 11:37:56 -0800 Message-Id: <20190102193756.6096-1-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190102022804.GH2217@ZenIV.linux.org.uk> References: <20190102022804.GH2217@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It looks like the c6b3d5bcd67c ("cgroup: fix top cgroup refcnt leak") commit was reverted by mistake. $ mkdir /tmp/cgroup $ mkdir /tmp/cgroup2 $ mount -t cgroup -o none,name=test test /tmp/cgroup $ mount -t cgroup -o none,name=test test /tmp/cgroup2 $ umount /tmp/cgroup $ umount /tmp/cgroup2 $ cat /proc/self/cgroup | grep test 12:name=test:/ You can see the test cgroup was not freed. Cc: Li Zefan Fixes: aea3f2676c83 ("kernfs, sysfs, cgroup, intel_rdt: Support fs_context") Signed-off-by: Andrei Vagin --- v2: clean up code and add the vfs/for-next tag v3: fix a reference leak when kernfs_node_dentry fails v4: call deactivate_locked_super() in a error case kernel/cgroup/cgroup.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index fb0717696895..309c8507fe6c 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -2019,7 +2019,7 @@ int cgroup_do_get_tree(struct fs_context *fc) ret = kernfs_get_tree(fc); if (ret < 0) - goto out_cgrp; + return ret; /* * In non-init cgroup namespace, instead of root cgroup's dentry, @@ -2038,19 +2038,28 @@ int cgroup_do_get_tree(struct fs_context *fc) mutex_unlock(&cgroup_mutex); nsdentry = kernfs_node_dentry(cgrp->kn, fc->root->d_sb); - if (IS_ERR(nsdentry)) - return PTR_ERR(nsdentry); + if (IS_ERR(nsdentry)) { + ret = PTR_ERR(nsdentry); + goto out_cgrp; + } dput(fc->root); fc->root = nsdentry; } ret = 0; - if (ctx->kfc.new_sb_created) - goto out_cgrp; - apply_cgroup_root_flags(ctx->flags); - return 0; + if (!ctx->kfc.new_sb_created) + apply_cgroup_root_flags(ctx->flags); out_cgrp: + if (!ctx->kfc.new_sb_created) + cgroup_put(&ctx->root->cgrp); + + if (unlikely(ret)) { + dput(fc->root); + deactivate_locked_super(fc->root->d_sb); + fc->root = NULL; + } + return ret; }