Received: by 10.223.164.202 with SMTP id h10csp505690wrb; Thu, 9 Nov 2017 09:39:21 -0800 (PST) X-Google-Smtp-Source: ABhQp+RL/6w0KJNDWO1Y3G/BaVqVrGaAjzwu/3Y2u4QL0O7Afw2UxJCpQtoVfATEhWZZh5zK9xcs X-Received: by 10.99.0.214 with SMTP id 205mr1149450pga.283.1510249161877; Thu, 09 Nov 2017 09:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510249161; cv=none; d=google.com; s=arc-20160816; b=qULM9mh+qt2+P5QmA3rAdPyw7546AXJ+KZj7g2bhkwcn5c9i8Z1xsd7tLtx+3tclQm dcik23HBQv+zSk06ayufmWal1330xIIAM/XTfa0IDb3Y6Xs5bEg3iR1d0/KnSuu+sIqd GOwwCelDR9cPET8GAp4ROUo+9dmqetYGCTg6aciVn0rPbFrhDQpxyHY47aPC3+a0hwSh BMx8zau/eqPD84M3m5ziiusHkSrZPrtYDGZfkWl+rS8DvgkVVXHR1DmCDSxtI068HdWf cToFheoA91hT9DW3OJnl8NERbfFqKpSyCVITNWHZ2lcMJgWEp6ifYHBNy24DAoaxYemi nKyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=BDF1kiP9tbnTxq6G+3l2ENorgLIdVA0zI2im81lD/9o=; b=SDB/QXmfTvhya36HAh7HQotnR8GEPx2YhlBCO0YKD2ejPzdP4UntRVNUYyVEoHf/Q5 7OaMGM44b9FTtMOToD+NlHF+Z+wXEB8AYRwXR8sPoCADdl8EqHd4cs8xkBOAnRVmBYTi 9+Qk8xsJi+8+LuhvEisaedqpYplGTcBEQgf3JU1cdRQy+9OC2H07TMe8DWozr12uBgkz 0mv64hOayFxWy0+FaP+wzbK17TpCkzITmU2n+2hSCA0CAwP9sZCKRUaRmp8IzIytdm0t MxFhdMKbQBB+R2GnPSAtbBZTnf1c/6XjZtDq8sd4lgd1W1HVTCv261OLaxjigeIYZv+5 Fszw== ARC-Authentication-Results: i=1; mx.google.com; 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 c18si7292319pfd.416.2017.11.09.09.39.10; Thu, 09 Nov 2017 09:39:21 -0800 (PST) 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; 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 S1754825AbdKIRhT (ORCPT + 81 others); Thu, 9 Nov 2017 12:37:19 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:45116 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752459AbdKIRhQ (ORCPT ); Thu, 9 Nov 2017 12:37:16 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id C48E09C1672; Thu, 9 Nov 2017 12:37:15 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 6-d2jgHfJVL7; Thu, 9 Nov 2017 12:37:15 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 265F39C19FF; Thu, 9 Nov 2017 12:37:15 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cH0dISAQx-N4; Thu, 9 Nov 2017 12:37:15 -0500 (EST) Received: from weeman.mtl.sfl (unknown [192.168.49.192]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id C02849C1672; Thu, 9 Nov 2017 12:37:14 -0500 (EST) From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Florian Fainelli , Stephen Rothwell , lkp@01.org, Vivien Didelot Subject: [PATCH net-next] net: dsa: remove tree refcount Date: Thu, 9 Nov 2017 12:36:52 -0500 Message-Id: <20171109173652.25258-1-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.15.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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'. Tracking the number of devices in a tree with a kref is not really appropriate anyway so removes it completely in favor of a basic counter. Fixes: 8e5bf9759a06 ("net: dsa: simplify tree reference counting") Signed-off-by: Vivien Didelot --- include/net/dsa.h | 2 +- net/dsa/dsa2.c | 29 ++++------------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 35b5dee7bb23..bbcdff43526f 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -119,7 +119,7 @@ struct dsa_switch_tree { unsigned int index; /* Number of switches attached to this tree */ - struct kref refcount; + unsigned int nr_devices; /* Has this tree been applied to the hardware? */ bool setup; diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index fd54a8e17986..fda3e5415eaf 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -51,10 +51,6 @@ static struct dsa_switch_tree *dsa_tree_alloc(int index) INIT_LIST_HEAD(&dst->list); list_add_tail(&dsa_tree_list, &dst->list); - /* Initialize the reference counter to the number of switches, not 1 */ - kref_init(&dst->refcount); - refcount_set(&dst->refcount.refcount, 0); - return dst; } @@ -75,25 +71,6 @@ static struct dsa_switch_tree *dsa_tree_touch(int index) return dst; } -static void dsa_tree_get(struct dsa_switch_tree *dst) -{ - kref_get(&dst->refcount); -} - -static void dsa_tree_release(struct kref *ref) -{ - struct dsa_switch_tree *dst; - - dst = container_of(ref, struct dsa_switch_tree, refcount); - - dsa_tree_free(dst); -} - -static void dsa_tree_put(struct dsa_switch_tree *dst) -{ - kref_put(&dst->refcount, dsa_tree_release); -} - static bool dsa_port_is_dsa(struct dsa_port *port) { return port->type == DSA_PORT_TYPE_DSA; @@ -492,7 +469,9 @@ static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, dsa_tree_teardown(dst); dst->ds[index] = NULL; - dsa_tree_put(dst); + dst->nr_devices--; + if (!dst->nr_devices) + dsa_tree_free(dst); } static int dsa_tree_add_switch(struct dsa_switch_tree *dst, @@ -504,7 +483,7 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, if (dst->ds[index]) return -EBUSY; - dsa_tree_get(dst); + dst->nr_devices++; dst->ds[index] = ds; err = dsa_tree_setup(dst); -- 2.15.0 From 1583623950318704450@xxx Thu Nov 09 21:04:48 +0000 2017 X-GM-THRID: 1583623950318704450 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread