Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2222078imm; Thu, 18 Oct 2018 10:56:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV61zavW+mTtxgA4wD9t+Bll9LW0T28RMj0V1awbD2MIQh81NNjYxeFPQXWFHKGHIyuMBhvjA X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr3280521pll.67.1539885415493; Thu, 18 Oct 2018 10:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539885415; cv=none; d=google.com; s=arc-20160816; b=leCkmhnHNtkI2S8UPhw8fpu5HPuBK6vxuOsB1s7T84I63zUz0RKTxG2P2WYmQlOjPz wfuHwfrV8AncMNraphmDtYq1ohPGkU25C+i98UcbCI31/2fIFVAQLxrAqqJAV1Z7i67q LGC79vcqAQlqkfiKGjyVOlkcwWPysyxYBY+LJjfhPo331I0p65TEf7dXCu3F7/M/rzxC 1yL+98aqB/lrnKCwfVYQoE4oxsIMkhlMbpaVMoL53hYUyerb0u93OBlI5crbw1GYre34 NDlU3+Hhdt5WR/pMWijlEXqf3d/tHUAK+84GGaW7jxKc+dfAxLrAhh4x8iivx0TAahAn cx3g== 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=G8q92bRl9Oj7mNyA4HXwkO5+DqP0qf1ww1kePwsQd4k=; b=YzHGpn92gHHUgERE/SYbo+SrCSO6USSrHZTEolG7+vDOFihE8uKQ/qfzYxUGYp06Le vTLCBWtvfiyz/JaZ8ieQuhdgET3cGbqBseHFUBmp0B3V/B9LpqaGSVw/lNCfIbLWfUa/ JEy2AXJiDkFFPpFoGiyJ4rzrpb/g36yfjsTwYxT/s9SYwcm8rtlgZ9zLOQsur75K/Thj 9e+2uLGxDeAWBFWv7VUp/3O70aLXOP4FEqrnXb3+z0IvnoFzck5+jkLXUTJ/FR0lJiE+ NU737K00UKeJabxWDlLAwivEY06l38y6L7MtrkFuZMmBJz3GjkzEivjn5NR4PfzY0qEp hm3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qPGJb1ar; 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 f63-v6si23439023pfb.0.2018.10.18.10.56.40; Thu, 18 Oct 2018 10:56:55 -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=qPGJb1ar; 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 S1728442AbeJSB6I (ORCPT + 99 others); Thu, 18 Oct 2018 21:58:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:45968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728406AbeJSB6I (ORCPT ); Thu, 18 Oct 2018 21:58:08 -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 953472145D; Thu, 18 Oct 2018 17:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885362; bh=taIwoMVBuaxbUy5rE3m5fE0kAFC5CRfDExEaCPRwQk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qPGJb1arj6vV6YaF6zIP5O9Ak+ZnPZpaAvW5sI4VcEQhWgmPFZ5vDzpCsNombL+8H rKhw79K4JE1wqdc6ZNhQ8rrDV0QphgkurMOLhm93xqyuy9Ej9+o4kG3La7uFXcy8Kt EfXMId86NT9o/jCZT+JcfAUSyQAT2F3JlBHEIGLA= 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.18 11/53] batman-adv: Prevent duplicated softif_vlan entry Date: Thu, 18 Oct 2018 19:54:04 +0200 Message-Id: <20181018175418.798436397@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175416.561567978@linuxfoundation.org> References: <20181018175416.561567978@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.18-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 @@ -574,15 +574,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; @@ -590,17 +595,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 */