From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CF9AC64EC4 for ; Fri, 10 Mar 2023 07:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229541AbjCJHvT (ORCPT ); Fri, 10 Mar 2023 02:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbjCJHvP (ORCPT ); Fri, 10 Mar 2023 02:51:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 691656FFF2 for ; Thu, 9 Mar 2023 23:51:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 085DA60EFC for ; Fri, 10 Mar 2023 07:51:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06124C433EF; Fri, 10 Mar 2023 07:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678434670; bh=/Bq/av451YzweCCOPw+RantvVT9w+XlNfixUTmOPEB8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zurZTbOP/tkaifQfk97LY1Z04bkumFbIV604E7GQEPEDrAZRfzSNnVfgQg1rgbRBZ duLByxrJUnkaAVpKc5Jp+hTGJMBR6+HPnQLUbcNdXoU3c3/l0R9e1au+MAF4UgC+j8 kT1NAULYxvvb47UGLjvpAm5w+DEjr1E2mou1kd1s= Date: Fri, 10 Mar 2023 08:51:07 +0100 From: Greg KH To: Xujun Leng Cc: linux-kernel@vger.kernel.org, rafael@kernel.org Subject: Re: [PATCH] driver core: platform: added arguments check for platform_device_add_resources() Message-ID: References: <20230310065546.22948-1-lengxujun2007@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230310065546.22948-1-lengxujun2007@126.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 10, 2023 at 02:55:46PM +0800, Xujun Leng wrote: > > On Tue, Mar 07, 2023 at 01:01:16PM +0800, Xujun Leng wrote: > > > In the follow two cases, platform_device_add_resources() can lead an > > > invalid address access: > > > 1) If (!res && num > 0), pdev->resource will be set to NULL but > > > pdev->num_resources > 0, then a later platform_get_resource() will > > > cause invalid address access. > > > 2) If (res && num == 0), because num == 0 cause kmalloc_slab() returns > > > ZERO_SIZE_PTR, then kmemdup() will copy data to the invalid address > > > ZERO_SIZE_PTR. > > > > > > Signed-off-by: Xujun Leng > > > --- > > > drivers/base/platform.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > > > index 77510e4f47de..a060941c3076 100644 > > > --- a/drivers/base/platform.c > > > +++ b/drivers/base/platform.c > > > @@ -606,6 +606,9 @@ int platform_device_add_resources(struct platform_device *pdev, > > > { > > > struct resource *r = NULL; > > > > > > + if ((!res && num > 0) || (res && num == 0)) > > > + return -EINVAL; > > > > What driver is causing this check to fail today? Shouldn't that be > > fixed instead? > > Ok, I got it. It's the caller's responsibility to take care about that. Maybe, I don't know, which is why I am asking what driver is triggering this kind of failure. Can you point me at one that causes this so we can see if this is something that a driver should be catching before it calls this, or if it is something that this core function should catch instead? thanks, greg k-h