* [PATCH] xen: Fix the issue of resource not being properly released in xenbus_dev_probe()
@ 2024-11-05 13:09 Qiu-ji Chen
2024-11-05 15:56 ` Jürgen Groß
0 siblings, 1 reply; 2+ messages in thread
From: Qiu-ji Chen @ 2024-11-05 13:09 UTC (permalink / raw)
To: jgross, sstabellini, oleksandr_tyshchenko, gregkh, sumit.garg, xin.wang2
Cc: xen-devel, linux-kernel, baijiaju1990, Qiu-ji Chen, stable
This patch fixes an issue in the function xenbus_dev_probe(). In the
xenbus_dev_probe() function, within the if (err) branch at line 313, the
program incorrectly returns err directly without releasing the resources
allocated by err = drv->probe(dev, id). As the return value is non-zero,
the upper layers assume the processing logic has failed. However, the probe
operation was performed earlier without a corresponding remove operation.
Since the probe actually allocates resources, failing to perform the remove
operation could lead to problems.
To fix this issue, we followed the resource release logic of the
xenbus_dev_remove() function by adding a new block fail_remove before the
fail_put block. After entering the branch if (err) at line 313, the
function will use a goto statement to jump to the fail_remove block,
ensuring that the previously acquired resources are correctly released,
thus preventing the reference count leak.
This bug was identified by an experimental static analysis tool developed
by our team. The tool specializes in analyzing reference count operations
and detecting potential issues where resources are not properly managed.
In this case, the tool flagged the missing release operation as a
potential problem, which led to the development of this patch.
Fixes: 4bac07c993d0 ("xen: add the Xenbus sysfs and virtual device hotplug driver")
Cc: stable@vger.kernel.org
Signed-off-by: Qiu-ji Chen <chenqiuji666@gmail.com>
---
drivers/xen/xenbus/xenbus_probe.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 9f097f1f4a4c..6d32ffb01136 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -313,7 +313,7 @@ int xenbus_dev_probe(struct device *_dev)
if (err) {
dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
dev->nodename);
- return err;
+ goto fail_remove;
}
dev->spurious_threshold = 1;
@@ -322,6 +322,12 @@ int xenbus_dev_probe(struct device *_dev)
dev->nodename);
return 0;
+fail_remove:
+ if (drv->remove) {
+ down(&dev->reclaim_sem);
+ drv->remove(dev);
+ up(&dev->reclaim_sem);
+ }
fail_put:
module_put(drv->driver.owner);
fail:
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] xen: Fix the issue of resource not being properly released in xenbus_dev_probe()
2024-11-05 13:09 [PATCH] xen: Fix the issue of resource not being properly released in xenbus_dev_probe() Qiu-ji Chen
@ 2024-11-05 15:56 ` Jürgen Groß
0 siblings, 0 replies; 2+ messages in thread
From: Jürgen Groß @ 2024-11-05 15:56 UTC (permalink / raw)
To: Qiu-ji Chen, sstabellini, oleksandr_tyshchenko, gregkh,
sumit.garg, xin.wang2
Cc: xen-devel, linux-kernel, baijiaju1990, stable
[-- Attachment #1.1.1: Type: text/plain, Size: 1629 bytes --]
On 05.11.24 14:09, Qiu-ji Chen wrote:
> This patch fixes an issue in the function xenbus_dev_probe(). In the
> xenbus_dev_probe() function, within the if (err) branch at line 313, the
> program incorrectly returns err directly without releasing the resources
> allocated by err = drv->probe(dev, id). As the return value is non-zero,
> the upper layers assume the processing logic has failed. However, the probe
> operation was performed earlier without a corresponding remove operation.
> Since the probe actually allocates resources, failing to perform the remove
> operation could lead to problems.
>
> To fix this issue, we followed the resource release logic of the
> xenbus_dev_remove() function by adding a new block fail_remove before the
> fail_put block. After entering the branch if (err) at line 313, the
> function will use a goto statement to jump to the fail_remove block,
> ensuring that the previously acquired resources are correctly released,
> thus preventing the reference count leak.
>
> This bug was identified by an experimental static analysis tool developed
> by our team. The tool specializes in analyzing reference count operations
> and detecting potential issues where resources are not properly managed.
> In this case, the tool flagged the missing release operation as a
> potential problem, which led to the development of this patch.
>
> Fixes: 4bac07c993d0 ("xen: add the Xenbus sysfs and virtual device hotplug driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qiu-ji Chen <chenqiuji666@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-05 15:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-05 13:09 [PATCH] xen: Fix the issue of resource not being properly released in xenbus_dev_probe() Qiu-ji Chen
2024-11-05 15:56 ` Jürgen Groß
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®