Received: by 10.223.185.116 with SMTP id b49csp5488463wrg; Wed, 7 Mar 2018 12:39:03 -0800 (PST) X-Google-Smtp-Source: AG47ELs5+OD/uEawG78XQqGK1LtPYY6Wwb6CAUjjjlGHnhQEO2HhJfmdKcyDvkrkyZb8GJbrOO5T X-Received: by 2002:a17:902:a610:: with SMTP id u16-v6mr20702336plq.293.1520455143520; Wed, 07 Mar 2018 12:39:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520455143; cv=none; d=google.com; s=arc-20160816; b=u8XFoNbG0ZdKQPHd8OZvwsv0s/FJeZDcz3FLMcTxxVHZUUwYqfGsLpLkZDp/IpAzc+ ZuzylsYJ/uKbea8opsTxsofuHLdP4B/Cb8rKpV6N9MywQcqKhw6bG61cWL9syvis9OiT v/pUJqb1E9lUg6dT137TqNal3X3BfqAfuH2ImjPf4ZKMqW9lTAVUmn3rehrCSboiQoLR FAbIrxgKush7F1zW1krk96jsaYnA2s/CDh+/Be1ehjwT1kczTPYphLkS47v1RZD6VVpE b59w9tQ67gULowvxj2TMxkQ5DbWJpAX8DuQiPBsD/SXW1pF1DMBgcqBg5hnMI+RDINXV QkZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qPorU9eifrSUAvxYieLiE9FsEz8K6zYVEKZRS5Nz3A0=; b=FQJE/3Ntae+g7fmBNYSv3UKw5ks7+TWEIzT6EKjydgPZZvrIDvRZVPRFgzBuhWMNpJ SLlH+2iN3ulArPA1Pq5hGTSWTpU+pguOO0JinFgLqG36xb+WfSpWkt340mvLbGWNgTgR zuTib/UiVMpPp8TuQ/8EJHXtv52UoAwnmdsa7xgKsfwfFhfLpzNXPSFwA+7nS2hRt9XZ 3ZNdDTR29s8syF+pGRpM3OQ7rqu4Ld1R6SnSLwq2gz/ioaT4SqTnYfXEwUAJO/kErRkv tdfFZhT6ZrntVVpWC6mHY0uzVUvvdb1t6bqdDKiMKc0N8e35HiUFXHpdCfflfola5BL8 4A2w== 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 t10-v6si13353337plh.403.2018.03.07.12.38.49; Wed, 07 Mar 2018 12:39:03 -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 S1754840AbeCGTl5 (ORCPT + 99 others); Wed, 7 Mar 2018 14:41:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41426 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754826AbeCGTly (ORCPT ); Wed, 7 Mar 2018 14:41:54 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1EFF51016; Wed, 7 Mar 2018 19:41:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Pirko , Ido Schimmel , "David S. Miller" Subject: [PATCH 4.15 065/122] mlxsw: spectrum_router: Fix error path in mlxsw_sp_vr_create Date: Wed, 7 Mar 2018 11:37:57 -0800 Message-Id: <20180307191738.752433368@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Pirko [ Upstream commit 0f2d2b2736b08dafa3bde31d048750fbc8df3a31 ] Since mlxsw_sp_fib_create() and mlxsw_sp_mr_table_create() use ERR_PTR macro to propagate int err through return of a pointer, the return value is not NULL in case of failure. So if one of the calls fails, one of vr->fib4, vr->fib6 or vr->mr4_table is not NULL and mlxsw_sp_vr_is_used wrongly assumes that vr is in use which leads to crash like following one: [ 1293.949291] BUG: unable to handle kernel NULL pointer dereference at 00000000000006c9 [ 1293.952729] IP: mlxsw_sp_mr_table_flush+0x15/0x70 [mlxsw_spectrum] Fix this by using local variables to hold the pointers and set vr->* only in case everything went fine. Fixes: 76610ebbde18 ("mlxsw: spectrum_router: Refactor virtual router handling") Fixes: a3d9bc506d64 ("mlxsw: spectrum_router: Extend virtual routers with IPv6 support") Fixes: d42b0965b1d4 ("mlxsw: spectrum_router: Add multicast routes notification handling functionality") Signed-off-by: Jiri Pirko Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 32 ++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -737,6 +737,9 @@ static struct mlxsw_sp_vr *mlxsw_sp_vr_c u32 tb_id, struct netlink_ext_ack *extack) { + struct mlxsw_sp_mr_table *mr4_table; + struct mlxsw_sp_fib *fib4; + struct mlxsw_sp_fib *fib6; struct mlxsw_sp_vr *vr; int err; @@ -745,29 +748,30 @@ static struct mlxsw_sp_vr *mlxsw_sp_vr_c NL_SET_ERR_MSG(extack, "spectrum: Exceeded number of supported virtual routers"); return ERR_PTR(-EBUSY); } - vr->fib4 = mlxsw_sp_fib_create(vr, MLXSW_SP_L3_PROTO_IPV4); - if (IS_ERR(vr->fib4)) - return ERR_CAST(vr->fib4); - vr->fib6 = mlxsw_sp_fib_create(vr, MLXSW_SP_L3_PROTO_IPV6); - if (IS_ERR(vr->fib6)) { - err = PTR_ERR(vr->fib6); + fib4 = mlxsw_sp_fib_create(vr, MLXSW_SP_L3_PROTO_IPV4); + if (IS_ERR(fib4)) + return ERR_CAST(fib4); + fib6 = mlxsw_sp_fib_create(vr, MLXSW_SP_L3_PROTO_IPV6); + if (IS_ERR(fib6)) { + err = PTR_ERR(fib6); goto err_fib6_create; } - vr->mr4_table = mlxsw_sp_mr_table_create(mlxsw_sp, vr->id, - MLXSW_SP_L3_PROTO_IPV4); - if (IS_ERR(vr->mr4_table)) { - err = PTR_ERR(vr->mr4_table); + mr4_table = mlxsw_sp_mr_table_create(mlxsw_sp, vr->id, + MLXSW_SP_L3_PROTO_IPV4); + if (IS_ERR(mr4_table)) { + err = PTR_ERR(mr4_table); goto err_mr_table_create; } + vr->fib4 = fib4; + vr->fib6 = fib6; + vr->mr4_table = mr4_table; vr->tb_id = tb_id; return vr; err_mr_table_create: - mlxsw_sp_fib_destroy(vr->fib6); - vr->fib6 = NULL; + mlxsw_sp_fib_destroy(fib6); err_fib6_create: - mlxsw_sp_fib_destroy(vr->fib4); - vr->fib4 = NULL; + mlxsw_sp_fib_destroy(fib4); return ERR_PTR(err); }