Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp645840ybg; Thu, 19 Mar 2020 06:20:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu7kNEP7gDxc0hmz2KqBhh9+Aekx7sPYjOcVBQA1rhxBaFV/rA2LkEb6fAjYQTnK4oTujl1 X-Received: by 2002:a9d:1d07:: with SMTP id m7mr2136864otm.167.1584624045080; Thu, 19 Mar 2020 06:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584624045; cv=none; d=google.com; s=arc-20160816; b=ceWqSg1Ym+vb7WP6oxDWabWhGlQ6mx9BvdcBk3KEyPi/5NREW7tKIXSARCxVlGBaJD 9GjClXMOol8inqYaBkVjeAXn60nPZQ+l5UI9OBF5GmiHUsyO0Z6cx8zu8LGoKkVG72j4 6tWkNbSvN2QEO6GtZgV/AZ1VLLQqo1AijuCx0UL8sjDUeoQ1UQ6oMMUEyA0girYyVx4E OahNT1uZVj+XYSEzVUqBv/m2j/cx6PCUrSFg+YUGVX2xO8EQ0v57Mo3rCnqk3gzu1Csy hAcR4u5pcK29T+U7R1iVlUk8qVpi3eFVCgu8qDIQngZg+BfQQmVFJbjxGYBwnHU7RAcX M/TQ== 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=2/H/rDseY5ubY+oI6zY8D3dOPr5B/q5Cm3CPDRfGmBs=; b=PP5zuTC7zmRNNSDDC/uzdnIu0+P8//bhikaIKpQyDnNYPitF9zdTjiFCCi6HDA/bmM ar6kJb6SmyNwMoNDIQ9i8VBtQO5+pyD4UHVJ2Cz134bSu7E2TKkLSzcE+YrRaaxNw6vc sjeCaLs0stTV7LyzT0w1JOhSol/DA+um9I3ky9G6+CPUNMZcyDyLf7ZG4HZF6GX2TpUj SDj6mm18NnIz4fIIupSR+/u9wV1WlxsdqexAmwnUebMYR5BAwG2vJ1g11YUOJlzfm9L4 jW10FdCK6IkI5IuPS8uHteT0reuqNrtMB2F6YIFBCIN2YpZt7YGLWbQfiChx6FPfG4b6 DZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YsgIC3Hh; 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 x7si1230144oto.262.2020.03.19.06.20.31; Thu, 19 Mar 2020 06:20:45 -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=YsgIC3Hh; 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 S1729647AbgCSNSt (ORCPT + 99 others); Thu, 19 Mar 2020 09:18:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:41466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729643AbgCSNSr (ORCPT ); Thu, 19 Mar 2020 09:18:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 38856206D7; Thu, 19 Mar 2020 13:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584623926; bh=4kYPdKmtyljDUwQ9JZEsL/KXY+VsOeZgZEVW+G37tUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YsgIC3Hh/3VBTUMwisnyvdKyKcn9urDkuZIi9c4Ap8poP2zatzaP4fkahzjOUX2PG LkVqTKYpjSmo+iRTyz75KlHyIVdJZIS3R4C+uQBIG8mJXo+c+Gw+ObNYcUrg8qLatq +/QapmyXP9t1+w8YUv7tNw6GFxKDaNkbskK0sZr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Sven Eckelmann , Antonio Quartulli , Simon Wunderlich Subject: [PATCH 4.14 73/99] batman-adv: Avoid race in TT TVLV allocator helper Date: Thu, 19 Mar 2020 14:03:51 +0100 Message-Id: <20200319124003.298772732@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200319123941.630731708@linuxfoundation.org> References: <20200319123941.630731708@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Sven Eckelmann commit 8ba0f9bd3bdea1058c2b2676bec7905724418e40 upstream. The functions batadv_tt_prepare_tvlv_local_data and batadv_tt_prepare_tvlv_global_data are responsible for preparing a buffer which can be used to store the TVLV container for TT and add the VLAN information to it. This will be done in three phases: 1. count the number of VLANs and their entries 2. allocate the buffer using the counters from the previous step and limits from the caller (parameter tt_len) 3. insert the VLAN information to the buffer The step 1 and 3 operate on a list which contains the VLANs. The access to these lists must be protected with an appropriate lock or otherwise they might operate on on different entries. This could for example happen when another context is adding VLAN entries to this list. This could lead to a buffer overflow in these functions when enough entries were added between step 1 and 3 to the VLAN lists that the buffer room for the entries (*tt_change) is smaller then the now required extra buffer for new VLAN entries. Fixes: 7ea7b4a14275 ("batman-adv: make the TT CRC logic VLAN specific") Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli Signed-off-by: Simon Wunderlich Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/translation-table.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -872,7 +872,7 @@ batadv_tt_prepare_tvlv_global_data(struc struct batadv_orig_node_vlan *vlan; u8 *tt_change_ptr; - rcu_read_lock(); + spin_lock_bh(&orig_node->vlan_list_lock); hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) { num_vlan++; num_entries += atomic_read(&vlan->tt.num_entries); @@ -910,7 +910,7 @@ batadv_tt_prepare_tvlv_global_data(struc *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: - rcu_read_unlock(); + spin_unlock_bh(&orig_node->vlan_list_lock); return tvlv_len; } @@ -946,7 +946,7 @@ batadv_tt_prepare_tvlv_local_data(struct u8 *tt_change_ptr; int change_offset; - rcu_read_lock(); + spin_lock_bh(&bat_priv->softif_vlan_list_lock); hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { num_vlan++; num_entries += atomic_read(&vlan->tt.num_entries); @@ -984,7 +984,7 @@ batadv_tt_prepare_tvlv_local_data(struct *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: - rcu_read_unlock(); + spin_unlock_bh(&bat_priv->softif_vlan_list_lock); return tvlv_len; }