Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2552280yba; Mon, 6 May 2019 07:55:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7EJ3W4VN49DFb2N0j3mN5VKPOZ6dFgocWhu6igijzqjpyv/CpTi0m+C+L+80+K8Zkz4hB X-Received: by 2002:a63:4621:: with SMTP id t33mr29802963pga.246.1557154501530; Mon, 06 May 2019 07:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154501; cv=none; d=google.com; s=arc-20160816; b=j9gqlkd5zWs1C9354HdwlDgXY4NJZge/UQhM5Nc5UnsChk+/piZwM5iGc4p160TKwq KfgkT9M5svmmdeObUVOrCqZrz9wU0B55Jl0p/QTYepMZbc1IuKqGS4hHX2mZbJAGJMK5 9Vh6J2rLzrTbdjRIat2RI1oRm1aiTk9eiGREHocexnqkcIhXfhes5HpW1O/uwQPM4Mj0 0K4Jg6NWf34Eb0Z7yqQXqiuopCrJ9BBr2q6o3mxnJBGwtogL3OsqqqvO/+/bzQxoF6dE HlYQmD6VlH26Wuuvra6sus9aje7QuOJvGD5BiZKs25TkX9DODoGd+WBapM1n1+EeF0zd CvIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JPFjeIZtY6GpzZg8IrC9uqdjuQRUKWqwy+sKxrPAQpU=; b=XCIhN2Zl6CS5RswuIeIQMrOoR+PcqGx7NeoNWTksEjc582Grn+BNtiv9kscIiX8aAo 4CoTj0cncx/DJiLG/WqcafXkoNqT5ncrCBKWXLaaqylE/852fp47SxkgoQVkjzeM4suq lcEoYS57Kdsh1eXPJWH38grJ3WGaAV5UzTjsPoYmYUani48aazlibBnNIUft00erDPRw ZJwwQkxg5asMfHAwqtOnyVi4kPFgQ3zq8f4nDfUQ8LzEquiBX/372Kd9IqZtI0elRpzh SMkriH/EAx+Yz+yPQ/KcfD7jRVkOWY1xbUcBiEaZXn5yzmxdMoqfKYAKgbFL2oB/zXUT SroA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MdKcg25t; 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 f18si4057191pgb.36.2019.05.06.07.54.45; Mon, 06 May 2019 07:55:01 -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=MdKcg25t; 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 S1729213AbfEFOwh (ORCPT + 99 others); Mon, 6 May 2019 10:52:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726914AbfEFOsI (ORCPT ); Mon, 6 May 2019 10:48: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 2F4BC21530; Mon, 6 May 2019 14:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154087; bh=Mz5846nar66Iy343b/Hbki8SXNus2eCbBEC8vFyt5XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MdKcg25t/mXCo3hsyEOgGONkow+VFK1xWxXAYeGPwvO5LeXHNVxZwFHhTaXePzYli ES9Nvjq8CuvyRBDRHVQwGoUIwrvsLFGmh3dAo5CnBYYdg3RwF9eFMzUAUaouXfNgVY 5H0pboT9idL8dePhpriROYG3uGmqoSrFWCUK+rzE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sven Eckelmann , Simon Wunderlich , Sasha Levin Subject: [PATCH 4.9 31/62] batman-adv: Reduce claim hash refcnt only for removed entry Date: Mon, 6 May 2019 16:33:02 +0200 Message-Id: <20190506143053.755589380@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143051.102535767@linuxfoundation.org> References: <20190506143051.102535767@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 4ba104f468bbfc27362c393815d03aa18fb7a20f ] The batadv_hash_remove is a function which searches the hashtable for an entry using a needle, a hashtable bucket selection function and a compare function. It will lock the bucket list and delete an entry when the compare function matches it with the needle. It returns the pointer to the hlist_node which matches or NULL when no entry matches the needle. The batadv_bla_del_claim is not itself protected in anyway to avoid that any other function is modifying the hashtable between the search for the entry and the call to batadv_hash_remove. It can therefore happen that the entry either doesn't exist anymore or an entry was deleted which is not the same object as the needle. In such an situation, the reference counter (for the reference stored in the hashtable) must not be reduced for the needle. Instead the reference counter of the actually removed entry has to be reduced. Otherwise the reference counter will underflow and the object might be freed before all its references were dropped. The kref helpers reported this problem as: refcount_t: underflow; use-after-free. Fixes: 23721387c409 ("batman-adv: add basic bridge loop avoidance code") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich Signed-off-by: Sasha Levin --- net/batman-adv/bridge_loop_avoidance.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 8b6f654bc85d..00123064eb26 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -802,6 +802,8 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, const u8 *mac, const unsigned short vid) { struct batadv_bla_claim search_claim, *claim; + struct batadv_bla_claim *claim_removed_entry; + struct hlist_node *claim_removed_node; ether_addr_copy(search_claim.addr, mac); search_claim.vid = vid; @@ -812,10 +814,18 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %d\n", mac, BATADV_PRINT_VID(vid)); - batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim, - batadv_choose_claim, claim); - batadv_claim_put(claim); /* reference from the hash is gone */ + claim_removed_node = batadv_hash_remove(bat_priv->bla.claim_hash, + batadv_compare_claim, + batadv_choose_claim, claim); + if (!claim_removed_node) + goto free_claim; + /* reference from the hash is gone */ + claim_removed_entry = hlist_entry(claim_removed_node, + struct batadv_bla_claim, hash_entry); + batadv_claim_put(claim_removed_entry); + +free_claim: /* don't need the reference from hash_find() anymore */ batadv_claim_put(claim); } -- 2.20.1