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 3C0DBC64EC4 for ; Thu, 9 Mar 2023 14:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjCIOkT (ORCPT ); Thu, 9 Mar 2023 09:40:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbjCIOjw (ORCPT ); Thu, 9 Mar 2023 09:39:52 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F5E220D3B for ; Thu, 9 Mar 2023 06:39:40 -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 ams.source.kernel.org (Postfix) with ESMTPS id B0384B81F67 for ; Thu, 9 Mar 2023 14:39:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFDC0C433D2; Thu, 9 Mar 2023 14:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678372776; bh=T5nXg/4LXB+VY3G0+46vhcHTV8PSa4/9S9CnJT4Ds0Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YNcIhDFdht3aO1z6kVh/7Cw11EpOABpIhJhX/EhQRVsbB1m1FBEDVZu5I7scnZiP9 /SWxyTttC/s94w5VZm+OIcUSSPf2sIu9N+S8f9iYlRIY2CeMuVQu/VB14mVOXOoA8B h5ttNDCo8nqQAgakZFlDdHIYToBMtq8SqiBkj6/0= Date: Thu, 9 Mar 2023 15:39:33 +0100 From: Greg KH To: Xujun Leng Cc: rafael@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] driver core: platform: added arguments check for platform_device_add_resources() Message-ID: References: <20230307050116.12019-1-lengxujun2007@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230307050116.12019-1-lengxujun2007@126.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? thanks, greg k-h