From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753862AbdKXVV2 (ORCPT ); Fri, 24 Nov 2017 16:21:28 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34243 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753765AbdKXVV0 (ORCPT ); Fri, 24 Nov 2017 16:21:26 -0500 X-Google-Smtp-Source: AGs4zMZIlFKRWiR96TQdOWKAr4PqrMT5MTvYfg3klGOOAQ23sTG5Uz5s4rpRyj6aKCXrAWef7OZaIw== Subject: Re: [PATCH net] net: dsa: fix 'increment on 0' warning To: Vivien Didelot , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Andrew Lunn , Fengguang Wu , wfg@linux.intel.com, LKP References: <20171124163606.11212-1-vivien.didelot@savoirfairelinux.com> From: Florian Fainelli Message-ID: <64d9f179-7635-b51a-7688-9bd546e2059f@gmail.com> Date: Fri, 24 Nov 2017 13:21:20 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171124163606.11212-1-vivien.didelot@savoirfairelinux.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/24/2017 08:36 AM, Vivien Didelot wrote: > Setting the refcount to 0 when allocating a tree to match the number of > switch devices it holds may cause an 'increment on 0; use-after-free', > if CONFIG_REFCOUNT_FULL is enabled. > > To fix this, do not decrement the refcount of a newly allocated tree, > increment it when an already allocated tree is found, and decrement it > after the probing of a switch, as done with the previous behavior. > > At the same time, make dsa_tree_get and dsa_tree_put accept a NULL > argument to simplify callers, and return the tree after incrementation, > as most kref users like of_node_get and of_node_put do. > > Fixes: 8e5bf9759a06 ("net: dsa: simplify tree reference counting") > Signed-off-by: Vivien Didelot Reviewed-by: Florian Fainelli Tested-by: Florian Fainelli Thanks! -- Florian