All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] livepatch: Reorder to use before freeing a pointer
@ 2022-03-19 16:51 trix
  2022-03-19 20:25 ` David Vernet
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2022-03-19 16:51 UTC (permalink / raw)
  To: jpoimboe, jikos, mbenes, pmladek, joe.lawrence, nathan, ndesaulniers
  Cc: live-patching, linux-kernel, llvm, Tom Rix

From: Tom Rix <trix@redhat.com>

Clang static analysis reports this issue
livepatch-shadow-fix1.c:113:2: warning: Use of
  memory after it is freed
  pr_info("%s: dummy @ %p, prevented leak @ %p\n",
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The pointer is freed in the previous statement.
Reorder the pr_info to report before the free.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 samples/livepatch/livepatch-shadow-fix1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c
index 918ce17b43fda..6701641bf12d4 100644
--- a/samples/livepatch/livepatch-shadow-fix1.c
+++ b/samples/livepatch/livepatch-shadow-fix1.c
@@ -109,9 +109,9 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
 	void *d = obj;
 	int **shadow_leak = shadow_data;
 
-	kfree(*shadow_leak);
 	pr_info("%s: dummy @ %p, prevented leak @ %p\n",
 			 __func__, d, *shadow_leak);
+	kfree(*shadow_leak);
 }
 
 static void livepatch_fix1_dummy_free(struct dummy *d)
-- 
2.26.3


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

* Re: [PATCH] livepatch: Reorder to use before freeing a pointer
  2022-03-19 16:51 [PATCH] livepatch: Reorder to use before freeing a pointer trix
@ 2022-03-19 20:25 ` David Vernet
  0 siblings, 0 replies; 2+ messages in thread
From: David Vernet @ 2022-03-19 20:25 UTC (permalink / raw)
  To: trix
  Cc: jpoimboe, jikos, mbenes, pmladek, joe.lawrence, nathan,
	ndesaulniers, live-patching, linux-kernel, llvm

On Sat, Mar 19, 2022 at 09:51:59AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> Clang static analysis reports this issue
> livepatch-shadow-fix1.c:113:2: warning: Use of
>   memory after it is freed
>   pr_info("%s: dummy @ %p, prevented leak @ %p\n",
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The pointer is freed in the previous statement.
> Reorder the pr_info to report before the free.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  samples/livepatch/livepatch-shadow-fix1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c
> index 918ce17b43fda..6701641bf12d4 100644
> --- a/samples/livepatch/livepatch-shadow-fix1.c
> +++ b/samples/livepatch/livepatch-shadow-fix1.c
> @@ -109,9 +109,9 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
>  	void *d = obj;
>  	int **shadow_leak = shadow_data;
>  
> -	kfree(*shadow_leak);
>  	pr_info("%s: dummy @ %p, prevented leak @ %p\n",
>  			 __func__, d, *shadow_leak);
> +	kfree(*shadow_leak);
>  }
>  
>  static void livepatch_fix1_dummy_free(struct dummy *d)
> -- 
> 2.26.3
> 

The fix looks good, though it looks like there is also a similar
use-after-free in livepatch_fix2_dummy_leak_dtor() in
livepatch-shadow-fix2.c. Could you please also fix that as part of this
patch?

Thanks,
David

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

end of thread, other threads:[~2022-03-19 20:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19 16:51 [PATCH] livepatch: Reorder to use before freeing a pointer trix
2022-03-19 20:25 ` David Vernet

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.