Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3005673imm; Sun, 1 Jul 2018 10:08:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ/1zWe/p1w5/dKW585IkBK3a2n/3LCd/adZXL2o4ksjfz3z+MQYzqszl55Ec0pyU3/R+2W X-Received: by 2002:a17:902:e101:: with SMTP id cc1-v6mr22578214plb.96.1530464907234; Sun, 01 Jul 2018 10:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530464907; cv=none; d=google.com; s=arc-20160816; b=Hq2RTHnIbIPxdSqUEAtkHepMyIyyC8rkASV6zRqlGjTco7km66AChF3KpUENjbz8K0 z51MT4nNB8zOb+8x7lrU3/Bn3tCcGvNkDdhkGrG32JJkPDD6dUDmboV6ilUu0t/EruR1 VhdUY8xhPMmp4bfjrM9o1s9k8z6sDiERpaUGPE4jP01xDoKJDlFkhAbDjb4Hjr74nNOe vCwqD9IronjaBsSmjffx9vFwaIo/XmkDmmBmss16J584QJ5vCnFEBEQ60/Vli1LpEtAM TOaI/iNF5b5P1yE0oNwCoSJOUkZCwi1xmKXXNJcZuSCumdAxz2sjdJjuKRFCyj2AJFMR vACw== 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=wC8Dh1qg2jS8vV2tE5xR6jn8HvEhBceoyWXR5o0GiFw=; b=gipm0joyAv9l3BYX/1EboW6T1wbY88Xd1Kf9CgTJksIoFj3EtEg2mI2ez+fhymO/cV QjfwHVFn7Fa6pjZ/Yoxc7NkgbtGRCQpsgwo6JEBWfAheAoyJh6DsFuGEnbPUmtyV6C3u /hZArdrLrDvd1YLd5SC71IVhW2q7nw2s1//z3R4dhk8Oauz/L7SOPHNuDQcGYmsMegQp Yr5mLTlpHKKcr6WZ9wfm4btfUdJdny0gDpuUrg52QBaenNmRKiNqJcY9hWgKbpdMaSsH 5YdULQ5a2WAzsu0vCCxATH3vjZKMkZ/JzVgGEk5rdQvFAge9ziAKQsvTNU8jgp2Nd1ac BOFg== 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 z23-v6si13671099pfh.266.2018.07.01.10.08.13; Sun, 01 Jul 2018 10:08:27 -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 S1753313AbeGARHk (ORCPT + 99 others); Sun, 1 Jul 2018 13:07:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37452 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032089AbeGAQlu (ORCPT ); Sun, 1 Jul 2018 12:41:50 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0A0E2AA6; Sun, 1 Jul 2018 16:41:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Kandagatla , Rob Herring Subject: [PATCH 4.17 080/220] of: platform: stop accessing invalid dev in of_platform_device_destroy Date: Sun, 1 Jul 2018 18:21:44 +0200 Message-Id: <20180701160911.778785774@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@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.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Srinivas Kandagatla commit 522811e944ed9b36806faa019faec10f9d259cca upstream. Immediately after the platform_device_unregister() the device will be cleaned up. Accessing the freed pointer immediately after that will crash the system. Found this bug when kernel is built with CONFIG_PAGE_POISONING and testing loading/unloading audio drivers in a loop on Qcom platforms. Fix this by moving of_node_clear_flag() just before the unregister calls. Below is the crash trace: Unable to handle kernel paging request at virtual address 6b6b6b6b6b6c03 Mem abort info: ESR = 0x96000021 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000021 CM = 0, WnR = 0 [006b6b6b6b6b6c03] address between user and kernel address ranges Internal error: Oops: 96000021 [#1] PREEMPT SMP Modules linked in: CPU: 2 PID: 1784 Comm: sh Tainted: G W 4.17.0-rc7-02230-ge3a63a7ef641-dirty #204 Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT) pstate: 80000005 (Nzcv daif -PAN -UAO) pc : clear_bit+0x18/0x2c lr : of_platform_device_destroy+0x64/0xb8 sp : ffff00000c9c3930 x29: ffff00000c9c3930 x28: ffff80003d39b200 x27: ffff000008bb1000 x26: 0000000000000040 x25: 0000000000000124 x24: ffff80003a9a3080 x23: 0000000000000060 x22: ffff00000939f518 x21: ffff80003aa79e98 x20: ffff80003aa3dae0 x19: ffff80003aa3c890 x18: ffff800009feb794 x17: 0000000000000000 x16: 0000000000000000 x15: ffff800009feb790 x14: 0000000000000000 x13: ffff80003a058778 x12: ffff80003a058728 x11: ffff80003a058750 x10: 0000000000000000 x9 : 0000000000000006 x8 : ffff80003a825988 x7 : bbbbbbbbbbbbbbbb x6 : 0000000000000001 x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000008 x2 : 0000000000000001 x1 : 6b6b6b6b6b6b6c03 x0 : 0000000000000000 Process sh (pid: 1784, stack limit = 0x (ptrval)) Call trace: clear_bit+0x18/0x2c q6afe_remove+0x20/0x38 apr_device_remove+0x30/0x70 device_release_driver_internal+0x170/0x208 device_release_driver+0x14/0x20 bus_remove_device+0xcc/0x150 device_del+0x10c/0x310 device_unregister+0x1c/0x70 apr_remove_device+0xc/0x18 device_for_each_child+0x50/0x80 apr_remove+0x18/0x20 rpmsg_dev_remove+0x38/0x68 device_release_driver_internal+0x170/0x208 device_release_driver+0x14/0x20 bus_remove_device+0xcc/0x150 device_del+0x10c/0x310 device_unregister+0x1c/0x70 qcom_smd_remove_device+0xc/0x18 device_for_each_child+0x50/0x80 qcom_smd_unregister_edge+0x3c/0x70 smd_subdev_remove+0x18/0x28 rproc_stop+0x48/0xd8 rproc_shutdown+0x60/0xe8 state_store+0xbc/0xf8 dev_attr_store+0x18/0x28 sysfs_kf_write+0x3c/0x50 kernfs_fop_write+0x118/0x1e0 __vfs_write+0x18/0x110 vfs_write+0xa4/0x1a8 ksys_write+0x48/0xb0 sys_write+0xc/0x18 el0_svc_naked+0x30/0x34 Code: d2800022 8b400c21 f9800031 9ac32043 (c85f7c22) ---[ end trace 32020935775616a2 ]--- Signed-off-by: Srinivas Kandagatla Cc: stable@vger.kernel.org Signed-off-by: Rob Herring Signed-off-by: Greg Kroah-Hartman --- drivers/of/platform.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -537,6 +537,9 @@ int of_platform_device_destroy(struct de if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) device_for_each_child(dev, NULL, of_platform_device_destroy); + of_node_clear_flag(dev->of_node, OF_POPULATED); + of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); + if (dev->bus == &platform_bus_type) platform_device_unregister(to_platform_device(dev)); #ifdef CONFIG_ARM_AMBA @@ -544,8 +547,6 @@ int of_platform_device_destroy(struct de amba_device_unregister(to_amba_device(dev)); #endif - of_node_clear_flag(dev->of_node, OF_POPULATED); - of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); return 0; } EXPORT_SYMBOL_GPL(of_platform_device_destroy);