public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] segment: Fix dangling pointer
@ 2024-03-28 20:29 Maks Mishin
  2024-03-28 21:04 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Maks Mishin @ 2024-03-28 20:29 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Maks Mishin

Pointer 'lookup_module' which is a field of the structure 'Dwfl'
freed at segment.c:88 is not overwritten, but it is usually overwritten
after free.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 libdwfl/segment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libdwfl/segment.c b/libdwfl/segment.c
index f6a3e84e..af76f2f8 100644
--- a/libdwfl/segment.c
+++ b/libdwfl/segment.c
@@ -86,6 +86,7 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
 	  if (unlikely (dwfl->lookup_module == NULL))
 	    {
 	      free (old);
+	      old = NULL;
 	      return true;
 	    }
 	}
-- 
2.30.2


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

* Re: [PATCH] segment: Fix dangling pointer
  2024-03-28 20:29 [PATCH] segment: Fix dangling pointer Maks Mishin
@ 2024-03-28 21:04 ` Mark Wielaard
       [not found]   ` <CAEh9MGSacFTTxckO5sv8nzfAzxGRCrdSEQUzVxO_wX2-5ReYsA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2024-03-28 21:04 UTC (permalink / raw)
  To: Maks Mishin; +Cc: elfutils-devel

Hi Maks,

On Thu, Mar 28, 2024 at 11:29:22PM +0300, Maks Mishin wrote:
> Pointer 'lookup_module' which is a field of the structure 'Dwfl'
> freed at segment.c:88 is not overwritten, but it is usually overwritten
> after free.

But the very next statement is a return true; so old isn't in scope
anymore. Why would we assign NULL to it?

> Found by RASU JSC.

What or who is that?

> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  libdwfl/segment.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libdwfl/segment.c b/libdwfl/segment.c
> index f6a3e84e..af76f2f8 100644
> --- a/libdwfl/segment.c
> +++ b/libdwfl/segment.c
> @@ -86,6 +86,7 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
>  	  if (unlikely (dwfl->lookup_module == NULL))
>  	    {
>  	      free (old);
> +	      old = NULL;
>  	      return true;
>  	    }
>  	}
> -- 
> 2.30.2
> 

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

* Re: [PATCH] segment: Fix dangling pointer
       [not found]   ` <CAEh9MGSacFTTxckO5sv8nzfAzxGRCrdSEQUzVxO_wX2-5ReYsA@mail.gmail.com>
@ 2024-04-03 20:28     ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2024-04-03 20:28 UTC (permalink / raw)
  To: Максим
	Мишин
  Cc: elfutils-devel

Hi Maks,

Adding the elfutils-devel list back to the CC because that is where
patches are discussed.

On Tue, Apr 02, 2024 at 10:45:59PM +0300, Максим Мишин wrote:
> RASU JSC is a part of Rosatom, a company where one of the areas of work is
> software development based on the Linux kernel.
> That's why I'm doing a static analysis of the Linux-core components.
> 
> We use the Svace static analyzer:
> https://www.ispras.ru/en/technologies/svace/
> 
> This patch is the processing of the analyzer's triggers with the
> DANGLING_POINTER type for pointer `old`.

OK, but that doesn't really make sense. old isn't a dangling
pointer. It is a local pointer that is freed before returning from the
function. What do you try to accomplish by assigning it the value
NULL?

What real issue are you trying to fix?

Thanks,

Mark

> пт, 29 мар. 2024 г. в 00:04, Mark Wielaard <mark@klomp.org>:
> 
> > Hi Maks,
> >
> > On Thu, Mar 28, 2024 at 11:29:22PM +0300, Maks Mishin wrote:
> > > Pointer 'lookup_module' which is a field of the structure 'Dwfl'
> > > freed at segment.c:88 is not overwritten, but it is usually overwritten
> > > after free.
> >
> > But the very next statement is a return true; so old isn't in scope
> > anymore. Why would we assign NULL to it?
> >
> > > Found by RASU JSC.
> >
> > What or who is that?
> >
> > > Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> > > ---
> > >  libdwfl/segment.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/libdwfl/segment.c b/libdwfl/segment.c
> > > index f6a3e84e..af76f2f8 100644
> > > --- a/libdwfl/segment.c
> > > +++ b/libdwfl/segment.c
> > > @@ -86,6 +86,7 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start,
> > GElf_Addr end, int segndx)
> > >         if (unlikely (dwfl->lookup_module == NULL))
> > >           {
> > >             free (old);
> > > +           old = NULL;
> > >             return true;
> > >           }
> > >       }
> > > --
> > > 2.30.2
> > >
> >
> 
> 
> -- 
> С уважением,
> Максим Мишин
> +7 (915) 958-41-07
> maks.mishinFZ@gmail.com

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

end of thread, other threads:[~2024-04-03 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 20:29 [PATCH] segment: Fix dangling pointer Maks Mishin
2024-03-28 21:04 ` Mark Wielaard
     [not found]   ` <CAEh9MGSacFTTxckO5sv8nzfAzxGRCrdSEQUzVxO_wX2-5ReYsA@mail.gmail.com>
2024-04-03 20:28     ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).