Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4741439yba; Sun, 12 May 2019 21:28:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5bSI89hHqwM0tWnH7GyW0Enp8W9Uio//l4uRMKtdZCGpmMwPvZFtVmTERH29tyBvv9woF X-Received: by 2002:a17:902:5ac8:: with SMTP id g8mr28701372plm.154.1557721730324; Sun, 12 May 2019 21:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557721730; cv=none; d=google.com; s=arc-20160816; b=NPItIsZkHz2cg93ckF2AqO7eZg7Pyr/VT4+aVpkkpdOFM2pJis0zgUNNtjcPeeBgWI UjNA6D+yPdAiasYtNlkBdoMPW2oEEN6xJcMVNRXDYiehpH8OAweynPqf2uhRPpugxyi/ e3BDa7TkRv9tD2n4/nHmWNH2bD4EtfII6KLCGzAzVBIMKPT/ljtiSfwS3EALLmG5LqlY PyWXZtTYu7GSKpsIXNWVbeHCQPhpe0W0YWthDicJbw0lgmvZXpLEnJM2TFxlur0LgVdP kdO8B5+5wC6b/rlWLQdVLCReXXyY4V2sqcwPvIjdFZ5EbyN0niZnOivge67TZ5qO4Qs4 i+8Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KzQDTRHUGlP2t4118hjOq4x8DiBylDCwEn5gHvNCjD4=; b=LytqJF/kgLUd67uhFdgs7lFXWp/fceQE+q+afMz8sPHWmTaSM2/HZnUw0KVM048isq /ZyIhve6f1znLnFpjjzuRb2wGb1es4mLp892qKhRn7+VijUSOhrlfKNsv6YfsD4IKMZN 1oQmLcuBVI2p9MvawljFfgeidBPIOJa+009hkoOnPy71Ss9Xnu+cxhrEBtwKGdrEi+FG zRC0/UlRR1Fxpo8+8egL46yxduDp0e0IRB+y/aiQHPyGjqgNAsw9C8vB/X+IP/hGjkRD OGlpEby1PkWJAe9jNRYoZe5Tiz5y57yBUEDlv9tm2Xe6y20A/L4Id8wor2NERLsfDOq9 3kEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=fkWp6iAz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e64si2241275pfe.178.2019.05.12.21.28.03; Sun, 12 May 2019 21:28:50 -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=@messagingengine.com header.s=fm2 header.b=fkWp6iAz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727351AbfEMDdD (ORCPT + 99 others); Sun, 12 May 2019 23:33:03 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46719 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727202AbfEMDdD (ORCPT ); Sun, 12 May 2019 23:33:03 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 487102210C; Sun, 12 May 2019 23:33:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 12 May 2019 23:33:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=KzQDTRHUGlP2t4118 hjOq4x8DiBylDCwEn5gHvNCjD4=; b=fkWp6iAzsSQSLc1i5Vt20o71uCRAw931S 1rkWHLSc6OSAfxLci18Ey+KOcDQB6oa+7tEC/0T2eXrQtSfY/buih4LWmGNsSQWm ALlraB9fYXjpymF9G1ha/E5L0zstBRH1ZJxHIHkiVhdnF1coESdFHmyF14jeb8lI F9hFrqztt6SLL8snC8u7b+/Qf6fu/UyPkz1TgGOsrQhsHTiD55aslyou6Brs9Q0f lKKTQYcxv1wDQ8vxap2/O87kOyKaxQ/yyhMxubsTKIGoO6YE1hpMA15X+8ilv3lR OzTPOd4KDWK+G9K06g0k07UJxlNeDa0IRPMCkel9EuNfIVMpmrOrw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrleefgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomhepfdfvohgsihhnucev rdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhgqeenucfkphepud dvgedrudeiledrudeirddukeehnecurfgrrhgrmhepmhgrihhlfhhrohhmpehtohgsihhn sehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from eros.localdomain (124-169-16-185.dyn.iinet.net.au [124.169.16.185]) by mail.messagingengine.com (Postfix) with ESMTPA id DE4F910378; Sun, 12 May 2019 23:32:58 -0400 (EDT) From: "Tobin C. Harding" To: Bob Peterson , Andreas Gruenbacher Cc: "Tobin C. Harding" , Greg Kroah-Hartman , "Rafael J. Wysocki" , cluster-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH] gfs2: Fix error path kobject memory leak Date: Mon, 13 May 2019 13:32:13 +1000 Message-Id: <20190513033213.2468-1-tobin@kernel.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a call to kobject_init_and_add() fails we must call kobject_put() otherwise we leak memory. Function always calls kobject_init_and_add() which always calls kobject_init(). It is safe to leave object destruction up to the kobject release function and never free it manually. Remove call to kfree() and always call kobject_put() in the error path. Signed-off-by: Tobin C. Harding --- Is it ok to send patches during the merge window? Applies on top of Linus' mainline tag: v5.1 Happy to rebase if there are conflicts. thanks, Tobin. fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 1787d295834e..98586b139386 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp) if (error) goto fail_reg; - sysfs_frees_sdp = 1; /* Freeing sdp is now done by sysfs calling - function gfs2_sbd_release. */ error = sysfs_create_group(&sdp->sd_kobj, &tune_group); if (error) goto fail_reg; @@ -687,10 +685,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp) fail_reg: free_percpu(sdp->sd_lkstats); fs_err(sdp, "error %d adding sysfs files\n", error); - if (sysfs_frees_sdp) - kobject_put(&sdp->sd_kobj); - else - kfree(sdp); + kobject_put(&sdp->sd_kobj); sb->s_fs_info = NULL; return error; } -- 2.21.0