Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5036917yba; Tue, 30 Apr 2019 08:11:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7nyFx+iqAgVeZMfxaXxHsQP/0nT4MVJvNQnnhEtdGU0qHTiy+thw1QSs84fG6ksda1Suu X-Received: by 2002:a17:902:263:: with SMTP id 90mr71287224plc.257.1556637099237; Tue, 30 Apr 2019 08:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556637099; cv=none; d=google.com; s=arc-20160816; b=CYa/jd0PJ7DeigmEw7s+2de9jU2tENEskm+MpQzpXCAtP9IGs473kgXAEmirzGGURY iuaJycWc3V3onBMSRs/wWyQyDmScPItn/4IAoGVLjTipeyMjuwf/P9EyBSSJ/My1g4xJ kurmpvYFKIZ3TfEE1czkhWaSxf0iKFfdqG00YmjL80vMOPe/2hN7f9HWUYgvp7Hu7zjV 0uFmLaHREgj2ZIDIa2bJrlALSgHehtcX/ubzR/7x3oWFY4oFmjq6WJjK0yrFS6mI5Yyb 0PER+bV1Gl/XmBMKXAet5Xrlkn1Xp4TDbrWrKepE1qAXKB+49bphcI8DyzZqd7ZAwIa+ FHnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1KD7hzsgPu61LAwy9Sn7ppHhiemyeKrIkAKA/cgWTDI=; b=Ip0FOI4ILqQmmKmYdudzKj/Dt4VB72gwrgLqljvB+2AGh6kKjcfor6nrrSUpA9WL2m 9AKLadYmzKWSH7TIP+EMu62mV8nKJ/Itan3pRoJIqePOJBRLhaZNwBU0goGqT4pDKaCf UgRoN8QKNJZy0K5qu1GUC9oU57ZkUYhX5XqDVj3RctEsri5vcskpPGaLgBvAw/EpB4y2 f+IOgAefmbeEjw7AoJAVXGA/Pnpr4BPMRqE5r5sRllb2k+c5hsWkgaBZy0FEMkoQw5pI LX8NoCuqdyuxN67+bgqAGWSH+SloNBVBieGlCZ13H0x58Tf4+XqdRfFyY60FQJDU9Z+N uf7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zUDdEa0J; 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 a5si32539421pgd.488.2019.04.30.08.11.19; Tue, 30 Apr 2019 08:11: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; dkim=pass header.i=@kernel.org header.s=default header.b=zUDdEa0J; 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 S1726385AbfD3PKL (ORCPT + 99 others); Tue, 30 Apr 2019 11:10:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbfD3PKI (ORCPT ); Tue, 30 Apr 2019 11:10:08 -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 8EB4B20835; Tue, 30 Apr 2019 15:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556637008; bh=zBYVD89Ga502t2W3oixEvvE+fgpD1hl8GQQvPTyVRkk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zUDdEa0JtLy8WrOxbx7BBxtDmXrNIiFICLg7H2xTTiXms64PfZ/Fh2KB2DlmrgE15 PoBF/xyJoecS5srDBmHfzTeR3mF1gUPR1qAZopw9g30sRcF7VkpokPRdXvjhnkOHwl lFO5RSMStrU0KCVjf8jTztwFQ6lS5ridnVz7vHYk= Date: Tue, 30 Apr 2019 17:10:05 +0200 From: Greg Kroah-Hartman To: Petr Mladek Cc: "Tobin C. Harding" , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Joe Lawrence , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] livepatch: Fix kobject memleak Message-ID: <20190430151005.GA20916@kroah.com> References: <20190430001534.26246-1-tobin@kernel.org> <20190430001534.26246-2-tobin@kernel.org> <20190430145613.7tokgyqjsuxlyh2g@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190430145613.7tokgyqjsuxlyh2g@pathway.suse.cz> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 30, 2019 at 04:56:13PM +0200, Petr Mladek wrote: > On Tue 2019-04-30 10:15:33, Tobin C. Harding wrote: > > Currently error return from kobject_init_and_add() is not followed by a > > call to kobject_put(). This means there is a memory leak. > > I see, the ref count is always initialized to 1 via: > > + kobject_init_and_add() > + kobject_init() > + kobject_init_internal() > + kref_init() > > > > Signed-off-by: Tobin C. Harding > > --- > > kernel/livepatch/core.c | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > > index eb0ee10a1981..98a7bec41faa 100644 > > --- a/kernel/livepatch/core.c > > +++ b/kernel/livepatch/core.c > > @@ -727,7 +727,9 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func) > > ret = kobject_init_and_add(&func->kobj, &klp_ktype_func, > > &obj->kobj, "%s,%lu", func->old_name, > > func->old_sympos ? func->old_sympos : 1); > > - if (!ret) > > + if (ret) > > + kobject_put(&func->kobj); > > + else > > func->kobj_added = true; > > We could actually get rid of the custom kobj_added. Intead, we could > check for kobj->state_initialized in the various klp_free* functions. Why do you need to care about this at all anyway? The kobject can handle it's own lifetime just fine (that's what it is there for), why do you need to also track it? thanks, greg k-h