Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2476200imd; Fri, 2 Nov 2018 12:04:39 -0700 (PDT) X-Google-Smtp-Source: AJdET5fJvTdnY7NTriJ4Et6znBZA4s2tm9z69xdQ/YWx/M+rF9fxkhBG+RoFPK4RpJTWyTkAyuvm X-Received: by 2002:a65:5a89:: with SMTP id c9-v6mr11649017pgt.216.1541185479515; Fri, 02 Nov 2018 12:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541185479; cv=none; d=google.com; s=arc-20160816; b=nLqL13GG1q0DaQ3+WuS+Vk20gccR9dalQU4U1gU7tj1ksqnx7QN0oeEZqlA7bIv4QZ lil4GSjXIdkQ1V3n7agKCdY34ktckogAuIAW5ECFuWyzDxN/qidqxYjHriGY6rWhtaAv BbtaEyF5r3ETHDP/LdJULUCOGpwQ/JhjSAq3HwXrbCkTr3songvQwD3gLGENXDP1SAyu FgtQquC3q3xsUnFxPFIPpE7YgfEh0B+tRpUqPmQGjggxTza0XZsk+pHtZFzsAxPDaEf2 BwOWuZn2QHUX/xnsgQe+Gmrx/j5Rh99uhZq2j18oNew7E2tkYJDj1gtufy8fkCuMzhSY eiJA== 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=u0kr424m0YVTcX2eG38oO2A4c6+kq9K7QfsAc7iruIY=; b=UejNSVhqaQFwlsYVjimySxUAx2wjotEfiojvPc4jRCXbvC5B5oskbWHMlROJixuYqD RkMANG8YTQqyQAnpjEdvukpyQcGlo1Z0iPpRP9gq5DruAQcz7WlHN7FP6SxCWJsZ1YFy WM7u0ZE3RFreSI61xckQh1fr6OFOzmzqD7s0vJ9a2UQMziyL3v0rxC3cdYzCRBuKRNb/ s+TZ/S3vDQRF1RXbe/tbEFuz+0sbrDOTXDwiBGz0HQxFuNKMmYbD5+pCPcSeFTARUdzS kUzFbbM2v/PnltFatEbBbiqfZn5aN3VUwkrVGib5motlukdNBe5qMOV+PRNUmw92R2Cb 26Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q13EsE6q; 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 s22-v6si48758386pfs.13.2018.11.02.12.04.24; Fri, 02 Nov 2018 12:04:39 -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=q13EsE6q; 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 S1730282AbeKCDyF (ORCPT + 99 others); Fri, 2 Nov 2018 23:54:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:49840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729310AbeKCDyE (ORCPT ); Fri, 2 Nov 2018 23:54:04 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 58C242084A; Fri, 2 Nov 2018 18:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184351; bh=qg8CpU78lH1OilsKxYb0PS/ZE73p/XI5xnpHgUtWS7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q13EsE6qPUqYEqB2U1aWLR4EKonFDICe0OgJHExz3V0QJm3RikmTRSBXd+Mt75Pa6 8IMk23Sy9lnCZrPqY11oT1XIefbB9WYm58SR89JPtc5Qz4Qp/cZl8edaM1ac23dJHw WxVzzd8b5fTpf/+wUSXBuC+Wwfux/7yho9ZAG77U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shalom Toledo , Jiri Pirko , Ido Schimmel , "David S. Miller" Subject: [PATCH 4.18 141/150] mlxsw: core: Fix devlink unregister flow Date: Fri, 2 Nov 2018 19:35:03 +0100 Message-Id: <20181102182912.333978872@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@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: Shalom Toledo [ Upstream commit a22712a962912faf257e857ab6857f56a93cfb34 ] After a failed reload, the driver is still registered to devlink, its devlink instance is still allocated and the 'reload_fail' flag is set. Then, in the next reload try, the driver's allocated devlink instance will be freed without unregistering from devlink and its components (e.g, resources). This scenario can cause a use-after-free if the user tries to execute command via devlink user-space tool. Fix by not freeing the devlink instance during reload (failed or not). Fixes: 24cc68ad6c46 ("mlxsw: core: Add support for reload") Signed-off-by: Shalom Toledo Reviewed-by: Jiri Pirko Signed-off-by: Ido Schimmel Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlxsw/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -985,8 +985,8 @@ static int mlxsw_devlink_core_bus_device mlxsw_core->bus, mlxsw_core->bus_priv, true, devlink); - if (err) - mlxsw_core->reload_fail = true; + mlxsw_core->reload_fail = !!err; + return err; } @@ -1126,8 +1126,15 @@ void mlxsw_core_bus_device_unregister(st const char *device_kind = mlxsw_core->bus_info->device_kind; struct devlink *devlink = priv_to_devlink(mlxsw_core); - if (mlxsw_core->reload_fail) - goto reload_fail; + if (mlxsw_core->reload_fail) { + if (!reload) + /* Only the parts that were not de-initialized in the + * failed reload attempt need to be de-initialized. + */ + goto reload_fail_deinit; + else + return; + } if (mlxsw_core->driver->fini) mlxsw_core->driver->fini(mlxsw_core); @@ -1140,9 +1147,12 @@ void mlxsw_core_bus_device_unregister(st if (!reload) devlink_resources_unregister(devlink, NULL); mlxsw_core->bus->fini(mlxsw_core->bus_priv); - if (reload) - return; -reload_fail: + + return; + +reload_fail_deinit: + devlink_unregister(devlink); + devlink_resources_unregister(devlink, NULL); devlink_free(devlink); mlxsw_core_driver_put(device_kind); }