Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3305429rdh; Mon, 27 Nov 2023 10:41:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFu45+xbG+1OXAw8WO/uAzSS+1e1i0tdFn4k5FdTmcwzGBokfsTg0FHi2J3+47SbvWJGLG X-Received: by 2002:a05:6808:8d8:b0:3b8:6fcc:226d with SMTP id k24-20020a05680808d800b003b86fcc226dmr4818206oij.53.1701110519092; Mon, 27 Nov 2023 10:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701110519; cv=none; d=google.com; s=arc-20160816; b=Zm+zzK2ALpttZ1f4Ws5kxeMWzafphbc1wWvkn9cRt3QNFk9FkU7KPN/xvLZXia/h42 BHSpTFwk/4cue8Z4fVNqnJExPUbfBmeCa5XI/5wXtGyYWEHWIDlKcqLV7uAsBV+H2Cr7 1N5F3B/vJ5h/vShw52Zftn79z1+iSVDMPyJ/Uc8lIgiD1AJTj3fVM7SyNrYGwpp5PYbu vpIbL1978QDQNXXZ5RuULILcG755qqFgH3CCX5PNJ3sBoZrlpuipAZADoMFKwFN6YhaV xVChTA/LIg5qhKP12gFI1tk/muciwAdWePtyrq7xMzpA6xOmnjnO69v0Q49UnEL3YrTQ 57Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/HD2maULkgf1C+kN7CW043vRKDUmkhkPgxLAdbMck+U=; fh=MCacCfdu7vO2R+n2CGNAQ4bc94OH0BYEdiFeU/40A64=; b=Ph60w+eH13DMGc5HFWCA+JkS6H1lZuOUiBaStZIIkFykw+engCwvDA2GtjQVwHxem9 3YoeW9Qw2nqnVoVjNbgqAaAnwAjvli5pjh+dv0KO4UGbgy2MVOuM7gc2er9+AhDzf5ZI ODaH8p8eL3PYqiGST6SOE9b+o7gMTPoW+lgzsEfrj5RMZVOBhJXfF2H7FP0Hyj9y9O7X ZGxAd4z1WYR298s0t5coxI6HlUj9I3Rb4jO0hFbUq2rjXOuSlOJx6GCGEGplMcAC9T52 AksEm22yQVCoZgSmj26c02AQ6n5ysU6a2zNe9GanbppJrBsgCCLqTrd0BfExDsbAU/VU NQAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WrP7Sepx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bz42-20020a056a02062a00b00584aa817597si11315989pgb.101.2023.11.27.10.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:41:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WrP7Sepx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 9BBDF80E708A; Mon, 27 Nov 2023 10:41:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbjK0Slh (ORCPT + 99 others); Mon, 27 Nov 2023 13:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjK0Slg (ORCPT ); Mon, 27 Nov 2023 13:41:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD4119B; Mon, 27 Nov 2023 10:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701110502; x=1732646502; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ocdAfY8jzn+hMTXj3yEo5xBI/FMZYl5m4SnwH6zy1iQ=; b=WrP7Sepx1wpxKfH70ZtzRBacTYrA02L6m2GpkDbiicKWyc3gVgaEb2KE r0AuYGEMG8j4mprHXeCcerHlk0p53y5ns1N0x6hPPLwR0DDJR3eOqT6lj +iKBsFVqr9KqctPFYWuiTLnsX0DFKVTk+4JC7e1UuLEkzuxeVosZGSRNx sqVOTVMnNH/x5bqObRAogvXb0QjJBhoyTQLdtaThUgx9NzAQlviu8v3/T NL/orWzXZgMmwpJOFHhU5XfztdfYl0g9nuJ07keJMJOiPWvnXAbyxhGWa vlt4XnEgl0cIPQpJoYhaZZQ7HCXY1asxl0CwmjwYJrGxYagAUZEGNrf4X A==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="392517688" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="392517688" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 10:41:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="891820937" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="891820937" Received: from alanpai-mobl.amr.corp.intel.com (HELO [10.209.65.171]) ([10.209.65.171]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 10:41:41 -0800 Message-ID: Date: Mon, 27 Nov 2023 11:44:43 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] soundwire: stream: fix NULL pointer dereference for multi_link Content-Language: en-US To: Krzysztof Kozlowski , Vinod Koul , Bard Liao , Sanyog Kale , Shreyas NC , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org References: <20231124180136.390621-1-krzysztof.kozlowski@linaro.org> From: Pierre-Louis Bossart In-Reply-To: <20231124180136.390621-1-krzysztof.kozlowski@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 10:41:54 -0800 (PST) On 11/24/23 12:01, Krzysztof Kozlowski wrote: > If bus is marked as multi_link, but number of masters in the stream is > not higher than bus->hw_sync_min_links (bus->multi_link && m_rt_count >= > bus->hw_sync_min_links), bank switching should not happen. The first > part of do_bank_switch() code properly takes these conditions into > account, but second part (sdw_ml_sync_bank_switch()) relies purely on > bus->multi_link property. This is not balanced and leads to NULL > pointer dereference: > > Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 > ... > Call trace: > wait_for_completion_timeout+0x124/0x1f0 > do_bank_switch+0x370/0x6f8 > sdw_prepare_stream+0x2d0/0x438 > qcom_snd_sdw_prepare+0xa0/0x118 > sm8450_snd_prepare+0x128/0x148 > snd_soc_link_prepare+0x5c/0xe8 > __soc_pcm_prepare+0x28/0x1ec > dpcm_be_dai_prepare+0x1e0/0x2c0 > dpcm_fe_dai_prepare+0x108/0x28c > snd_pcm_do_prepare+0x44/0x68 > snd_pcm_action_single+0x54/0xc0 > snd_pcm_action_nonatomic+0xe4/0xec > snd_pcm_prepare+0xc4/0x114 > snd_pcm_common_ioctl+0x1154/0x1cc0 > snd_pcm_ioctl+0x54/0x74 > > Fixes: ce6e74d008ff ("soundwire: Add support for multi link bank switch") > Cc: > Signed-off-by: Krzysztof Kozlowski LGTM, thanks for the patch. Reviewed-by: Pierre-Louis Bossart > --- > drivers/soundwire/stream.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c > index 9dc6399f206a..f9c0adc0738d 100644 > --- a/drivers/soundwire/stream.c > +++ b/drivers/soundwire/stream.c > @@ -742,14 +742,15 @@ static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count) > * sdw_ml_sync_bank_switch: Multilink register bank switch > * > * @bus: SDW bus instance > + * @multi_link: whether this is a multi-link stream with hardware-based sync > * > * Caller function should free the buffers on error > */ > -static int sdw_ml_sync_bank_switch(struct sdw_bus *bus) > +static int sdw_ml_sync_bank_switch(struct sdw_bus *bus, bool multi_link) > { > unsigned long time_left; > > - if (!bus->multi_link) > + if (!multi_link) > return 0; > > /* Wait for completion of transfer */ > @@ -847,7 +848,7 @@ static int do_bank_switch(struct sdw_stream_runtime *stream) > bus->bank_switch_timeout = DEFAULT_BANK_SWITCH_TIMEOUT; > > /* Check if bank switch was successful */ > - ret = sdw_ml_sync_bank_switch(bus); > + ret = sdw_ml_sync_bank_switch(bus, multi_link); > if (ret < 0) { > dev_err(bus->dev, > "multi link bank switch failed: %d\n", ret);