All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ocfs2: Fix a use after free on error
@ 2021-02-02 11:32 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-02-02 11:32 UTC (permalink / raw)
  To: Mark Fasheh
  Cc: Joel Becker, Joseph Qi, Andrew Morton, Takashi Iwai, Jens Axboe,
	Alex Shi, Jiri Slaby, ocfs2-devel, linux-kernel, kernel-janitors

The error handling in this function frees "reg" but it is still on the
"o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
points out that we need to clear the bit in the "o2hb_region_bitmap" as
well

Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: The first version didn't clear the bit.

 fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 0179a73a3fa2..12a7590601dd 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 			o2hb_nego_timeout_handler,
 			reg, NULL, &reg->hr_handler_list);
 	if (ret)
-		goto free;
+		goto remove_item;
 
 	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
 			sizeof(struct o2hb_nego_msg),
@@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 
 unregister_handler:
 	o2net_unregister_handler_list(&reg->hr_handler_list);
+remove_item:
+	spin_lock(&o2hb_live_lock);
+	list_del(&reg->hr_all_item);
+	if (o2hb_global_heartbeat_active())
+		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
+	spin_unlock(&o2hb_live_lock);
 free:
 	kfree(reg);
 	return ERR_PTR(ret);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] ocfs2: Fix a use after free on error
@ 2021-02-02 11:32 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-02-02 11:32 UTC (permalink / raw)
  To: Mark Fasheh
  Cc: Joel Becker, Joseph Qi, Andrew Morton, Takashi Iwai, Jens Axboe,
	Alex Shi, Jiri Slaby, ocfs2-devel, linux-kernel, kernel-janitors

The error handling in this function frees "reg" but it is still on the
"o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
points out that we need to clear the bit in the "o2hb_region_bitmap" as
well

Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: The first version didn't clear the bit.

 fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 0179a73a3fa2..12a7590601dd 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 			o2hb_nego_timeout_handler,
 			reg, NULL, &reg->hr_handler_list);
 	if (ret)
-		goto free;
+		goto remove_item;
 
 	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
 			sizeof(struct o2hb_nego_msg),
@@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 
 unregister_handler:
 	o2net_unregister_handler_list(&reg->hr_handler_list);
+remove_item:
+	spin_lock(&o2hb_live_lock);
+	list_del(&reg->hr_all_item);
+	if (o2hb_global_heartbeat_active())
+		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
+	spin_unlock(&o2hb_live_lock);
 free:
 	kfree(reg);
 	return ERR_PTR(ret);
-- 
2.30.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Ocfs2-devel] [PATCH v2] ocfs2: Fix a use after free on error
@ 2021-02-02 11:32 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-02-02 11:32 UTC (permalink / raw)
  To: Mark Fasheh
  Cc: Jens Axboe, Takashi Iwai, kernel-janitors, linux-kernel,
	Alex Shi, Jiri Slaby, ocfs2-devel

The error handling in this function frees "reg" but it is still on the
"o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
points out that we need to clear the bit in the "o2hb_region_bitmap" as
well

Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: The first version didn't clear the bit.

 fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 0179a73a3fa2..12a7590601dd 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 			o2hb_nego_timeout_handler,
 			reg, NULL, &reg->hr_handler_list);
 	if (ret)
-		goto free;
+		goto remove_item;
 
 	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
 			sizeof(struct o2hb_nego_msg),
@@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 
 unregister_handler:
 	o2net_unregister_handler_list(&reg->hr_handler_list);
+remove_item:
+	spin_lock(&o2hb_live_lock);
+	list_del(&reg->hr_all_item);
+	if (o2hb_global_heartbeat_active())
+		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
+	spin_unlock(&o2hb_live_lock);
 free:
 	kfree(reg);
 	return ERR_PTR(ret);
-- 
2.30.0


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ocfs2: Fix a use after free on error
  2021-02-02 11:32 ` Dan Carpenter
  (?)
@ 2021-02-02 12:08   ` Joseph Qi
  -1 siblings, 0 replies; 6+ messages in thread
From: Joseph Qi @ 2021-02-02 12:08 UTC (permalink / raw)
  To: Dan Carpenter, Mark Fasheh
  Cc: Joel Becker, Andrew Morton, Takashi Iwai, Jens Axboe, Alex Shi,
	Jiri Slaby, ocfs2-devel, linux-kernel, kernel-janitors



