Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2971846imu; Sun, 9 Dec 2018 14:00:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9o33ZV7mQcpsb7fovEpZGxZvtnwZsG3WEuTEsm1mR85JaVy6fGZ1EAjaeEeLzpzp92kdd X-Received: by 2002:a63:7044:: with SMTP id a4mr8642514pgn.359.1544392849246; Sun, 09 Dec 2018 14:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544392849; cv=none; d=google.com; s=arc-20160816; b=dAegUiZICYOGo2T/nsfKcm3KKwuZtyiyMNQSqTSKk8mm7Xa3wVDHbJTmd5j5AvkDK7 8Y6Owz9xHXtGtLVZUUui6/BzuYRCJSFn9p4HLcB+rhRVl2doqx5aEgY23IGhdZfmRglM k44UCSwmwz3wsjkEFtaDSnBIVTLx/GkIGNbS4aDfj02IFNvlI4TTZ52K8QfI18dsDpRv 4im3rSVsEtRmC4W5ESph5Kd8l5eBLIsYl3XdHvCGcQcBoGC3Ucuq9ZDdVTZpA67xK6SU oCedC2nzZv9WIjakiIcDYUIaWn2syJz/GlL8VsLxMrSOPnaydZ7XkoRIIh/NvEOXgQuK +JfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Uga1sStqC6xOl8MthF7rILdUW/roX4KJ7G3dkM4GMjg=; b=FETB/EetsRc6m3gfRjA2TuXaPb8FBxK5agavOu+ySJ3beIT7hG0xanIM8O+VdM2BuD GzHdN8i43U+UV3Fu0379+R1ix852JpcEkPE8xbQG3uD4qLflLCJJIarQAUXF+yZBd/rZ q37pcxyiEGXLxswK0IsJcEUu3IJxfpRfd4HmVHNS3GIIY/Mw2/c/PTfXJbqW2i/3W1W5 FBj9u/IvizS7ZwpsokSWAkFOrWM12GVEdkzdwHWmmlKKy+WiEX3e/9ew90Daxaixzml5 Xj/3Bd/k7v7pCy3i6gf1i2ELUsn+2k3ZYucXGcvAdI7yotFTFpaJaKXlLqVeTRkeARhg Pepg== ARC-Authentication-Results: i=1; mx.google.com; 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 v30si7841434pga.45.2018.12.09.14.00.33; Sun, 09 Dec 2018 14:00:49 -0800 (PST) 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; 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 S1727134AbeLIV65 (ORCPT + 99 others); Sun, 9 Dec 2018 16:58:57 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:36224 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbeLIVzj (ORCPT ); Sun, 9 Dec 2018 16:55:39 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW730-0002ir-RO; Sun, 09 Dec 2018 21:55:35 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72g-0003XA-Ue; Sun, 09 Dec 2018 21:55:14 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Sven Eckelmann" , "Simon Wunderlich" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 219/328] batman-adv: Prevent duplicated global TT entry In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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 [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- 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 @@ -1287,6 +1287,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 @@ -1309,10 +1311,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: @@ -1320,6 +1320,8 @@ sync_flags: out: if (orig_entry) batadv_tt_orig_list_entry_free_ref(orig_entry); + + spin_unlock_bh(&tt_global->list_lock); } /**