]>
Commit | Line | Data |
---|---|---|
20d0511e GKH |
1 | From 467233a4ac29b215d492843d067a9f091e6bf0c5 Mon Sep 17 00:00:00 2001 |
2 | From: Shengjiu Wang <shengjiu.wang@nxp.com> | |
3 | Date: Wed, 21 Sep 2022 09:58:43 +0800 | |
4 | Subject: rpmsg: char: Avoid double destroy of default endpoint | |
5 | ||
6 | From: Shengjiu Wang <shengjiu.wang@nxp.com> | |
7 | ||
8 | commit 467233a4ac29b215d492843d067a9f091e6bf0c5 upstream. | |
9 | ||
10 | The rpmsg_dev_remove() in rpmsg_core is the place for releasing | |
11 | this default endpoint. | |
12 | ||
13 | So need to avoid destroying the default endpoint in | |
14 | rpmsg_chrdev_eptdev_destroy(), this should be the same as | |
15 | rpmsg_eptdev_release(). Otherwise there will be double destroy | |
16 | issue that ept->refcount report warning: | |
17 | ||
18 | refcount_t: underflow; use-after-free. | |
19 | ||
20 | Call trace: | |
21 | refcount_warn_saturate+0xf8/0x150 | |
22 | virtio_rpmsg_destroy_ept+0xd4/0xec | |
23 | rpmsg_dev_remove+0x60/0x70 | |
24 | ||
25 | The issue can be reproduced by stopping remoteproc before | |
26 | closing the /dev/rpmsgX. | |
27 | ||
28 | Fixes: bea9b79c2d10 ("rpmsg: char: Add possibility to use default endpoint of the rpmsg device") | |
29 | Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> | |
30 | Reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> | |
31 | Reviewed-by: Peng Fan <peng.fan@nxp.com> | |
32 | Cc: stable <stable@vger.kernel.org> | |
33 | Link: https://lore.kernel.org/r/1663725523-6514-1-git-send-email-shengjiu.wang@nxp.com | |
34 | Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> | |
35 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
36 | --- | |
37 | drivers/rpmsg/rpmsg_char.c | 4 +++- | |
38 | 1 file changed, 3 insertions(+), 1 deletion(-) | |
39 | ||
40 | --- a/drivers/rpmsg/rpmsg_char.c | |
41 | +++ b/drivers/rpmsg/rpmsg_char.c | |
42 | @@ -76,7 +76,9 @@ int rpmsg_chrdev_eptdev_destroy(struct d | |
43 | ||
44 | mutex_lock(&eptdev->ept_lock); | |
45 | if (eptdev->ept) { | |
46 | - rpmsg_destroy_ept(eptdev->ept); | |
47 | + /* The default endpoint is released by the rpmsg core */ | |
48 | + if (!eptdev->default_ept) | |
49 | + rpmsg_destroy_ept(eptdev->ept); | |
50 | eptdev->ept = NULL; | |
51 | } | |
52 | mutex_unlock(&eptdev->ept_lock); |