Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2532877yba; Mon, 6 May 2019 07:36:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwrTZf311zRMHMEjZBLjao6vLhbWabSLxYm60/5QtH7QVV8l5vRIs9gwTCgpKthBUn+T6e X-Received: by 2002:a63:8342:: with SMTP id h63mr32891772pge.251.1557153389366; Mon, 06 May 2019 07:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153389; cv=none; d=google.com; s=arc-20160816; b=RjK/hDRKvZq1Fm3pP916xhsmqFgQqCMTCAQKn8lM7a4v1/qE7ikZAP1H/evbRyj2Sq feYe4JakGTLQiZ0DC0qfA21NQbatJ69+3VmIyNvO9FfNx3/OjHdkScM04pE06hkfuIp6 1jzumIFl6Ovukrj+b1Esv5rAMHS09uQjqHCikxJdI2fMf8zYvFLQCkQsFranfPuGo3Rm BxAUO5VIU66cDMq6Acz0ZTk5aNTxmrF1eHyXvNu9vMzEebKA71Ujid+F1uzk1Ug8ZGJg D9tRinW+f1fxYavx3XfCGff6QYLZ1MJ4c0/YxZhChaFPlNWpuQGsucLD8ocky4uY+vNf nGAA== 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=gC0omZZPGfYobXz6OIqXVDcs6jJMr+gcDHGtspkTTno=; b=t3SjwOv3NLFbnhfaS/Z8YV+p5/rVBTuwQbptqRAOcuU5EV7Ci/gNrcB6akb3JF9sTN jGzGWWQj8RuhY3WmLEAO0UEVAB/MVSQ6OE0HQClx829nRzr+3yUh2uQVhdh1y8lQoG78 HS/Ef/OAfGknb9wKdXNHDOvWG+kgZSZypA04KUe4CkVwr6ybtcWbxvSpDK2IHui1L1ha sF45VDAlRZi3Q/ZtTjetoS8wJMbgMRaZgs/WgT7Y/szIlWweO1SWAd6FjZ4jL4ZoW00B vVxQ/ISSMnfn7u7lXU2B2sxC4sH+rrO6s8X+8uf2yHJN+fe/skB2CVkbfMjkyy+tfSaS Y8OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h4HNxC5I; 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 u4si14809201pgp.477.2019.05.06.07.36.13; Mon, 06 May 2019 07:36:29 -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=h4HNxC5I; 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 S1726756AbfEFOet (ORCPT + 99 others); Mon, 6 May 2019 10:34:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:54552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbfEFOeq (ORCPT ); Mon, 6 May 2019 10:34:46 -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 AC4882087F; Mon, 6 May 2019 14:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153285; bh=ROUxYga+HkYJBhTR31jjlAQqJfyi6Iu9qZZvZ9FY1fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4HNxC5Idv5zTNzXCf/ogfPaoePecaVNgllkSe6qibwaEsIYvcfd/GXgJR/PrlCGN pg2jec8kzr51BLJqxmEdZT0kw4WSVpx6t9ep3SAMjhZUhGelQtJYhUBH/lLraPChKz NUZ1J7QFNHfzE87Ap4NyJiAFCCQvngvsF8WkWAyA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sven Eckelmann , Simon Wunderlich , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 032/122] batman-adv: Reduce claim hash refcnt only for removed entry Date: Mon, 6 May 2019 16:31:30 +0200 Message-Id: <20190506143057.690450004@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 (Microsoft) --- 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 5fdde2947802..cf2bcea7df82 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -803,6 +803,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; @@ -813,10 +815,18 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): %pM, vid %d\n", __func__, 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