Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3731457imm; Mon, 8 Oct 2018 08:38:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV61XGk8iEVvDdoFJdMkLsx2TDYwitHYtrDRQqYZxMKEGZlFGEYQtehdw1QWC2ylVWnclB1xS X-Received: by 2002:a62:5251:: with SMTP id g78-v6mr25741302pfb.256.1539013131594; Mon, 08 Oct 2018 08:38:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539013131; cv=none; d=google.com; s=arc-20160816; b=GohL9Rv6A4rdA5i29MVq0rEKlTi43Sr32knN4FFQacdptEVrigfGjlxL4MZPojHW5m Bd3E+knFs6+sQU9fhvTpnHPzUJLg+rmba4+uArWXl0CCjcgUS5k1/CJ+JMoLl3VqK5FN tD6SUn7zuK49Z8ONGYKnqITWZdW2p5Gwjw+qLg37VW9NX5MIAW/SavdtpxgRnWOkcsSd LakGvXybNHEJAaRotXr/oXzzYUQ4ALeu2vLzTjyILVb0/8h0Iq6UbUvQbvDeBMwFF+r0 bYmVxBjUds5gDNSKICWfxbZA/FqRElhvEH7n6x8kC9Hehesm2Rdi6bU8/MbZ+BKR/S4k n1Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OSMCsUHvHglVFaC5DGUcwuDAl80Yl9Tg/z0l27BKzR0=; b=ZKHYjnqs0XO61GL9biffYsCtJckDJCiQPozf3QoUmfK/J+6EtRmZbrLaErtdYriDDq jzb+eahzhYDHlh0a9RsTCcUOeLFnOgZ+Ew9SaEvNT5ghdQMxrbZ1zt3tuXPcSXUQcgME aSLqGTM8Cbe7195NQNR2dQZi+IrunZiznHU9z7E/lRXwBfvlDV46QqpaDiGLvRhltsc0 sVy2pAXI2JNrlwuNBMaYX0RbhiIpoNz7/PJ2+4uadgrPQ2Ln7KQTGjYIMzBtp9xw9kLx lixjuVhjtD0HCYAohzSUqq16D2SlK3wuMIinEYesZJhZ/Yza3XHZFPAgbpufRKMgDbWF 3AVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FFO6ClhK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si18032095plb.131.2018.10.08.08.38.36; Mon, 08 Oct 2018 08:38:51 -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=FFO6ClhK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727384AbeJHWur (ORCPT + 99 others); Mon, 8 Oct 2018 18:50:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:55918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbeJHWhx (ORCPT ); Mon, 8 Oct 2018 18:37:53 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 299FF2145D; Mon, 8 Oct 2018 15:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539012338; bh=OqVDLI38IOd+1PyRD0hsblu11L8+F83XLszN8QUdkIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFO6ClhK5dt77VkW1K+POWoB94IjDpby3kowXxfT3goPRSzMo+s84EQSy1icuidu/ 0DXFi/BqzJEBhYblSNjicvaf60jFrxHiRZAPeVMScsstlUn34VE5eXiQMwdeuvGxY0 EoR2+KCdqEbwelKE3ZeqXE8e8U3y3ic2Sydn99b4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sven Eckelmann , Simon Wunderlich , Sasha Levin Subject: [PATCH AUTOSEL 4.18 12/58] batman-adv: Prevent duplicated global TT entry Date: Mon, 8 Oct 2018 11:24:37 -0400 Message-Id: <20181008152523.70705-12-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181008152523.70705-1-sashal@kernel.org> References: <20181008152523.70705-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sven Eckelmann [ Upstream commit e7136e48ffdfb9f37b0820f619380485eb407361 ] 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: Sasha Levin --- net/batman-adv/translation-table.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 12a2b7d21376..d21624c44665 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1613,6 +1613,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global, { 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 @@ -1635,11 +1637,9 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global, orig_entry->flags = flags; kref_init(&orig_entry->refcount); - spin_lock_bh(&tt_global->list_lock); kref_get(&orig_entry->refcount); 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: @@ -1647,6 +1647,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global, out: if (orig_entry) batadv_tt_orig_list_entry_put(orig_entry); + + spin_unlock_bh(&tt_global->list_lock); } /** -- 2.17.1