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 X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F202CC433E0 for ; Fri, 5 Feb 2021 17:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E7EF64FBF for ; Fri, 5 Feb 2021 17:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233331AbhBEPpi (ORCPT ); Fri, 5 Feb 2021 10:45:38 -0500 Received: from mga17.intel.com ([192.55.52.151]:44434 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbhBEPa2 (ORCPT ); Fri, 5 Feb 2021 10:30:28 -0500 IronPort-SDR: CQpyMXpvhloMPV9YnhO5ZJAcZTZTCrOqrn6DfzfUdkj3rMbwABTUwFNyJtY5XnI4YTC+iSfGJI GjqrMx9MyVWw== X-IronPort-AV: E=McAfee;i="6000,8403,9885"; a="161207378" X-IronPort-AV: E=Sophos;i="5.81,155,1610438400"; d="scan'208";a="161207378" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2021 08:19:12 -0800 IronPort-SDR: vI6yDYYoX55QmM8S4GOE9030RMWx8Va+4uopWh1v0W10+ipUMXOR9zWIixyR3MgA17VIG9KaiR eVgeFxlfACKQ== X-IronPort-AV: E=Sophos;i="5.81,155,1610438400"; d="scan'208";a="393923553" Received: from gjcomber-mobl.amr.corp.intel.com (HELO [10.255.228.165]) ([10.255.228.165]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2021 08:19:11 -0800 Subject: Re: [PATCH] soundwire: intel: fix possible crash when no device is detected (was Re: Crash in acpi_ns_validate_handle triggered by soundwire on Linux 5.10) To: =?UTF-8?Q?Marcin_=c5=9alusarz?= , "Rafael J. Wysocki" Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Erik Kaneda , "Rafael J. Wysocki" , ACPI Devel Maling List , Vinod Koul , "Slusarz, Marcin" , Bard Liao , Len Brown References: <1dc2639a-ecbc-c554-eaf6-930256dcda96@linux.intel.com> From: Pierre-Louis Bossart Message-ID: Date: Fri, 5 Feb 2021 10:16:15 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Thanks Marcin for the patch, much appreciated. > acpi_walk_namespace can return success without executing our > callback which initializes info->handle. > If the random value in this structure is a valid address (which > is on the stack, so it's quite possible), then nothing bad will > happen, because: > sdw_intel_scan_controller > -> acpi_bus_get_device > -> acpi_get_device_data > -> acpi_get_data_full > -> acpi_ns_validate_handle > will reject this handle. > > However, if the value from the stack doesn't point to a valid > address, we get this: > > BUG: kernel NULL pointer dereference, address: 0000000000000050 [...] > diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c > index cabdadb09a1b..bc8520eb385e 100644 > --- a/drivers/soundwire/intel_init.c > +++ b/drivers/soundwire/intel_init.c > @@ -405,11 +405,12 @@ int sdw_intel_acpi_scan(acpi_handle *parent_handle, > { > acpi_status status; > > + info->handle = NULL; > status = acpi_walk_namespace(ACPI_TYPE_DEVICE, > parent_handle, 1, > sdw_intel_acpi_cb, > NULL, info, NULL); > - if (ACPI_FAILURE(status)) > + if (ACPI_FAILURE(status) || info->handle == NULL) > return -ENODEV; > > return sdw_intel_scan_controller(info); It does seem like a required code pattern if I look at I2C and SPI. I had no idea. Maybe worth documenting? Reviewed-by: Pierre-Louis Bossart