On 2/2/21 7:32 PM, Dan Carpenter wrote:
> The error handling in this function frees "reg" but it is still on the
> "o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
> points out that we need to clear the bit in the "o2hb_region_bitmap" as
> well
> 
> Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
> v2: The first version didn't clear the bit.
> 
>  fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index 0179a73a3fa2..12a7590601dd 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  			o2hb_nego_timeout_handler,
>  			reg, NULL, &reg->hr_handler_list);
>  	if (ret)
> -		goto free;
> +		goto remove_item;
>  
>  	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
>  			sizeof(struct o2hb_nego_msg),
> @@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  
>  unregister_handler:
>  	o2net_unregister_handler_list(&reg->hr_handler_list);
> +remove_item:
> +	spin_lock(&o2hb_live_lock);
> +	list_del(&reg->hr_all_item);
> +	if (o2hb_global_heartbeat_active())
> +		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
> +	spin_unlock(&o2hb_live_lock);
>  free:
>  	kfree(reg);
>  	return ERR_PTR(ret);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ocfs2: Fix a use after free on error
@ 2021-02-02 12:08   ` Joseph Qi
  0 siblings, 0 replies; 6+ messages in thread
From: Joseph Qi @ 2021-02-02 12:08 UTC (permalink / raw)
  To: Dan Carpenter, Mark Fasheh
  Cc: Joel Becker, Andrew Morton, Takashi Iwai, Jens Axboe, Alex Shi,
	Jiri Slaby, ocfs2-devel, linux-kernel, kernel-janitors



On 2/2/21 7:32 PM, Dan Carpenter wrote:
> The error handling in this function frees "reg" but it is still on the
> "o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
> points out that we need to clear the bit in the "o2hb_region_bitmap" as
> well
> 
> Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
> v2: The first version didn't clear the bit.
> 
>  fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index 0179a73a3fa2..12a7590601dd 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  			o2hb_nego_timeout_handler,
>  			reg, NULL, &reg->hr_handler_list);
>  	if (ret)
> -		goto free;
> +		goto remove_item;
>  
>  	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
>  			sizeof(struct o2hb_nego_msg),
> @@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  
>  unregister_handler:
>  	o2net_unregister_handler_list(&reg->hr_handler_list);
> +remove_item:
> +	spin_lock(&o2hb_live_lock);
> +	list_del(&reg->hr_all_item);
> +	if (o2hb_global_heartbeat_active())
> +		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
> +	spin_unlock(&o2hb_live_lock);
>  free:
>  	kfree(reg);
>  	return ERR_PTR(ret);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Ocfs2-devel] [PATCH v2] ocfs2: Fix a use after free on error
@ 2021-02-02 12:08   ` Joseph Qi
  0 siblings, 0 replies; 6+ messages in thread
From: Joseph Qi @ 2021-02-02 12:08 UTC (permalink / raw)
  To: Dan Carpenter, Mark Fasheh
  Cc: Jens Axboe, Takashi Iwai, kernel-janitors, linux-kernel,
	Alex Shi, Jiri Slaby, ocfs2-devel



On 2/2/21 7:32 PM, Dan Carpenter wrote:
> The error handling in this function frees "reg" but it is still on the
> "o2hb_all_regions" list so it will lead to a use after freew.  Joseph Qi
> points out that we need to clear the bit in the "o2hb_region_bitmap" as
> well
> 
> Fixes: 1cf257f51191 ("ocfs2: fix memory leak")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
> v2: The first version didn't clear the bit.
> 
>  fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index 0179a73a3fa2..12a7590601dd 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -2042,7 +2042,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  			o2hb_nego_timeout_handler,
>  			reg, NULL, &reg->hr_handler_list);
>  	if (ret)
> -		goto free;
> +		goto remove_item;
>  
>  	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
>  			sizeof(struct o2hb_nego_msg),
> @@ -2057,6 +2057,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
>  
>  unregister_handler:
>  	o2net_unregister_handler_list(&reg->hr_handler_list);
> +remove_item:
> +	spin_lock(&o2hb_live_lock);
> +	list_del(&reg->hr_all_item);
> +	if (o2hb_global_heartbeat_active())
> +		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
> +	spin_unlock(&o2hb_live_lock);
>  free:
>  	kfree(reg);
>  	return ERR_PTR(ret);
> 

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-02-02 12:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 11:32 [PATCH v2] ocfs2: Fix a use after free on error Dan Carpenter
2021-02-02 11:32 ` [Ocfs2-devel] " Dan Carpenter
2021-02-02 11:32 ` Dan Carpenter
2021-02-02 12:08 ` Joseph Qi
2021-02-02 12:08   ` [Ocfs2-devel] " Joseph Qi
2021-02-02 12:08   ` Joseph Qi

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.