Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13335669ybl; Sun, 29 Dec 2019 09:33:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxPMutW7IEif4zzoihMti5LX2NqJXbspFuFrNndt9OELhZDeehayDffiy3dsgJuNXrdH1p2 X-Received: by 2002:a05:6830:1755:: with SMTP id 21mr69642351otz.323.1577640810383; Sun, 29 Dec 2019 09:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577640810; cv=none; d=google.com; s=arc-20160816; b=ABYdnVuu00uKpMnZjEuAvfGWOp7mufvCAZS/IR0oOh6AI6Y+GSwBt5Xbjk0Qdkojyz Fqe0oNwxm0Lnv6rsdOmQ9SeruasRrquc0cV72jW0uma14H4bROJyedSvQbzfQQdZTMN7 tpU9nlaRCAspKknAv54blFP6qYMnB9AZ0+zJ8IofkqACAVk1/VJpMRKka4MtYvVhA1Q8 n3vbNW2G5tUnCcqapJdUMTspPCt6eef+Ko6sBKG/j3G8uUTbsLvDTYS0uaoKikgZifFQ HLyLelIhiyYeq/YdTmrtyULvmAlj/nk0Trz0ZlCbhNXfUvQg4MUbtE3oPIM3fpOfwb/z FrYg== 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=feNHDImjqNjv7DA5uBzDzAR5+Uev3++U8NqtyoHOrMA=; b=DIQt0kEdm+iBQGsEfdoUTy29ofPs10R9WeLWOAh+IH7JxwpuHE8fgLKSwKfGJ8znE9 aG7iUTdlQBUY5kyHwr1sJnCf/8GvWzt4cBI0YEZRtffv1dsG0jhSQZK6U4EDZ9xlb70j gkaxCDs9OJVgx4f6b9b8/adDMU6GknDEkLZh829SLXW3Tq55Lt8cfGfUsle4WuBb8zQn VgpoCE/mO9iwwUndSsbR4qZ7PVB1oIHHce1/aoAqTv0jRjNyaiSSlefrr2wnjjJsINh5 TW9kcF4l25SfptCo0f4Q0ys+2vN2DRF1EMJA2OxNnXXmFy16GzrtNwWLaxBrRND0Oyzh p8NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Udkz/1XN"; 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 x11si4011377oic.185.2019.12.29.09.33.19; Sun, 29 Dec 2019 09:33:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b="Udkz/1XN"; 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 S1729289AbfL2RcP (ORCPT + 99 others); Sun, 29 Dec 2019 12:32:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:60568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729264AbfL2RcO (ORCPT ); Sun, 29 Dec 2019 12:32:14 -0500 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 E292F21744; Sun, 29 Dec 2019 17:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640733; bh=L/byCmbk7ZaHYHTfMACnQugc5v7EjSd8LbO9F2snzSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Udkz/1XNBbvFbW6LCYRAiEMrodRJgo/JFBWUzHse1c6PY9dF1cqvTTLRe2MgB7ucA W0ySRVd2GK00WGaD25NsInZxrQnbXl4YwcpaYoJ+hFLKwtTpUhfSwDCQMpy74sszp5 kZ/gXsptyPl/4WeXVt5AydLXKp8LGZHmabj/EpVs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, tony camuso , Corey Minyard , Sasha Levin Subject: [PATCH 4.19 089/219] ipmi: Dont allow device module unload when in use Date: Sun, 29 Dec 2019 18:18:11 +0100 Message-Id: <20191229162520.260768030@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@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: Corey Minyard [ Upstream commit cbb79863fc3175ed5ac506465948b02a893a8235 ] If something has the IPMI driver open, don't allow the device module to be unloaded. Before it would unload and the user would get errors on use. This change is made on user request, and it makes it consistent with the I2C driver, which has the same behavior. It does change things a little bit with respect to kernel users. If the ACPI or IPMI watchdog (or any other kernel user) has created a user, then the device module cannot be unloaded. Before it could be unloaded, This does not affect hot-plug. If the device goes away (it's on something removable that is removed or is hot-removed via sysfs) then it still behaves as it did before. Reported-by: tony camuso Signed-off-by: Corey Minyard Tested-by: tony camuso Signed-off-by: Sasha Levin --- drivers/char/ipmi/ipmi_msghandler.c | 23 ++++++++++++++++------- include/linux/ipmi_smi.h | 12 ++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 84c17f936c09..91f2d9219489 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -447,6 +447,8 @@ enum ipmi_stat_indexes { #define IPMI_IPMB_NUM_SEQ 64 struct ipmi_smi { + struct module *owner; + /* What interface number are we? */ int intf_num; @@ -1139,6 +1141,11 @@ int ipmi_create_user(unsigned int if_num, if (rv) goto out_kfree; + if (!try_module_get(intf->owner)) { + rv = -ENODEV; + goto out_kfree; + } + /* Note that each existing user holds a refcount to the interface. */ kref_get(&intf->refcount); @@ -1269,6 +1276,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) } kref_put(&intf->refcount, intf_free); + module_put(intf->owner); } int ipmi_destroy_user(struct ipmi_user *user) @@ -2384,7 +2392,7 @@ static int __get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc) * been recently fetched, this will just use the cached data. Otherwise * it will run a new fetch. * - * Except for the first time this is called (in ipmi_register_smi()), + * Except for the first time this is called (in ipmi_add_smi()), * this will always return good data; */ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc, @@ -3304,10 +3312,11 @@ static void redo_bmc_reg(struct work_struct *work) kref_put(&intf->refcount, intf_free); } -int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, - void *send_info, - struct device *si_dev, - unsigned char slave_addr) +int ipmi_add_smi(struct module *owner, + const struct ipmi_smi_handlers *handlers, + void *send_info, + struct device *si_dev, + unsigned char slave_addr) { int i, j; int rv; @@ -3333,7 +3342,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, return rv; } - + intf->owner = owner; intf->bmc = &intf->tmp_bmc; INIT_LIST_HEAD(&intf->bmc->intfs); mutex_init(&intf->bmc->dyn_mutex); @@ -3440,7 +3449,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, return rv; } -EXPORT_SYMBOL(ipmi_register_smi); +EXPORT_SYMBOL(ipmi_add_smi); static void deliver_smi_err_response(struct ipmi_smi *intf, struct ipmi_smi_msg *msg, diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h index 7d5fd38d5282..1995ce146789 100644 --- a/include/linux/ipmi_smi.h +++ b/include/linux/ipmi_smi.h @@ -211,10 +211,14 @@ static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd, * is called, and the lower layer must get the interface from that * call. */ -int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, - void *send_info, - struct device *dev, - unsigned char slave_addr); +int ipmi_add_smi(struct module *owner, + const struct ipmi_smi_handlers *handlers, + void *send_info, + struct device *dev, + unsigned char slave_addr); + +#define ipmi_register_smi(handlers, send_info, dev, slave_addr) \ + ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr) /* * Remove a low-level interface from the IPMI driver. This will -- 2.20.1