Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754813AbbDTUYu (ORCPT ); Mon, 20 Apr 2015 16:24:50 -0400 Received: from mail-la0-f47.google.com ([209.85.215.47]:35829 "EHLO mail-la0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752466AbbDTUYr (ORCPT ); Mon, 20 Apr 2015 16:24:47 -0400 MIME-Version: 1.0 In-Reply-To: <20150420192844.GD20701@google.com> References: <1429546972-28400-1-git-send-email-ricardo.ribalda@gmail.com> <20150420192844.GD20701@google.com> From: Ricardo Ribalda Delgado Date: Mon, 20 Apr 2015 22:24:25 +0200 Message-ID: Subject: Re: [PATCH] kernel/resource: Invalid memory access in __release_resource To: Bjorn Helgaas Cc: Andrew Morton , Vivek Goyal , Vinod Koul , Cliff Wickman , Jiang Liu , Jakub Sitnicki , Thierry Reding , Mike Travis , LKML , Grant Likely Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2274 Lines: 70 Hi Bjorn! Thanks for your promtly response. On Mon, Apr 20, 2015 at 9:28 PM, Bjorn Helgaas wrote: > [+cc Grant (author of ac80a51e2ce5)] > > Hi Ricardo, > > On Mon, Apr 20, 2015 at 06:22:52PM +0200, Ricardo Ribalda Delgado wrote: >> >> If of_platform_depopulate is called later, resource->parent is >> accessed (Offset 0x30 of address 0), causing a kernel error. > > Interesting; how'd you find this? It looks like the > of_platform_depopulate() code has been this way for a long time, so we > must be doing something new that makes us trip over this now. More > analysis below... I have an out of tree driver that dynamically adds devices to the device tree. It was developed before the dynamic_of and dt_overlays existed. Now I am porting my code to the new interfaces available. I am trying to do it small steps. First step was being able to depopulate a previously loaded device tree. Old, code was calling of_platform_populate, so calling of_platform_depopulate looked like the right choice. Unfortunately everything crashed, and it turned out that this was the issue. On my defense I would say, that the plan is to make this driver public, once the hardware is stabilized and sold to the public. >> @@ -237,6 +237,9 @@ static int __release_resource(struct resource *old) >> { >> struct resource *tmp, **p; >> >> + if (!old->parent) >> + return -EINVAL; > > This path has been fine for a long time without testing for a NULL > pointer, so I suspect this change papers over an issue that would be > better fixed elsewhere. > This code is pretty tested, but dynamic remove is not. > From reading drivers/base/platform.c, it looks like the intent is > that platform device users would use these interfaces: I can take a look to modify OF to use insert_resource(), but I still think that no matter what, we should add this extra check, like the propossed patch or maybe with a BUG_ON().... Lets see what Grant thinks about this. Thanks again! -- Ricardo Ribalda -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/