From: Yu Zhang <yuz08559@gmail.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] stm class: clear output->pdrv_private when the output is freed
Date: Sun, 1 Nov 2026 16:23:43 +1000 [thread overview]
Message-ID: <20261101062343.16629-1-yuz08559@gmail.com> (raw)
sys_t_output_close() frees output->pdrv_private but leaves the pointer
in place, and stm_output_free() only calls the output_close() of the
protocol driver that is bound when the output is freed. The protocol
driver of an stm device can be changed while an output is unassigned,
by removing the policy and creating one for another protocol, so the
stale pointer survives a re-assignment under a driver that has no
output_open() and is dereferenced again once the sys-t driver is bound
back:
P=/sys/kernel/config/stp-policy
L=/sys/class/stm_source/heartbeat.0/stm_source_link
mkdir $P/dummy_stm.0:p_sys-t.a $P/dummy_stm.0:p_sys-t.a/heartbeat.0
echo dummy_stm.0 > $L # sys_t_output_open() allocates pdrv_private
echo none > $L # unlink: sys_t_output_close() frees it
rmdir $P/dummy_stm.0:p_sys-t.a/heartbeat.0 $P/dummy_stm.0:p_sys-t.a
mkdir $P/dummy_stm.0:p_basic.b $P/dummy_stm.0:p_basic.b/heartbeat.0
echo dummy_stm.0 > $L # no output_open(), pdrv_private is kept
rmdir $P/dummy_stm.0:p_basic.b/heartbeat.0 $P/dummy_stm.0:p_basic.b
mkdir $P/dummy_stm.0:p_sys-t.c
The next heartbeat then runs sys_t_write() on the freed sys_t_output,
and unlinking the source frees it a second time.
Clear the pointer when the output is freed, so that a stale private
pointer can neither be used nor freed again. If no protocol driver is
bound at that point the private data is leaked instead, as before.
Fixes: c7fd62bc69d0 ("stm class: Introduce framing protocol drivers")
Cc: stable@vger.kernel.org
Signed-off-by: Yu Zhang <yuz08559@gmail.com>
---
drivers/hwtracing/stm/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 64a9eb1..5b7dfa3 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -345,6 +345,7 @@ static void stm_output_free(struct stm_device *stm, struct stm_output *output)
stm_output_disclaim(stm, output);
if (stm->pdrv && stm->pdrv->output_close)
stm->pdrv->output_close(output);
+ output->pdrv_private = NULL;
spin_unlock(&output->lock);
spin_unlock(&stm->mc_lock);
}
--
2.43.0
reply other threads:[~2026-11-01 6:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261101062343.16629-1-yuz08559@gmail.com \
--to=yuz08559@gmail.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®