qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [PATCH v6 02/10] monitor: fix access freed memory


From: Michael S. Tsirkin
Subject: Re: [Qemu-trivial] [PATCH v6 02/10] monitor: fix access freed memory
Date: Sun, 17 Aug 2014 12:55:22 +0200

On Fri, Aug 15, 2014 at 02:25:51PM -0400, Luiz Capitulino wrote:
> On Thu, 14 Aug 2014 12:30:10 +0200
> "Michael S. Tsirkin" <address@hidden> wrote:
> 
> > On Thu, Aug 14, 2014 at 03:29:13PM +0800, zhanghailiang wrote:
> > > The function monitor_fdset_dup_fd_find_remove() references member of 
> > > 'mon_fdset'
> > > which may be freed in function monitor_fdset_cleanup()
> > > 
> > > Reviewed-by: Gonglei <address@hidden>
> > > Signed-off-by: zhanghailiang <address@hidden>
> > 
> > Id doesn't make sense after fdset is gone.
> > A cleaner way would be return -1 within that remove
> > clause.
> > 
> > --->
> > 
> > monitor: fix use after free
> > 
> > The function monitor_fdset_dup_fd_find_remove() references member of
> > 'mon_fdset' which - when remove flag is set - may be freed in function
> > monitor_fdset_cleanup().
> > remove is set by monitor_fdset_dup_fd_remove which in practice
> > does not need the returned value, so make it void,
> > and return -1 from monitor_fdset_dup_fd_find_remove.
> > 
> > Signed-off-by: Michael S. Tsirkin <address@hidden>
> 
> Looks correct to me, can you post as a toplevel patch please?

Done.

> > 
> > ---
> > 
> > diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> > index 3d6929d..78a5fc8 100644
> > --- a/include/monitor/monitor.h
> > +++ b/include/monitor/monitor.h
> > @@ -64,7 +64,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool 
> > has_fdset_id, int64_t fdset_id,
> >                                  Error **errp);
> >  int monitor_fdset_get_fd(int64_t fdset_id, int flags);
> >  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
> > -int monitor_fdset_dup_fd_remove(int dup_fd);
> > +void monitor_fdset_dup_fd_remove(int dup_fd);
> >  int monitor_fdset_dup_fd_find(int dup_fd);
> >  
> >  #endif /* !MONITOR_H */
> > diff --git a/monitor.c b/monitor.c
> > index 5bc70a6..ef28328 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -2541,8 +2541,10 @@ static int monitor_fdset_dup_fd_find_remove(int 
> > dup_fd, bool remove)
> >                      if (QLIST_EMPTY(&mon_fdset->dup_fds)) {
> >                          monitor_fdset_cleanup(mon_fdset);
> >                      }
> > +                    return -1;
> > +                } else {
> > +                    return mon_fdset->id;
> >                  }
> > -                return mon_fdset->id;
> >              }
> >          }
> >      }
> > @@ -2554,9 +2556,9 @@ int monitor_fdset_dup_fd_find(int dup_fd)
> >      return monitor_fdset_dup_fd_find_remove(dup_fd, false);
> >  }
> >  
> > -int monitor_fdset_dup_fd_remove(int dup_fd)
> > +void monitor_fdset_dup_fd_remove(int dup_fd)
> >  {
> > -    return monitor_fdset_dup_fd_find_remove(dup_fd, true);
> > +    monitor_fdset_dup_fd_find_remove(dup_fd, true);
> >  }
> >  
> >  int monitor_handle_fd_param(Monitor *mon, const char *fdname)
> > diff --git a/stubs/fdset-remove-fd.c b/stubs/fdset-remove-fd.c
> > index b3886d9..7f6d61e 100644
> > --- a/stubs/fdset-remove-fd.c
> > +++ b/stubs/fdset-remove-fd.c
> > @@ -1,7 +1,6 @@
> >  #include "qemu-common.h"
> >  #include "monitor/monitor.h"
> >  
> > -int monitor_fdset_dup_fd_remove(int dupfd)
> > +void monitor_fdset_dup_fd_remove(int dupfd)
> >  {
> > -    return -1;
> >  }
> > 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]