Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2555132yba; Mon, 6 May 2019 07:58:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqDgigOPTmAX7p5N4aH6vz2ddNq4hlch9GnM/BNms1H/y0pL58sHMgbUz0PXqU/WrG8sji X-Received: by 2002:a65:480c:: with SMTP id h12mr31837853pgs.266.1557154683362; Mon, 06 May 2019 07:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154683; cv=none; d=google.com; s=arc-20160816; b=WxwD2cMZwniubBu22rxKSmrWW9O3NG+znTDxdx17igBLZ8eL08s6+infm/ZdxHhsMf RITnFlBs/oLCXxrVXENCIM6X60zradC/K2mMajn9XKsKjpW3pUbovzFjtsl1uVjDO879 QZdGoXhssgOEm//Y9GGOJETtu0UBPYp+a4RcdPFCx9LT0TyzSG8Q7j2aI2OX3unubzIe y3LG9Q9AzcvuewGBc5z4OFG2/r9qb63w06nEqZ8DwI49PlTIYD38/tzwGS8lzYt9XFb2 Uci70DD8z9jW8aLmoFPsTKcXBj1JZelyRZwu7dt1g4QI+iX/PZ6ytPoOHXaj3M5PJaqb cvcw== 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=aJXOPG2CFteJwW4xOMKOOgB2RoO3cberumOx3x9WiO0=; b=DIa7qfAgX5Twe5h3mGKMtzf4eKsvtTNx5BAZcXt0171jwXWsVWl0Oe5hgzzBsMuf7Q CrXI1y0loKDVllc5o7IVNnZEghdCEgBZNBtnPpZHhfd1/VyqicIBd1CnLAafbOR89hN9 ow/otgqsQPGbuLyZmqEWNiGbTxyvL8AuEVGwKV4yqdjJD0HIEDJWNzTG7zhyLaWRvW/C rCkOhCs8T/nFJeYMgn8rAC/YGm2ZgNEK5R5z/0fOCIVVchP/vATEGD+A7EXY91Ncu6+s zdIvjvRQSjokmNFbE8DytD1FIc92pzd0iqEzTQTN3m5+7lhzdx7P8p+CVKxU8DJ8jz/B D9Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2be2xJbe; 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 1si14454681pgx.176.2019.05.06.07.57.47; Mon, 06 May 2019 07:58:03 -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=2be2xJbe; 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 S1726974AbfEFOoo (ORCPT + 99 others); Mon, 6 May 2019 10:44:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:41062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbfEFOol (ORCPT ); Mon, 6 May 2019 10:44:41 -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 6C60D214C6; Mon, 6 May 2019 14:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153880; bh=ttUIcJbXRDl/zoJuI+vglxrDAbedDZMDmHggSG76Jfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2be2xJbeV8QwyA9N81kmV+1B2uLvza4n2AMwzxIxW4VVHnxgczFraxKvtnQX+94DU olNJ5x5fYpV8X+oAfiJ+9J5PttVb6+cm8ksXDFHcmqlpBQIxJvJLpS7avuFkMD1oCp lJvpAShwoUDenJgkbs/m7CSBp8THdw5I4qyEoEcE= 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.14 30/75] batman-adv: Reduce tt_local hash refcnt only for removed entry Date: Mon, 6 May 2019 16:32:38 +0200 Message-Id: <20190506143055.909815509@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143053.287515952@linuxfoundation.org> References: <20190506143053.287515952@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 --- 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 9da3455847ff..6c3e446abeed 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1313,9 +1313,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) @@ -1344,15 +1345,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