From: Yu Zhang <yuz08559@gmail.com>
To: Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v2] rpmsg: char: take ept_lock in the SET_INCOMING_FLOWCONTROL ioctl
Date: Sat, 31 Oct 2026 19:06:50 +1000 [thread overview]
Message-ID: <20261031090650.23701-1-yuz08559@gmail.com> (raw)
In-Reply-To: <20261026100306.68019-1-yuz08559@gmail.com>
rpmsg_eptdev_ioctl() handles RPMSG_SET_INCOMING_FLOWCONTROL by calling
rpmsg_set_flow_control(eptdev->ept, ...) without holding eptdev->ept_lock
and without checking eptdev->ept for NULL. rpmsg_set_flow_control()
dereferences ept->ops, so this is the only eptdev->ept user that does not
honour the ept_lock discipline.
eptdev->ept is torn down under ept_lock: rpmsg_chrdev_eptdev_destroy()
(reached via RPMSG_DESTROY_EPT_IOCTL on a second fd, or when the rpmsg
device is removed) and rpmsg_eptdev_release() both do
mutex_lock(&eptdev->ept_lock);
rpmsg_destroy_ept(eptdev->ept);
eptdev->ept = NULL;
mutex_unlock(&eptdev->ept_lock);
and rpmsg_destroy_ept() drops the endpoint's last reference and frees it.
A SET_INCOMING_FLOWCONTROL ioctl running concurrently can therefore read
eptdev->ept just as it is freed and dereference ept->ops -> use-after-free
(or a NULL dereference once ept has been cleared).
Fixes: 5550201c0fe2 ("rpmsg: char: Add RPMSG GET/SET FLOWCONTROL IOCTL support")
Cc: stable@vger.kernel.org
Signed-off-by: Yu Zhang <yuz08559@gmail.com>
---
v2:
- Drop the paragraph about the other ept_lock users from the commit
message (Mathieu).
- Bail out early when the endpoint is already gone instead of an
if/else around the call (Mathieu).
v1: https://lore.kernel.org/all/20261026100306.68019-1-yuz08559@gmail.com/
---
drivers/rpmsg/rpmsg_char.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 550fda2..d8868fa 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -343,7 +343,20 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd,
break;
}
set = !!arg;
- ret = rpmsg_set_flow_control(eptdev->ept, set, eptdev->chinfo.dst);
+
+ ret = mutex_lock_interruptible(&eptdev->ept_lock);
+ if (ret)
+ break;
+
+ if (!eptdev->ept) {
+ mutex_unlock(&eptdev->ept_lock);
+ ret = -EPIPE;
+ break;
+ }
+
+ ret = rpmsg_set_flow_control(eptdev->ept, set,
+ eptdev->chinfo.dst);
+ mutex_unlock(&eptdev->ept_lock);
break;
case RPMSG_DESTROY_EPT_IOCTL:
/* Don't allow to destroy a default endpoint. */
--
2.43.0
next prev parent reply other threads:[~2026-10-31 9:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 10:03 [PATCH] rpmsg: char: take ept_lock in the SET_INCOMING_FLOWCONTROL ioctl Yu Zhang
2026-10-30 17:48 ` Mathieu Poirier
2026-10-31 9:06 ` Yu Zhang [this message]
2026-11-05 16:56 ` [PATCH v2] " Mathieu Poirier
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=20261031090650.23701-1-yuz08559@gmail.com \
--to=yuz08559@gmail.com \
--cc=andersson@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.