Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2230371imm; Thu, 18 Oct 2018 11:04:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV63HmXdN/t33hVZ//WN2UgLpYEn498qNDCdKDwJRQvKNQvsUihj3k5rAoalRiiOTQJE/C3NP X-Received: by 2002:a63:2d07:: with SMTP id t7-v6mr10274074pgt.260.1539885873592; Thu, 18 Oct 2018 11:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539885873; cv=none; d=google.com; s=arc-20160816; b=0bRQE4mJavOvs1peD5v1rsU7h4mPBbYIAKzcfB7r1hZWEBHAKPELmnvLm06pye87jx sVvgYLFcII0GZYABnE4cCwKfCDWLvWGw01AawD37BEzDOs0IiPyKl0r9AUPUqbFxWsuv DYzxWoAhcEk9CVa0CMqE9n1yaaidxLz44xlOZWExdz6TjpnNJohSCjklTvAP1C6HvIr8 xzW8QivziSJ5Vspy1LIfKUId1FowOuKzyKs3IN60sCDvuozPJDQCL07k6VJwq/rv5dLW F8UG/FCE2SpG1M0WKA0RV/pBsPBE87aGQOziXltna33KNlrmUeVsE80jMaVEtlDpNgL2 Dllg== 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=/kIC3Vzg5+sXTDV52gMgHZUdNG5i4jpSbo5+OmURIKI=; b=L2dtX9IrawOijGeCfWJr+pg9kcHZ+LFDcu8hyZl5qXDJltSd6Rln5UHzgK3eHfKBLC L7SVXMwY7vwOaFV+/G5mbhGgzlzya9IOxD7vEL59U/5YCa62BgM79kjZOZsFA3sTMM0r uL+HhvYGOv6il7ETh/X9joPMwKovzO6xO8N4v8F0+hYDRx0101Jccw6Be+XOFgKED5G7 m4aC1RU0avO5Ev5vj60m4Ulobpu4/xyOEqOw/MstmzsyR2Hgw2urnusG+fbtMgYIoM49 lRkX5e5tRMh4SyTQEiko7pzzev0/nWdEUIfk/1t/ytQrMdseQuUoqCS6NWUdgGMtovR0 5DHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1Xr31rlJ; 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 b3-v6si15564555plc.103.2018.10.18.11.04.18; Thu, 18 Oct 2018 11:04:33 -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=1Xr31rlJ; 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 S1729657AbeJSCEA (ORCPT + 99 others); Thu, 18 Oct 2018 22:04:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729073AbeJSCD7 (ORCPT ); Thu, 18 Oct 2018 22:03:59 -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 C4B1721479; Thu, 18 Oct 2018 18:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885713; bh=thTN0OabMSy0NBoihD5tHi984mRK0S9+GYw0ZUzkZcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Xr31rlJbrnnu5RceXDxTMMkkb53OrQF96yYzr4DDKmU9+KXAyd1N4TdnD7Nn0dJO bTYGZwFG77jJwKshvfAlrVxHJBuzyjxDqcdkK3udN9EYjRHmkGnHSwHNzUIV8Jpmlx yPbxgw6o8Fu5Gw3owjUtDP+XR1PwGGYL68zzU1hs= 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.14 07/41] batman-adv: Prevent duplicated softif_vlan entry Date: Thu, 18 Oct 2018 19:54:22 +0200 Message-Id: <20181018175417.986474852@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175416.718399607@linuxfoundation.org> References: <20181018175416.718399607@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.14-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 @@ -566,15 +566,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; @@ -582,17 +587,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 */