Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2505688imm; Mon, 24 Sep 2018 05:36:40 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb0XIFrro4RViFWKrxEBV3KUv8I3qkpDiRvsxLlvKUA7HIz0DFd4lu47d3iLiEhGUT7EGdd X-Received: by 2002:a63:d502:: with SMTP id c2-v6mr6253024pgg.324.1537792600358; Mon, 24 Sep 2018 05:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792600; cv=none; d=google.com; s=arc-20160816; b=Gx2Wl4CkO/loQ5wf2fbU0hWeTlKjQUrMK8Nj/PnZyrXZ6oBgaAtS+rZYuyva11lxu7 TZcthw8WdmmVgSCVwzWkZ98mIcETnU8D1qctXuSZK5Z5ugpr0ZQNuHI0ROdRN9XhcSow YCTIB8NJReUWtZW0j2O/a5n8Bj2YhhXFxYux/ZFsLyZS12KqzeiClo9YMkSEQozyYMGs JXr3VR7Qf7DH5QdghsgNWrQfZXjcjsXwRze41iZCP63KrXp2djvhEuLq/RPp/ltRaaBq QVuvq+H9Mklu/ezlJZi5NfxDsADaJzdvYm4wUDpwA6lUi/R2dN3coEJy29fa5Sh0jY0F l9aQ== 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; bh=hbVQxB5zU0I1An+rSzDHAteQ8d3dnexUH+jR0olMznw=; b=a5qgDW35yK6q/fjoEYsrWhohTVD/pYqjg5VcdTTMUB4+yCGiaNzAYZ7WlbxcD0gwhf BP3PByVl74kgYU5tCWHbn4ob8f4G2PaYsLOYIHwLYkhuQ5zGGdMkLDD0Ck35A942XIVO q1vGWThQ5hjOEZA6wegznbqJSyeyGr4sdfKcfViU3Fa+WCtudvFvep1MlBIBkzHsHkZV rxKSztAy7XDNon5g/Y+N913fYYcJinlunkkUiI8N3MPHB9td/yT4YbepvpquitLwuzRG 1zSsTyyUfPTpftJpeHtQV6V9GNR8+PNVkO34p71wy0npZ9nCr4rX7XRoYWAZMJeQiSCF 1spw== 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 f10-v6si34970765pfn.85.2018.09.24.05.36.24; Mon, 24 Sep 2018 05:36:40 -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; 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 S2388047AbeIXSgC (ORCPT + 99 others); Mon, 24 Sep 2018 14:36:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58400 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbeIXSgB (ORCPT ); Mon, 24 Sep 2018 14:36:01 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0FEB91018; Mon, 24 Sep 2018 12:34:04 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, George Cherian , Corey Minyard Subject: [PATCH 4.18 107/235] ipmi: Fix I2C client removal in the SSIF driver Date: Mon, 24 Sep 2018 13:51:33 +0200 Message-Id: <20180924113116.360812596@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@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: Corey Minyard commit 0745dde62835be7e2afe62fcdb482fcad79cb743 upstream. The SSIF driver was removing any client that came in through the platform interface, but it should only remove clients that it added. On a failure in the probe function, this could result in the following oops when the driver is removed and the client gets unregistered twice: CPU: 107 PID: 30266 Comm: rmmod Not tainted 4.18.0+ #80 Hardware name: Cavium Inc. Saber/Saber, BIOS Cavium reference firmware version 7.0 08/04/2018 pstate: 60400009 (nZCv daif +PAN -UAO) pc : kernfs_find_ns+0x28/0x120 lr : kernfs_find_and_get_ns+0x40/0x60 sp : ffff00002310fb50 x29: ffff00002310fb50 x28: ffff800a8240f800 x27: 0000000000000000 x26: 0000000000000000 x25: 0000000056000000 x24: ffff000009073000 x23: ffff000008998b38 x22: 0000000000000000 x21: ffff800ed86de820 x20: 0000000000000000 x19: ffff00000913a1d8 x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 5300737265766972 x13: 643d4d4554535953 x12: 0000000000000030 x11: 0000000000000030 x10: 0101010101010101 x9 : ffff800ea06cc3f9 x8 : 0000000000000000 x7 : 0000000000000141 x6 : ffff000009073000 x5 : ffff800adb706b00 x4 : 0000000000000000 x3 : 00000000ffffffff x2 : 0000000000000000 x1 : ffff000008998b38 x0 : ffff000008356760 Process rmmod (pid: 30266, stack limit = 0x00000000e218418d) Call trace: kernfs_find_ns+0x28/0x120 kernfs_find_and_get_ns+0x40/0x60 sysfs_unmerge_group+0x2c/0x6c dpm_sysfs_remove+0x34/0x70 device_del+0x58/0x30c device_unregister+0x30/0x7c i2c_unregister_device+0x84/0x90 [i2c_core] ssif_platform_remove+0x38/0x98 [ipmi_ssif] platform_drv_remove+0x2c/0x6c device_release_driver_internal+0x168/0x1f8 driver_detach+0x50/0xbc bus_remove_driver+0x74/0xe8 driver_unregister+0x34/0x5c platform_driver_unregister+0x20/0x2c cleanup_ipmi_ssif+0x50/0xd82c [ipmi_ssif] __arm64_sys_delete_module+0x1b4/0x220 el0_svc_handler+0x104/0x160 el0_svc+0x8/0xc Code: aa1e03e0 aa0203f6 aa0103f7 d503201f (7940e280) ---[ end trace 09f0e34cce8e2d8c ]--- Kernel panic - not syncing: Fatal exception SMP: stopping secondary CPUs Kernel Offset: disabled CPU features: 0x23800c38 So track the clients that the SSIF driver adds and only remove those. Reported-by: George Cherian Signed-off-by: Corey Minyard Tested-by: George Cherian Cc: # 4.14.x Signed-off-by: Greg Kroah-Hartman --- drivers/char/ipmi/ipmi_ssif.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -181,6 +181,8 @@ struct ssif_addr_info { struct device *dev; struct i2c_client *client; + struct i2c_client *added_client; + struct mutex clients_mutex; struct list_head clients; @@ -1641,15 +1643,7 @@ static int ssif_probe(struct i2c_client out: if (rv) { - /* - * Note that if addr_info->client is assigned, we - * leave it. The i2c client hangs around even if we - * return a failure here, and the failure here is not - * propagated back to the i2c code. This seems to be - * design intent, strange as it may be. But if we - * don't leave it, ssif_platform_remove will not remove - * the client like it should. - */ + addr_info->client = NULL; dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv); kfree(ssif_info); } @@ -1669,7 +1663,8 @@ static int ssif_adapter_handler(struct d if (adev->type != &i2c_adapter_type) return 0; - i2c_new_device(to_i2c_adapter(adev), &addr_info->binfo); + addr_info->added_client = i2c_new_device(to_i2c_adapter(adev), + &addr_info->binfo); if (!addr_info->adapter_name) return 1; /* Only try the first I2C adapter by default. */ @@ -1842,7 +1837,7 @@ static int ssif_platform_remove(struct p return 0; mutex_lock(&ssif_infos_mutex); - i2c_unregister_device(addr_info->client); + i2c_unregister_device(addr_info->added_client); list_del(&addr_info->link); kfree(addr_info);