Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2255980imm; Thu, 18 Oct 2018 11:30:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV63YC4JGVjkFw/KuQrPPMSim6gm1uFn+IIQh7EH7ykVp2+u19ucRp6GNeO6ZRxn6qUGIgbMK X-Received: by 2002:a63:5a54:: with SMTP id k20-v6mr29751751pgm.297.1539887409794; Thu, 18 Oct 2018 11:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539887409; cv=none; d=google.com; s=arc-20160816; b=lTf0oqWdw8bSa+q7+JrxnY0hlcw+CZnWORNpdC/MM1XYJlHewyh6/fJwQDpwUmy9GE u6cpDiXQVpOGqwzynRGTtCXtSL58+27lfZuw88oOZtf7iYfQbb9wsKXIQzYrjnMk1v8V PaWmwS4hWTV5AH+aicP75MaGczrYI5Xh4pVrHhOU3WYhBQjVIvbcvO2xoW5VJGjG2BAH NWQBbnrNotKi8D+TbJwNHMysY3yapcluXcFESyXi41GdRVZW2pfCG4ekqZexAhhgSaeb TzViH9GrlwVbob36DVXQ7MUZUOHs1rX4IvDeY+Nt42+Hz3b4quDFiGq1DmIk0KFnk2bW uT9w== 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=gOrd65oo3k0/OeMQCqgC9znwjkk+FMLUl8nIlnQFe8s=; b=PP5vvalZ9HUfCLyr9XJylpQ8cW84O8UJv40TanfyLF47MCutQCbQOJxDBXmiRqozz/ bAw09aukmEdFjfT2tDLv/IsC91E+SY1EMnXl/0S2arIxJUBMe6kXtLlN5D4pn8KJiSe6 F3leAqKXxq+mcDOw7CTivtC9C4fAZDOyoGqNTXXAS9zR/Ofl3pY5RVIxJsiXCVTK0zUC S/f3HbQjwKr/yVF+GFZiWGKTI5uMeGEcm122LPhS5byirXL0cNjuLSPyeVrVAgzxqFIX KGeX8WhlsV4C6S5WnOexlhLUIK4am7Y+XOS92R3uop3pW0Op3s+KTF4DY/ImVS2Uwvaa c1MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qu+Ka9fk; 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 w19-v6si15019060pgf.197.2018.10.18.11.29.54; Thu, 18 Oct 2018 11:30:09 -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=Qu+Ka9fk; 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 S1730084AbeJSCG1 (ORCPT + 99 others); Thu, 18 Oct 2018 22:06:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:54798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728416AbeJSCG0 (ORCPT ); Thu, 18 Oct 2018 22:06:26 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 E4FBE21479; Thu, 18 Oct 2018 18:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885859; bh=v47HcZzTeKNa4w5IK+NMWSNKljmJlhJDp+RhZsDbQnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qu+Ka9fkiaJVCGfHAwIoh/duNSpcdiFR9njivH8nsMpknGBp+SC2zzQEIMF62Nlm+ J8we8ntgFVABSNHcXQoZ1VkkBl/qy5Wt5B12ibK7VsHxFZlYMCqZ/ywVlxkjz8vvyw HBFQ3BVX5FlIY8J5Uj9WWHjYiXLL8Sb81XUzGymc= 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.9 05/35] batman-adv: Prevent duplicated softif_vlan entry Date: Thu, 18 Oct 2018 19:54:34 +0200 Message-Id: <20181018175423.261569992@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175422.506152522@linuxfoundation.org> References: <20181018175422.506152522@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sven Eckelmann [ Upstream commit 94cb82f594ed86be303398d6dfc7640a6f1d45d4 ] The function batadv_softif_vlan_get is responsible for adding new softif_vlan to the softif_vlan_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: 5d2c05b21337 ("batman-adv: add per VLAN interface attribute framework") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/soft-interface.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -565,15 +565,20 @@ int batadv_softif_create_vlan(struct bat struct batadv_softif_vlan *vlan; int err; + spin_lock_bh(&bat_priv->softif_vlan_list_lock); + vlan = batadv_softif_vlan_get(bat_priv, vid); if (vlan) { batadv_softif_vlan_put(vlan); + spin_unlock_bh(&bat_priv->softif_vlan_list_lock); return -EEXIST; } vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC); - if (!vlan) + if (!vlan) { + spin_unlock_bh(&bat_priv->softif_vlan_list_lock); return -ENOMEM; + } vlan->bat_priv = bat_priv; vlan->vid = vid; @@ -581,17 +586,23 @@ int batadv_softif_create_vlan(struct bat atomic_set(&vlan->ap_isolation, 0); + kref_get(&vlan->refcount); + hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list); + spin_unlock_bh(&bat_priv->softif_vlan_list_lock); + + /* batadv_sysfs_add_vlan cannot be in the spinlock section due to the + * sleeping behavior of the sysfs functions and the fs_reclaim lock + */ err = batadv_sysfs_add_vlan(bat_priv->soft_iface, vlan); if (err) { - kfree(vlan); + /* ref for the function */ + batadv_softif_vlan_put(vlan); + + /* ref for the list */ + batadv_softif_vlan_put(vlan); return err; } - spin_lock_bh(&bat_priv->softif_vlan_list_lock); - kref_get(&vlan->refcount); - hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list); - spin_unlock_bh(&bat_priv->softif_vlan_list_lock); - /* add a new TT local entry. This one will be marked with the NOPURGE * flag */