Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp288171lqg; Thu, 11 Apr 2024 03:02:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwfF1qH3CGkNVTc2VcypjEGgwrBSxCLM1EVD9Cla8sVo2SqxgUGIyZgmrfFI4J8lpjF1JOhInYzVl3NsW49LqXM1IPxb6S3J6nbaMzTg== X-Google-Smtp-Source: AGHT+IH5TPAzzYD1+WK1fn2rXl59sz/zbzn/gn1jeNmIyWzJ+o3qwld8ld4mTjdfDb6c9m8KWg7E X-Received: by 2002:a05:6358:4b09:b0:17f:56be:8c95 with SMTP id kr9-20020a0563584b0900b0017f56be8c95mr5802970rwc.25.1712829721412; Thu, 11 Apr 2024 03:02:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712829721; cv=pass; d=google.com; s=arc-20160816; b=EkhzVXoBprY7omtJb/YK2Hj4lGGz1XkE7TSIsuKpZY3f35qZK7x6hNjy/nLc5STXDH kvSIb55OFnxuYKUlZ8Sw51ConWvsPJUYqtFgzPkxji+o+1UwB846HYVvTEV85yEd4Vpm Xb5tQLRJhKPJXFA7q/ZOwb+yXiCog4jPGN3lftHfKIIURYl8XqgBhEdC50L7b/dwmvt9 ka3G7e4w7xNmXGrOilLVytSCJ7TQazFpSRi2cAgiIaILf7F5MKUsE8w4k2wRUxCIyFCQ oZHTgXiJGcS/0wGNAI8mMn2OB5gHdfDSN/KjLUk1kAfxbiixZ8pYii8niKFRYDQqo7Do ye4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=wOKJQ8jt7AxSxSEOBwduE0YRgHhLkC7CChdOI3MJABQ=; fh=bxoh46Azsz8rHeuQiCqWbcKt9340We6e9Ahu/vpeRyc=; b=rPvFMOPyIPkXzsP3pApbBeAtX/gd5xw15Pom8weaccBYJ3JdiEZCJzzCvGD1VOJeUF ppoHJFVFZsmNhXeW1xUFhsgO4GVwtpypbXf7O4Jb1i9cpz8IaZPJUNhW7LMNzZr+EWEE GRawIpN6SESkW1PffZX1lwcsj4Ip+cH5srWtJbyELCv0FYnyMgpdWVR26ISdt8dWtemX 5maNwH/sk+PsQQd4BqInsaWZq/2rdoAi5S3NaE64q+6begeHeW8/rmEtRkXDXOeMsHng op0rqCi9spw9Dg0sxVpjgCnNUVJjZJtYoMdW9wtBkkVxiROVgMX2ipI6/BYiGBJqXeAT HcAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xU0CDoW/"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-140200-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k10-20020a635a4a000000b005dc85a758cfsi1000864pgm.169.2024.04.11.03.02.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 03:02:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140200-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xU0CDoW/"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-140200-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DDAFAB25DD6 for ; Thu, 11 Apr 2024 09:49:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E1EF145B0D; Thu, 11 Apr 2024 09:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xU0CDoW/" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6D0D145345 for ; Thu, 11 Apr 2024 09:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712828949; cv=none; b=o1cPPibUnNOoqH4LGZ5+Z/WQS+9WC2ikYGOANHuZiQp6PlQHX+EZcPoQVQ40mEwXFHsiiS9LLj5NtRk/NrWVJQglZzlvbLMQjl4GcgQUHjP2zYmfYzxD3Zd2TjUhaJwy6yNf7CtsPj4FgmBQ3MpDt/kEMDMYSVlff/T4Re3RBKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712828949; c=relaxed/simple; bh=VRFMeL1yR00t7d0ztD3oY+Cl355vb7WeMLBqLT3v9VQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fBMHLZ5k3YbjLJSyE8WPb8Qoyt/48Jt6YO42k6JQQyZoo08Z3kTExAmaG1VkP8uzOZYuujRiNJk0TB0SGzHXy+PNI/9qVxx4RApH6BrgUmmaOAxmmA4ALe2eQgu0x5bNOcI0rCbOrL8J66kkVhChb9K+2gNUrlqJpx9DLW3MHjI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xU0CDoW/; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-417d14b3b29so4276095e9.0 for ; Thu, 11 Apr 2024 02:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712828946; x=1713433746; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wOKJQ8jt7AxSxSEOBwduE0YRgHhLkC7CChdOI3MJABQ=; b=xU0CDoW/tHFm3EcpNoha8j0eWPMr/mW9jdLWcoeWtZN2nYcurlaUgzJYpVOyvk3OJo m0eHUnsAtCwtV1wNmhpm5CDo5jgwdQIQ8w5oXBgNLnLqMuX94lDtJp7Uf8g38db5Aykn U8Q2O5Csq6QqXdgwC/3S93pfsV40BXO+sAY+mcT5Od3AqncVz3pNke8BhADFPQCZ9hxH tpX6j/Ws1g5gYeYu4pC7gm5LAQXdJ6Zmfa1wPS/SFGYqIkZXYMLGMmnll31CXiQcz/js Ffil/PXhfKEGLq4wh/LkjhZcimlNJDv1mtCnl3OryV0ybTwfODymBQz+ssz6u6YppLGh L1Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712828946; x=1713433746; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wOKJQ8jt7AxSxSEOBwduE0YRgHhLkC7CChdOI3MJABQ=; b=fHswtMLyc5yEes5xxrv4rFC0cvJej+f71MhA5Zo73ll3RVvMkIPgyLIz06n+Scy3HN OzJKiddViqJm14kMFEAHiMaaFPKjOby93u6zz3n+nNk5nJJS2OGqp8eyDzkZKPRjhiqv LZAY7I7AqNjYgRY/+0xsfouokwDejO7+tmxBw4bwTYxOCPW4cIjQZyJoAGh4OAHs3kRF Kz77qM7qTI0gtr4XvAaJrfbwMYGHYDFXAIMNdfD9La5E5CqG0VwAYtnxDzcX742X0CON /ZlaNyeoMp35JCafY/rNKS00yY4Ahs+R4tC9MMiQRb0ubCrqKuEyjDA2SvjeC/oQf4XI tkkw== X-Forwarded-Encrypted: i=1; AJvYcCW7sEXkfJVsLopsSNUc2Cke8FMsTDDXRcxP0bX5qm7EQOd6CBK7VRRFLdQiNaLVf/hauYPSc3ov5ycuKGRxBFGGav94HcRbCWZXoiD2 X-Gm-Message-State: AOJu0YxT3cky5qjVXMbnHolaxcg22IzuRMcENrJtZsKUIEjYVxshMs3x +MCSKXcVHFDUqBOnOWdbrdtZKMu4Z4iTVY17dww3x8nxWnukBHgP/cLd0iT0fpA= X-Received: by 2002:a05:600c:4e94:b0:416:34c0:de9 with SMTP id f20-20020a05600c4e9400b0041634c00de9mr5015684wmq.29.1712828945966; Thu, 11 Apr 2024 02:49:05 -0700 (PDT) Received: from [192.168.1.195] ([5.133.47.210]) by smtp.googlemail.com with ESMTPSA id f11-20020adfdb4b000000b0033e7a102cfesm1356008wrj.64.2024.04.11.02.49.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Apr 2024 02:49:05 -0700 (PDT) Message-ID: Date: Thu, 11 Apr 2024 10:49:03 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 RESEND] slimbus: stream: Add null pointer check for client functions To: Viken Dadhaniya , andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: quic_msavaliy@quicinc.com, quic_vtanuku@quicinc.com, quic_anupkulk@quicinc.com, quic_cchiluve@quicinc.com References: <20240327083214.29443-1-quic_vdadhani@quicinc.com> Content-Language: en-US From: Srinivas Kandagatla In-Reply-To: <20240327083214.29443-1-quic_vdadhani@quicinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Thanks Viken for the patch, On 27/03/2024 08:32, Viken Dadhaniya wrote: > There is a possible scenario where client driver is calling > slimbus stream APIs in incorrect sequence and it might lead to > invalid null access of the stream pointer in slimbus > enable/disable/prepare/unprepare/free function. > > Fix this by checking validity of the stream before accessing in > all function API’s exposed to client. > > Signed-off-by: Viken Dadhaniya > --- > drivers/slimbus/stream.c | 37 +++++++++++++++++++++++++++++++++---- > 1 file changed, 33 insertions(+), 4 deletions(-) > > diff --git a/drivers/slimbus/stream.c b/drivers/slimbus/stream.c > index 1d6b38657917..c5a436fd0952 100644 > --- a/drivers/slimbus/stream.c > +++ b/drivers/slimbus/stream.c > @@ -202,10 +202,16 @@ static int slim_get_prate_code(int rate) > int slim_stream_prepare(struct slim_stream_runtime *rt, > struct slim_stream_config *cfg) > { > - struct slim_controller *ctrl = rt->dev->ctrl; > + struct slim_controller *ctrl; > struct slim_port *port; > int num_ports, i, port_id, prrate; > > + if (!rt || !cfg) { > + pr_err("%s: Stream or cfg is NULL, Check from client side\n", __func__); Please use dev_err where possible --srini > + return -EINVAL; > + } > + > + ctrl = rt->dev->ctrl; > if (rt->ports) { > dev_err(&rt->dev->dev, "Stream already Prepared\n"); > return -EINVAL; > @@ -358,9 +364,15 @@ int slim_stream_enable(struct slim_stream_runtime *stream) > { > DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION, > 3, SLIM_LA_MANAGER, NULL); > - struct slim_controller *ctrl = stream->dev->ctrl; > + struct slim_controller *ctrl; > int ret, i; > > + if (!stream) { > + pr_err("%s: Stream is NULL, Check from client side\n", __func__); > + return -EINVAL; > + } > + > + ctrl = stream->dev->ctrl; > if (ctrl->enable_stream) { > ret = ctrl->enable_stream(stream); > if (ret) > @@ -411,12 +423,18 @@ int slim_stream_disable(struct slim_stream_runtime *stream) > { > DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION, > 3, SLIM_LA_MANAGER, NULL); > - struct slim_controller *ctrl = stream->dev->ctrl; > + struct slim_controller *ctrl; > int ret, i; > > + if (!stream) { > + pr_err("%s: Stream is NULL, Check from client side\n", __func__); > + return -EINVAL; > + } > + > if (!stream->ports || !stream->num_ports) > return -EINVAL; > > + ctrl = stream->dev->ctrl; > if (ctrl->disable_stream) > ctrl->disable_stream(stream); > > @@ -448,6 +466,11 @@ int slim_stream_unprepare(struct slim_stream_runtime *stream) > { > int i; > > + if (!stream) { > + pr_err("%s: Stream is NULL, Check from client side\n", __func__); > + return -EINVAL; > + } > + > if (!stream->ports || !stream->num_ports) > return -EINVAL; > > @@ -476,8 +499,14 @@ EXPORT_SYMBOL_GPL(slim_stream_unprepare); > */ > int slim_stream_free(struct slim_stream_runtime *stream) > { > - struct slim_device *sdev = stream->dev; > + struct slim_device *sdev; > + > + if (!stream) { > + pr_err("%s: Stream is NULL, Check from client side\n", __func__); > + return -EINVAL; > + } > > + sdev = stream->dev; > spin_lock(&sdev->stream_list_lock); > list_del(&stream->node); > spin_unlock(&sdev->stream_list_lock);