Received: by 10.223.185.116 with SMTP id b49csp5457184wrg; Wed, 7 Mar 2018 12:05:28 -0800 (PST) X-Google-Smtp-Source: AG47ELsntyB4cgx5VMPUx8LtJDShD8HddNT75IwyLc+dneBF1QK57AP8Hf/ikDbdeszkegJuwSBN X-Received: by 10.98.224.208 with SMTP id d77mr23949348pfm.194.1520453128436; Wed, 07 Mar 2018 12:05:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520453128; cv=none; d=google.com; s=arc-20160816; b=Bl8eoxOBqhY5W4Q7eXeea79cKNfR6AV75f2vAcRUzfYAf+BWwo/5wodvjtVuplvtVu I8DrPJzqZgcGa4v79CH3NHV//BI7ZfpY/jx+f9ApdooQMiInbUmvqkqE/qHSOJTDeo+k 11lnZ1N0ozYNjOiU9J0UsXcQrVEM85JnGr8fwELVv2Fwfr7A/kGAfL6E+3JFOr/peK0Y AICFB6EIgMEaEY1xvQmDP70H4lLwk7PPpCwnphBbkYRkUE2EwTS2CA5fH6wXVT6WJSgd k5QKFXGlFjW7RFcMoeLECooTUeB7LZj/zb+RF5DequUGUuHlU/3Qkvyi+TeuL/BallgR C9CA== 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=zKlzBdirsUbwbNlGmhJlroNNIwqKG1kF+W6i73SZBFI=; b=mF4rS0geHRs19Ugq8ZnLWBE3lGOwv2jW9E6K9Eysvlmzg8Rkar/M7TtIL9Xi2ccl8p guWBwq4kqPfUi8WSOwUl2rb7c5vCZdQWzWIQVO6/kDcI0xuix7Zwhm+tRdOYuQk/ThYC 3cDOaqqPx0U14mcl/c/jPuxViY7YsnnPO6L2ubCE5+rNVmIBdciyuIp3krESrcdCaPzk n0aZauDuHTzAmEFyYRuplh5qBWowq+bmOEme8PSnUzSBTM2j6oJ8HMkw7y/D1PFiddyb /oDEXZw+U5ex1jWoMBYhYUBYTVoIDPKIx9d71+MXc2wtt84b6OwRrycRpR5azq1tqDeX 5oYg== 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 s3-v6si13333180plb.4.2018.03.07.12.05.14; Wed, 07 Mar 2018 12:05:28 -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 S965550AbeCGTqb (ORCPT + 99 others); Wed, 7 Mar 2018 14:46:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44612 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965521AbeCGTq2 (ORCPT ); Wed, 7 Mar 2018 14:46:28 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 89C381077; Wed, 7 Mar 2018 19:46:27 +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.14 062/110] mlxsw: spectrum_router: Fix error path in mlxsw_sp_vr_create Date: Wed, 7 Mar 2018 11:38:45 -0800 Message-Id: <20180307191047.501874963@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@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.14-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 | 19 ++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -729,26 +729,29 @@ static struct mlxsw_sp_fib *mlxsw_sp_vr_ static struct mlxsw_sp_vr *mlxsw_sp_vr_create(struct mlxsw_sp *mlxsw_sp, u32 tb_id) { + struct mlxsw_sp_fib *fib4; + struct mlxsw_sp_fib *fib6; struct mlxsw_sp_vr *vr; int err; vr = mlxsw_sp_vr_find_unused(mlxsw_sp); if (!vr) 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->fib4 = fib4; + vr->fib6 = fib6; vr->tb_id = tb_id; return vr; err_fib6_create: - mlxsw_sp_fib_destroy(vr->fib4); - vr->fib4 = NULL; + mlxsw_sp_fib_destroy(fib4); return ERR_PTR(err); }