Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2574492yba; Mon, 6 May 2019 08:12:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxK0oGg7aZgNpx1Xyp87H+CiyqcaOpueulNAIr7DlnGXZBg965e4Vbo8WyOky8/vdJz58fE X-Received: by 2002:a63:1460:: with SMTP id 32mr2426824pgu.319.1557155550217; Mon, 06 May 2019 08:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155550; cv=none; d=google.com; s=arc-20160816; b=EoECfCa9UQJpdvGzJ9o9boT+j/ky2oKSFH3+aCbE60FJ5p8kADvbFWlzbroNMz+Utt PwYPpINke14kyEEePtokN4tiU+0SVZxU45OTcQ63j1iDI6Br1q+Q9b5AVuLJYg4YP6qz k0yoiStafW8GAasD+AZdc2eOcIHHZkHpln9h7VmPIZtLa3tVyFnfsE5NAym7/Edhlmno wg3f5oPRG606Yml+lOWnVPnQU5T/8ewfke5H+hhXImcZ6NYqW8AjKTyJ/iRa7AsyBibz rLclQgynpGFsgoPKF6Y5pJy438y7JkLX2Ybjtfz5NgnydVXzY+CvkO9W+1dh5Bgx3fkP hM2w== 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=qDLJ8ex+0MGSHOFIHkG2VomHaf9Eo9WJ5k0MpiHiZnE=; b=oPRUHKhTBczewiFKmLQLdzGPJg3j9Enye65pj5vaGR0cugucF7Qnht4oZq9H2iHFGI s+GbHChDfeAlF/mZ0oc5j87PK6acGITkPs940o5yDjEPdOzZwD9RS2qxoPPeHEhFHegi Aye8DmSLpALxwShruqStLu34wvU0Yz5iTeKhtPBgmyaDTbbJZXUhDGKVqZGLzWoQ1LWg BOLW5n7blUHGzn+HYkUd6FkZyQcqCQmNCDyXk/RlXVF8CLwGma7pKP63UFWNF6J8lLR9 3G927nOdeUJynifKygQbLU/Dy4DmkLaR7Yk4d4uoMGvDRWLA3MimI3kzwasKS1kuZLbB VWcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZkUuke7u; 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 m3si15352040plt.394.2019.05.06.08.12.13; Mon, 06 May 2019 08:12:30 -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=ZkUuke7u; 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 S1726771AbfEFOex (ORCPT + 99 others); Mon, 6 May 2019 10:34:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:54626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbfEFOet (ORCPT ); Mon, 6 May 2019 10:34:49 -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 5A6D7214AE; Mon, 6 May 2019 14:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153287; bh=FX5UbOOfZ9KTsRy7VUCn5UmZo9wP6794CI7PoIemgs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkUuke7uO1ekQ2tBkMiylgiB2LlOmtWe+HKGh2fd7dH11eWesQgJHt3kLF7Y2cir1 VZz0Q0PBbfjRIWla8tgh6HFB6/Zf3f26/zUsOvuYBtm0O0sDdVyJgy2lfDx+sgzUm2 qGWa24XOTMIFIlxJyt8EFiaVksLkHh+aLtP8dZqg= 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 033/122] batman-adv: Reduce tt_local hash refcnt only for removed entry Date: Mon, 6 May 2019 16:31:31 +0200 Message-Id: <20190506143057.786578425@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 3d65b9accab4a7ed5038f6df403fbd5e298398c7 ] 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_tt_local_remove 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: ef72706a0543 ("batman-adv: protect tt_local_entry from concurrent delete events") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich Signed-off-by: Sasha Levin (Microsoft) --- net/batman-adv/translation-table.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 8dcd4968cde7..2ee87d3ca6d0 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1337,9 +1337,10 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, unsigned short vid, const char *message, bool roaming) { + struct batadv_tt_local_entry *tt_removed_entry; struct batadv_tt_local_entry *tt_local_entry; u16 flags, curr_flags = BATADV_NO_FLAGS; - void *tt_entry_exists; + struct hlist_node *tt_removed_node; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) @@ -1368,15 +1369,18 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, */ batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); - tt_entry_exists = batadv_hash_remove(bat_priv->tt.local_hash, + tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash, batadv_compare_tt, batadv_choose_tt, &tt_local_entry->common); - if (!tt_entry_exists) + if (!tt_removed_node) goto out; - /* extra call to free the local tt entry */ - batadv_tt_local_entry_put(tt_local_entry); + /* drop reference of remove hash entry */ + tt_removed_entry = hlist_entry(tt_removed_node, + struct batadv_tt_local_entry, + common.hash_entry); + batadv_tt_local_entry_put(tt_removed_entry); out: if (tt_local_entry) -- 2.20.1