mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: ipa: Fix enabled_state leak in ipa_smp2p_init()
@ 2026-09-17 11:52 Wentao Liang
  2026-09-17 12:17 ` Alex Elder
  0 siblings, 1 reply; 3+ messages in thread
From: Wentao Liang @ 2026-09-17 11:52 UTC (permalink / raw)
  To: andrew+netdev
  Cc: davem, edumazet, elder, kuba, linux-kernel, netdev, pabeni,
	Wentao Liang, stable

qcom_smem_state_get() takes a reference on the state, but
ipa_smp2p_init() returns without releasing the "ipa-clock-enabled" state
when the bit number is out of range, when the smp2p structure cannot be
allocated, and on the error paths that free the structure. Release the
reference on all of these paths.

Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/net/ipa/ipa_smp2p.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c
index 2f0ccdd937cc..78f6df2cad76 100644
--- a/drivers/net/ipa/ipa_smp2p.c
+++ b/drivers/net/ipa/ipa_smp2p.c
@@ -239,12 +239,16 @@ ipa_smp2p_init(struct ipa *ipa, struct platform_device *pdev, bool modem_init)
 					    &enabled_bit);
 	if (IS_ERR(enabled_state))
 		return PTR_ERR(enabled_state);
-	if (enabled_bit >= 32)		/* BITS_PER_U32 */
+	if (enabled_bit >= 32) {	/* BITS_PER_U32 */
+		qcom_smem_state_put(enabled_state);
 		return -EINVAL;
+	}
 
 	smp2p = kzalloc_obj(*smp2p);
-	if (!smp2p)
+	if (!smp2p) {
+		qcom_smem_state_put(enabled_state);
 		return -ENOMEM;
+	}
 
 	smp2p->ipa = ipa;
 
@@ -288,6 +292,7 @@ ipa_smp2p_init(struct ipa *ipa, struct platform_device *pdev, bool modem_init)
 err_null_smp2p:
 	ipa->smp2p = NULL;
 	mutex_destroy(&smp2p->mutex);
+	qcom_smem_state_put(enabled_state);
 	kfree(smp2p);
 
 	return ret;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ipa: Fix enabled_state leak in ipa_smp2p_init()
  2026-09-17 11:52 [PATCH] net: ipa: Fix enabled_state leak in ipa_smp2p_init() Wentao Liang
@ 2026-09-17 12:17 ` Alex Elder
  2026-11-08 10:27   ` Wentao Liang
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Elder @ 2026-09-17 12:17 UTC (permalink / raw)
  To: Wentao Liang, andrew+netdev
  Cc: davem, edumazet, elder, kuba, linux-kernel, netdev, pabeni, stable

On 9/17/26 6:52 AM, Wentao Liang wrote:
> qcom_smem_state_get() takes a reference on the state, but
> ipa_smp2p_init() returns without releasing the "ipa-clock-enabled" state
> when the bit number is out of range, when the smp2p structure cannot be
> allocated, and on the error paths that free the structure. Release the
> reference on all of these paths.

Where did you get the code used in this patch?  It doesn't
match what is currently present in Linux v7.2.

This issue was reported and already fixed:
   96ca1e658ae45 net: ipa: fix SMEM state handle leaks in SMP2P init

					-Alex

> Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   drivers/net/ipa/ipa_smp2p.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c
> index 2f0ccdd937cc..78f6df2cad76 100644
> --- a/drivers/net/ipa/ipa_smp2p.c
> +++ b/drivers/net/ipa/ipa_smp2p.c
> @@ -239,12 +239,16 @@ ipa_smp2p_init(struct ipa *ipa, struct platform_device *pdev, bool modem_init)
>   					    &enabled_bit);
>   	if (IS_ERR(enabled_state))
>   		return PTR_ERR(enabled_state);
> -	if (enabled_bit >= 32)		/* BITS_PER_U32 */
> +	if (enabled_bit >= 32) {	/* BITS_PER_U32 */
> +		qcom_smem_state_put(enabled_state);
>   		return -EINVAL;
> +	}
>   
>   	smp2p = kzalloc_obj(*smp2p);
> -	if (!smp2p)
> +	if (!smp2p) {
> +		qcom_smem_state_put(enabled_state);
>   		return -ENOMEM;
> +	}
>   
>   	smp2p->ipa = ipa;
>   
> @@ -288,6 +292,7 @@ ipa_smp2p_init(struct ipa *ipa, struct platform_device *pdev, bool modem_init)
>   err_null_smp2p:
>   	ipa->smp2p = NULL;
>   	mutex_destroy(&smp2p->mutex);
> +	qcom_smem_state_put(enabled_state);
>   	kfree(smp2p);
>   
>   	return ret;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ipa: Fix enabled_state leak in ipa_smp2p_init()
  2026-09-17 12:17 ` Alex Elder
@ 2026-11-08 10:27   ` Wentao Liang
  0 siblings, 0 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-08 10:27 UTC (permalink / raw)
  To: Alex Elder
  Cc: andrew+netdev, davem, edumazet, elder, kuba, linux-kernel,
	netdev, pabeni, vulab

Hi Alex,

Sorry for the very late reply, and for the noise.

You are right on both points.  This is already fixed by 96ca1e658ae45
("net: ipa: fix SMEM state handle leaks in SMP2P init"), which has been
in mainline since v7.2-rc2 and releases both SMEM state handles on the
init error paths and in ipa_smp2p_exit().  My patch is a duplicate, and
on its own it would also have been incomplete: it only handles
enabled_state and leaves ipa_smp2p_exit() untouched.  No v2 is needed;
please disregard it.

On where the code came from: the diff was generated from an old snapshot
of the tree (v7.1-rc4 based), not from v7.2, and I did not rebase or
recheck it against the current tree before sending.  That is why the
context does not match what v7.2 has now.  The candidate itself came from
our static analysis tooling; DeepSeek and GPT-6.1 Sol were used to audit
the finding and to help write the change, and I reviewed the result
myself before sending it.  Checking it against the tree of the day was my
job and I skipped it, so I am sorry you spent review time on this.

I am working through the rest of the feedback by hand now.

Thanks,
Wentao


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-08 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 11:52 [PATCH] net: ipa: Fix enabled_state leak in ipa_smp2p_init() Wentao Liang
2026-09-17 12:17 ` Alex Elder
2026-11-08 10:27   ` Wentao Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®