Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755280AbdIGMTz (ORCPT ); Thu, 7 Sep 2017 08:19:55 -0400 Received: from mail-by2nam03on0082.outbound.protection.outlook.com ([104.47.42.82]:62784 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754219AbdIGMTx (ORCPT ); Thu, 7 Sep 2017 08:19:53 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jan.Glauber@cavium.com; Date: Thu, 7 Sep 2017 14:19:40 +0200 From: Jan Glauber To: Ulf Hansson Cc: David Daney , "linux-mmc@vger.kernel.org" , Rob Herring , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] mmc: cavium: Fix use-after-free in of_platform_device_destroy Message-ID: <20170907121940.GA22336@hc> References: <20170907112417.21495-1-jglauber@cavium.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [88.67.130.225] X-ClientProxiedBy: DB6PR0801CA0061.eurprd08.prod.outlook.com (2603:10a6:4:2b::29) To SN2PR07MB2592.namprd07.prod.outlook.com (2603:10b6:804:7::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37afdcca-8df0-4a1b-3f51-08d4f5eabd60 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN2PR07MB2592; X-Microsoft-Exchange-Diagnostics: 1;SN2PR07MB2592;3:ZVcCLMJ/0t89nBb4IIJM2CMg4lc73+u8tOTcbrxEQtKZLZ/9z29+IByqs3O1pqhJUz0YAnQSG9rG5ItZ2jNxe/nhgrifUN5AUq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0hVx6mrOZhIBYncu4DVbpO+E+8kNy+WgUZEh2O9xbb9B19EnxH4rUxxgvVsywl6mEix3a/BKPk8bChZOblX4Q6YHGK1lK/tFJGoNB+0Y5YuxGRMgeXxBek4GikMVycZPtUNzVQgG94PC9JP7K9ZV9bSUOHaWj1KoQMZOC0Z+wzSzgXYkhNnqPNJcb9sc4a04UTD5x8oEstOghGHYJIBUplX41dMVdTEndBYJBxS997DMFLzT2rS9720Ul8tRB4fI8PIlnz7V13n7BBPQbrYlbwmnTdFGs/lwDeqVkyKs1Ro84lHvnz0oRVjPtcp2VG7snbGaohXN3Q2i1BeJBhivj/s60J1q9JUW3t+vA=;4:wEuT94M/KNoriVcno21agvMuydKicrFklvSlJGXeIWrrHjK41525JK2uhZq3wzK3zKT2EudYoPkEXclItfeCaYxYiYbOhKubWrCXcxUBsPA5QjjBr5xonntsOT8EIz8HwP8Ec4IQK3qvi0gK81tjM9lctbFIZ3joEMF+WwecE+yrC+RP+9SXiS3QC81noNqsDUcPfb2Kq39zZb4Z20ZMWOgJyj5vz7Xcu8gcvoUKx87xURC8HZIki/W87aUFG0jV X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(3002001)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123558100)(20161123560025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN2PR07MB2592;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN2PR07MB2592; X-Forefront-PRVS: 04238CD941 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(199003)(189002)(24454002)(6496005)(47776003)(55016002)(8676002)(8936002)(9686003)(54906002)(81156014)(478600001)(72206003)(53936002)(66066001)(68736007)(189998001)(6246003)(106356001)(5660300001)(101416001)(4326008)(3846002)(23726003)(110136004)(81166006)(33656002)(6116002)(1076002)(50986999)(54356999)(76176999)(25786009)(50466002)(229853002)(2950100002)(83506001)(6666003)(42882006)(6916009)(53546010)(42186005)(4001350100001)(105586002)(230783001)(5890100001)(97736004)(33716001)(7736002)(305945005)(2906002)(18370500001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR07MB2592;H:hc;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR07MB2592;23:4Yf/CRw0JLaC6rTKToyV7vipze10KPQUzExjujs/q?= =?us-ascii?Q?5NpChf+tagKCK5ZpWYMryLXVRry/lzZbEY2LSD/Z85VDWiYS7rosP0n1z1ZN?= =?us-ascii?Q?+93/5Sf1/EtfYanjlHwDiZsDne27FWI1s5npQBlaeKuJK0Ago423RRKt/pzX?= =?us-ascii?Q?JRrOzZw/5k9E2LjWsrQUk9EEmR39DTSUQXYhyH2e/GaZ1p7KNxVabPqmYww4?= =?us-ascii?Q?JLtvrr0kHP2SgU9A1PBDGC3nC0/ozvvY96rbhlfNiLNhnc1QVAxaSrfszjoe?= =?us-ascii?Q?09yJe0DjVPwaN2BYogiRkF1UcSBnbecDm0c6n/K1gAOK3KBOSH8Gp2k0+JVb?= =?us-ascii?Q?W1XwRLt6RuZ2DbphvMIio9VnCpp1PsINGZ2bhw49iIu/fW18WVC5m8UzH87h?= =?us-ascii?Q?0dCIICuZMrkLEALSGVx3jSzOFcrOISY2v0Xqgzth9720JusCAZyY8VNBWSFk?= =?us-ascii?Q?6J2uPgSv5rJ5nwdhLIG/mXsRZwYLGIaqGOxzMpxU1/Qrl1X/wZY5TT/+1WLz?= =?us-ascii?Q?mAb/JDHFscg1y/0M3KCNutSAlO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A5QKiK8fsK1H4Y1fbrvCvFrMWydUEe6Xglkk9tV0aFcx0ccptUXDlTIWjum+6rTa0RFmeHgNWN/IEplf3qJ/I+rUxttTsQaKg7Ql77gclvQxCox890xOPCvmEUacHcMYEgvCC7f6wtDKr3HtWey+WZjDJt3jAgzBtGeqRkMFAP+3sjsB1uX3DzUAiJ17NIt6NRwAM14uxI1O35w==;5:p5C1sIgoYhzO7X2iKaAib0oplBQGyGAcZPuZLrTtMbi7xKg/380ZhdcoFtd0NnDtvgi1GMOY7wvhvTg7hapGGy+3DHm1TRk+Ic7tEeRYqaqK2YYlruo1emcR1E/9Ci949EeP+/GwjoFO3dfURxYjpw==;24:ouvno/NBn19aVt2mRlvCQ0b85JEerLXTJQvZ8YNL8qz08PhonzCztFoFLnqKClAS0BuiyvSlxipJeNGsmVBtjDzliJQvD98MSMhV0Y+y5Sk=;7:xd/XoG5ZlwHDd4E4fjTb/8XEeHZSpMg3YVpK0hv+KoMkMGOx+0levaLMM1Ihafwl2asymAmBKNv5fRe99Agyx3Au8pgDK5+u7qKqMKWwjdhCGeCgFXXhhS/SwZtqxkeaqIG3H+PyZYydphTn5GJbyajZaKCZAQC6H+D36swzvRNhrVNSgvM/SS83FMAZ4+dRJdDUZLs8ix7c7ZWKOxeg3ZS8YTz6JzCCh65nnmtxRlk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2017 12:19:50.2405 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR07MB2592 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4127 Lines: 91 Thanks Uffe. The fix would only be required for 4.13, as only with that the Cavium GPIO driver became available. --Jan On Thu, Sep 07, 2017 at 02:07:01PM +0200, Ulf Hansson wrote: > On 7 September 2017 at 13:24, Jan Glauber wrote: > > KASAN reported the following: > > > > [ 19.338655] ================================================================== > > [ 19.345946] BUG: KASAN: use-after-free in of_platform_device_destroy+0x88/0x100 > > [ 19.345966] Read of size 8 at addr fffffe01aa6f1468 by task systemd-udevd/264 > > > > [ 19.345983] CPU: 1 PID: 264 Comm: systemd-udevd Not tainted 4.13.0-jang+ #737 > > [ 19.345989] Hardware name: Cavium ThunderX CN81XX board (DT) > > [ 19.345995] Call trace: > > [ 19.346013] [] dump_backtrace+0x0/0x368 > > [ 19.346026] [] show_stack+0x24/0x30 > > [ 19.346040] [] dump_stack+0xa4/0xc8 > > [ 19.346057] [] print_address_description+0x68/0x258 > > [ 19.346070] [] kasan_report+0x238/0x2f8 > > [ 19.346082] [] __asan_load8+0x88/0xb8 > > [ 19.346098] [] of_platform_device_destroy+0x88/0x100 > > [ 19.346131] [] thunder_mmc_probe+0x314/0x550 [thunderx_mmc] > > [ 19.346147] [] pci_device_probe+0x158/0x1f8 > > [ 19.346162] [] driver_probe_device+0x394/0x5f8 > > [ 19.346174] [] __driver_attach+0x154/0x158 > > [ 19.346185] [] bus_for_each_dev+0xdc/0x140 > > [ 19.346196] [] driver_attach+0x38/0x48 > > [ 19.346207] [] bus_add_driver+0x290/0x3c8 > > [ 19.346219] [] driver_register+0xbc/0x1a0 > > [ 19.346232] [] __pci_register_driver+0xc4/0xd8 > > [ 19.346260] [] thunder_mmc_driver_init+0x24/0x10000 [thunderx_mmc] > > [ 19.346273] [] do_one_initcall+0x98/0x1c0 > > [ 19.346289] [] do_init_module+0xe0/0x2cc > > [ 19.346303] [] load_module+0x3238/0x35c0 > > [ 19.346318] [] SyS_finit_module+0x190/0x1a0 > > [ 19.346329] [] __sys_trace_return+0x0/0x4 > > > > This is caused by: > > > > platform_device_register() > > -> platform_device_unregister(to_platform_device(dev)) > > freeing struct device > > -> of_node_clear_flag(dev->of_node, ...) > > writing to the freed device > > > > The issue is solved by increasing the reference count before calling > > of_platform_device_destroy() so freeing the device is postponed after > > the call. > > > > Fixes: 8fb83b142823 ("mmc: cavium: Fix probing race with regulator") > > Signed-off-by: Jan Glauber > > Thanks, applied for fixes and added a stable tag. > > Kind regards > Uffe > > > --- > > drivers/mmc/host/cavium-thunderx.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c > > index b9cc95998799..eee08d81b242 100644 > > --- a/drivers/mmc/host/cavium-thunderx.c > > +++ b/drivers/mmc/host/cavium-thunderx.c > > @@ -7,6 +7,7 @@ > > * > > * Copyright (C) 2016 Cavium Inc. > > */ > > +#include > > #include > > #include > > #include > > @@ -149,8 +150,11 @@ static int thunder_mmc_probe(struct pci_dev *pdev, > > for (i = 0; i < CAVIUM_MAX_MMC; i++) { > > if (host->slot[i]) > > cvm_mmc_of_slot_remove(host->slot[i]); > > - if (host->slot_pdev[i]) > > + if (host->slot_pdev[i]) { > > + get_device(&host->slot_pdev[i]->dev); > > of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL); > > + put_device(&host->slot_pdev[i]->dev); > > + } > > } > > clk_disable_unprepare(host->clk); > > return ret; > > -- > > 2.9.0.rc0.21.g7777322 > >