From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A38CDC4332D for ; Thu, 19 Mar 2020 13:36:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78AA020663 for ; Thu, 19 Mar 2020 13:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584625000; bh=02K4N+O2xv7mwBzmmPLvM1cmWS5GsidpF10WJrr9krw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=YMxtCM7APkt726WF/40M/fsWvbt6KFW34g2n8O0JvLxpQne+5iLYH5qFKxjpLSH7K BpKsDUV/5F/db6zDbq7/utIaNSHw+StSSwGNs7tAu+ABJveRDGqEF27STLFNGRtdbo iEUMxtlUJguUfwtgeJ7clL7KTzmHiy78ZLhFhYzo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbgCSNJZ (ORCPT ); Thu, 19 Mar 2020 09:09:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:53850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgCSNJY (ORCPT ); Thu, 19 Mar 2020 09:09:24 -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 A8FDF20789; Thu, 19 Mar 2020 13:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584623364; bh=02K4N+O2xv7mwBzmmPLvM1cmWS5GsidpF10WJrr9krw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X9qf+lkMu+yTH0/RKSh0WZPTEGC3X857nCXcLe2bM3Xiy0Fi33vMw2wMTR/676BZi QmxDUdSOBmI4LT7wc7atH0Gi451cgUUiAPVQyseHq1ZEJttpK6u/mLQ7XnHv1W46rO 3BJ9CyIy3Cxmhk13XCbCYQaRUxrBkD5iUEGLgHzw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Sven Eckelmann , Simon Wunderlich Subject: [PATCH 4.4 78/93] batman-adv: Prevent duplicated global TT entry Date: Thu, 19 Mar 2020 14:00:22 +0100 Message-Id: <20200319123949.406744237@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200319123924.795019515@linuxfoundation.org> References: <20200319123924.795019515@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sven Eckelmann commit e7136e48ffdfb9f37b0820f619380485eb407361 upstream. The function batadv_tt_global_orig_entry_add is responsible for adding new tt_orig_list_entry to the orig_list. It first checks whether the entry already is in the list or not. If it is, then the creation of a new entry is aborted. But the lock for the list is only held when the list is really modified. This could lead to duplicated entries because another context could create an entry with the same key between the check and the list manipulation. The check and the manipulation of the list must therefore be in the same locked code section. Fixes: d657e621a0f5 ("batman-adv: add reference counting for type batadv_tt_orig_list_entry") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/translation-table.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1315,6 +1315,8 @@ batadv_tt_global_orig_entry_add(struct b { struct batadv_tt_orig_list_entry *orig_entry; + spin_lock_bh(&tt_global->list_lock); + orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node); if (orig_entry) { /* refresh the ttvn: the current value could be a bogus one that @@ -1337,10 +1339,8 @@ batadv_tt_global_orig_entry_add(struct b orig_entry->flags = flags; atomic_set(&orig_entry->refcount, 2); - spin_lock_bh(&tt_global->list_lock); hlist_add_head_rcu(&orig_entry->list, &tt_global->orig_list); - spin_unlock_bh(&tt_global->list_lock); atomic_inc(&tt_global->orig_list_count); sync_flags: @@ -1348,6 +1348,8 @@ sync_flags: out: if (orig_entry) batadv_tt_orig_list_entry_free_ref(orig_entry); + + spin_unlock_bh(&tt_global->list_lock); } /**