* [PATCH] block: partitions: fix of_node refcount leak in of_partition()
@ 2026-05-26 10:21 Wentao Liang
2026-05-26 14:59 ` Haris Iqbal
2026-05-26 16:36 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-05-26 10:21 UTC (permalink / raw)
To: Jens Axboe, stable
Cc: Josh Law, Kees Cook, linux-block, linux-kernel, Wentao Liang
of_partition() calls of_node_get() on the parent device node at the
beginning of the function, storing the reference in 'partitions_np'.
This reference is leaked in two paths:
1. The compatibility check at the top of the function returns 0
without releasing partitions_np when the node exists but is not
"fixed-partitions" compatible.
2. The function returns 1 at the end after successfully processing
all partitions without releasing partitions_np.
Fix both leaks by adding of_node_put(partitions_np) on each path.
Fixes: 2e3a191e89f9 ("block: add support for partition table defined in OF")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
block/partitions/of.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/partitions/of.c b/block/partitions/of.c
index c22b60661098..53664ea06b65 100644
--- a/block/partitions/of.c
+++ b/block/partitions/of.c
@@ -74,8 +74,10 @@ int of_partition(struct parsed_partitions *state)
struct device_node *partitions_np = of_node_get(ddev->of_node);
if (!partitions_np ||
- !of_device_is_compatible(partitions_np, "fixed-partitions"))
+ !of_device_is_compatible(partitions_np, "fixed-partitions")) {
+ of_node_put(partitions_np);
return 0;
+ }
slot = 1;
/* Validate parition offset and size */
@@ -104,5 +106,6 @@ int of_partition(struct parsed_partitions *state)
seq_buf_puts(&state->pp_buf, "\n");
+ of_node_put(partitions_np);
return 1;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: partitions: fix of_node refcount leak in of_partition()
2026-05-26 10:21 [PATCH] block: partitions: fix of_node refcount leak in of_partition() Wentao Liang
@ 2026-05-26 14:59 ` Haris Iqbal
2026-05-26 16:36 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Haris Iqbal @ 2026-05-26 14:59 UTC (permalink / raw)
To: Wentao Liang, Jens Axboe, stable
Cc: Josh Law, Kees Cook, linux-block, linux-kernel
On 5/26/26 12:21, Wentao Liang wrote:
> of_partition() calls of_node_get() on the parent device node at the
> beginning of the function, storing the reference in 'partitions_np'.
> This reference is leaked in two paths:
>
> 1. The compatibility check at the top of the function returns 0
> without releasing partitions_np when the node exists but is not
> "fixed-partitions" compatible.
>
> 2. The function returns 1 at the end after successfully processing
> all partitions without releasing partitions_np.
>
> Fix both leaks by adding of_node_put(partitions_np) on each path.
>
> Fixes: 2e3a191e89f9 ("block: add support for partition table defined in OF")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Looks good:
Reviewed-by: Md Haris Iqbal <haris.iqbal@linux.dev>
> ---
> block/partitions/of.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/block/partitions/of.c b/block/partitions/of.c
> index c22b60661098..53664ea06b65 100644
> --- a/block/partitions/of.c
> +++ b/block/partitions/of.c
> @@ -74,8 +74,10 @@ int of_partition(struct parsed_partitions *state)
> struct device_node *partitions_np = of_node_get(ddev->of_node);
>
> if (!partitions_np ||
> - !of_device_is_compatible(partitions_np, "fixed-partitions"))
> + !of_device_is_compatible(partitions_np, "fixed-partitions")) {
> + of_node_put(partitions_np);
> return 0;
> + }
>
> slot = 1;
> /* Validate parition offset and size */
> @@ -104,5 +106,6 @@ int of_partition(struct parsed_partitions *state)
>
> seq_buf_puts(&state->pp_buf, "\n");
>
> + of_node_put(partitions_np);
> return 1;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: partitions: fix of_node refcount leak in of_partition()
2026-05-26 10:21 [PATCH] block: partitions: fix of_node refcount leak in of_partition() Wentao Liang
2026-05-26 14:59 ` Haris Iqbal
@ 2026-05-26 16:36 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-05-26 16:36 UTC (permalink / raw)
To: stable, Wentao Liang; +Cc: Josh Law, Kees Cook, linux-block, linux-kernel
On Tue, 26 May 2026 10:21:24 +0000, Wentao Liang wrote:
> of_partition() calls of_node_get() on the parent device node at the
> beginning of the function, storing the reference in 'partitions_np'.
> This reference is leaked in two paths:
>
> 1. The compatibility check at the top of the function returns 0
> without releasing partitions_np when the node exists but is not
> "fixed-partitions" compatible.
>
> [...]
Applied, thanks!
[1/1] block: partitions: fix of_node refcount leak in of_partition()
commit: 148cd4873115feb266c002d4d4618ea7f14342d9
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-26 16:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 10:21 [PATCH] block: partitions: fix of_node refcount leak in of_partition() Wentao Liang
2026-05-26 14:59 ` Haris Iqbal
2026-05-26 16:36 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox