Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8411194ybi; Thu, 6 Jun 2019 11:52:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfWWz7q2WDJEpcPhQR6fqx/e2xpxOO87XeXVbVTgnpE4CmPHst7Pfw3SCPInesAW2T9kQ8 X-Received: by 2002:a65:4c4b:: with SMTP id l11mr9596pgr.9.1559847127964; Thu, 06 Jun 2019 11:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559847127; cv=none; d=google.com; s=arc-20160816; b=rsoAfhbSPUQTYX+VegX7+Jr7szrGUpR2xT87BRUUfm1H9vgnjjp1rHHUy00jk8Sy2a zNpb+VQbCPCEJclPCOWOIRH7H4441Evudxlqt1W52bgwzPcBtAwwwO7pI0Nvq7j6V62R phETCLaAcQWpmhzZXFThZGNhNhJHs6fYnHlCGr0cxPf3tRrbZYKOghyDRJos+nU7XKjW X+Dc7hhp6K9h7Nxmj/M2FbEkF9s5VSfO6hVpk9l1CFKxoJwbS3fnhPM1SlJCwS4t2Hyf QDHasaoXN6wQrev6VM1HuqLD88m9nlrbpKl2LuZwjNOhZRDjyJtjbHGfr1jz5mqzQNAm itxA== 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=u6Y+cqrYVOxVvx9PJQvJzOmV48wnJDsYZSMNZJzXapE=; b=lxeOJ/I1BPgkbzLLCpCDqmGf8UQcxIGXr1cIzN0CBz6sYdxQxiecdzG90xpJX9fjkB uY7IvPJtNYfvd/ZNhPO5M4OwEcH1vsGIdg+AIDTEQh58ch6H3tH5RHF/NfLyc+HzJiuY 6P/5PlcOxsYpvdLjoZAd2Rf9VpkO/7qtKdZuSTY8WdRTck2Kav0TsoWeCkIx0p4AOFv1 Vjkpih19zH4Yiv+A08/tU1D9Hml/pdo4cuHI7Lv3dpqCeo3BMoNratMwFqQDhAQfPYxq Y/MIv3wy44jr0B0s9eS3IobXPLsckF9tt6G+6MF79eT6Bvk/irRbDvv2XH1F1VaU7t+H LVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=KqIZgrne; 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 x13si1386771pfo.144.2019.06.06.11.51.51; Thu, 06 Jun 2019 11:52:07 -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=fail header.i=@gmail.com header.s=20161025 header.b=KqIZgrne; 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 S1729860AbfFFQz6 (ORCPT + 99 others); Thu, 6 Jun 2019 12:55:58 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40092 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbfFFQz6 (ORCPT ); Thu, 6 Jun 2019 12:55:58 -0400 Received: by mail-pl1-f194.google.com with SMTP id a93so1159280pla.7; Thu, 06 Jun 2019 09:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=u6Y+cqrYVOxVvx9PJQvJzOmV48wnJDsYZSMNZJzXapE=; b=KqIZgrneAkfId4BXzJlJ/Ba8ZWCyfARfJKryBHIwJpFOUWjvAFIhrMepKB/WdmaJCW +Q80K/fqEwYpYM9kk/LC4dVD2ffjBQhjIlpa6xmKPFYunh8O9gYd56CtjXDBwr5UhYX6 uhvj7YSiUsR2Txa/kz6rPS4nTfow4cH/wA73R6mnZxQtz1ELmkKUURkHP1Ho0flF+Tgx QVzbpjAAcaVuL5DWYrX+exTgeFmY61JZuMYPfF/xqAMkOIj4SPQ+T787MdhgLcFBWZc/ FMivxtwW7WooFzXWErEAvPQ9y+MNrWGFbjU4zl3Fd15Qs3FJT1CjMA5HYrl6nwB7sSNP v/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=u6Y+cqrYVOxVvx9PJQvJzOmV48wnJDsYZSMNZJzXapE=; b=Jg5jDJvQ9DpP4pKDENeRFgUIhWnWjmOGjXkND78TZcD34GXDHX/5kGsPXhBZMsiQm8 Ynvo5Sh7YupUEEJ1knIYFJGZg/wROKJWjT0LfXOXRp2xCliDGzvEk/8x/99DWhtiGdtQ S8Au84JgebV0Z2+VZ5Wu47ihLs84Q6Bn5A56PoZM1LQQqXdPlkMQktKw+m7MwjNCVsK9 WoySHS2KjCRTwt3BlvOgB54oLu+cjK1d3YHTRBdTnZt3/rDhFSg3MU7MUu5wEXC15V6i HmTAF/tKtM9mAQLPvDEYDJcUR9mejaLdRiVNfpnnk8LK8Mdi3apNHFX9BBLw+lDPT4iN 5r+w== X-Gm-Message-State: APjAAAX1a7aTtmwCpbA8ZL//U58IXgVUPvqhQnRNkebuhcbKkCeg+3db P0aXAQUXjO4svopeRQllzNxOHm82 X-Received: by 2002:a17:902:9305:: with SMTP id bc5mr50809503plb.193.1559840157877; Thu, 06 Jun 2019 09:55:57 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id l21sm2257286pff.40.2019.06.06.09.55.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 09:55:57 -0700 (PDT) Date: Thu, 6 Jun 2019 09:55:55 -0700 From: Guenter Roeck To: Eduardo Valentin Cc: Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 2/2] hwmon: core: fix potential memory leak in *hwmon_device_register* Message-ID: <20190606165555.GA32130@roeck-us.net> References: <20190530025605.3698-1-eduval@amazon.com> <20190530025605.3698-3-eduval@amazon.com> <20190605203837.GA30238@roeck-us.net> <20190606143509.GF1534@u40b0340c692b58f6553c.ant.amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190606143509.GF1534@u40b0340c692b58f6553c.ant.amazon.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 06, 2019 at 07:35:44AM -0700, Eduardo Valentin wrote: > On Wed, Jun 05, 2019 at 01:38:38PM -0700, Guenter Roeck wrote: > > On Wed, May 29, 2019 at 07:56:05PM -0700, Eduardo Valentin wrote: > > > When registering a hwmon device with HWMON_C_REGISTER_TZ flag > > > in place, the hwmon subsystem will attempt to register the device > > > also with the thermal subsystem. When the of-thermal registration > > > fails, __hwmon_device_register jumps to ida_remove, leaving > > > the locally allocated hwdev pointer. > > > > > > This patch fixes the leak by jumping to a new label that > > > will first unregister hdev and then fall into the kfree of hwdev > > > to finally remove the idas and propagate the error code. > > > > > > > Hah, actually this is wrong. hwdev is freed indirectly with the > > device_unregister() call. See commit 74e3512731bd ("hwmon: (core) > > Fix double-free in __hwmon_device_register()"). > > heh.. I see it now. Well, it is not a straight catch though. > > > > > It may make sense to add a respective comment to the code, though. > > > > I agree. Or a simple comment saying "dont worry about freeing hwdev > because hwmon_dev_release() takes care of it". > > Are you patching it ? > Will do. I'll send a patch in a minute. Thanks, Guenter