All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
To: "Xie, Huawei" <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org
Subject: Re: [PATCH] vhost: Fix `struct file' leakage in `eventfd_link'
Date: Mon, 23 Mar 2015 16:22:49 +0100	[thread overview]
Message-ID: <4710593.KA6H5ovzJI@xps13> (raw)
In-Reply-To: <C37D651A908B024F974696C65296B57B0F3F240D-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>

Huawei,
This thread is unreadable because your mailer is not quoting.
Please check. Thanks

2015-03-23 15:16, Xie, Huawei:
> On 3/23/2015 10:52 PM, Pavel Boldin wrote:
> 
> 
> On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org<mailto:huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>> wrote:
> On 3/23/2015 10:37 PM, Pavel Boldin wrote:
> 
> 
> On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org<mailto:huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org><mailto:huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org<mailto:huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>>> wrote:
> On 3/23/2015 8:54 PM, Pavel Boldin wrote:
> > Due to increased `struct file's reference counter subsequent call
> > to `filp_close' does not free the `struct file'. Prepend `fput' call
> > to decrease the reference counter.
> >
> > Signed-off-by: Pavel Boldin <pboldin-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org<mailto:pboldin-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org><mailto:pboldin-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org<mailto:pboldin-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org>>>
> > ---
> >  lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.c b/lib/librte_vhost/eventfd_link/eventfd_link.c
> > index 7755dd6..62c45c8 100644
> > --- a/lib/librte_vhost/eventfd_link/eventfd_link.c
> > +++ b/lib/librte_vhost/eventfd_link/eventfd_link.c
> > @@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
> >                * Release the existing eventfd in the source process
> >                */
> >               spin_lock(&files->file_lock);
> > +             fput(file);
> Could we just call atomic_long_dec here?
> 
> We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion.
> it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
> The code with `atomic_long_inc_not_zero' call is a copy-paste of the `fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.
> 
> I don't understand why there is a (exact?) copy&paste of fget there. :).
> Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer.
> Second thing is: another thread of the same processor can call the `sys_close' on the `fd' and this will dereference counter so `fput' will correctly free the `struct file'. Using `atomic_long_dec' will leak a `struct file' and print a KERN_ERR message by `filp_close'.
> 
> So, the common thing is to use appropriate functions and don't reinvent the wheel.
> 
> Pavel
> 
> 
> 
> Pavel
> 
> >               filp_close(file, files);
> >               fdt = files_fdtable(files);
> >               fdt->fd[eventfd_copy.source_fd] = NULL;
> 

  parent reply	other threads:[~2015-03-23 15:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23 12:53 [PATCH] vhost: Fix `struct file' leakage in `eventfd_link' Pavel Boldin
2015-03-23 14:21 ` Xie, Huawei
     [not found]   ` <C37D651A908B024F974696C65296B57B0F3F1E14-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-23 14:36     ` Pavel Boldin
2015-03-23 14:41       ` Xie, Huawei
     [not found]         ` <C37D651A908B024F974696C65296B57B0F3F1F75-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-23 14:51           ` Pavel Boldin
2015-03-23 15:16             ` Xie, Huawei
     [not found]               ` <C37D651A908B024F974696C65296B57B0F3F240D-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-23 15:22                 ` Thomas Monjalon [this message]
2015-03-23 15:27                 ` Pavel Boldin
2015-03-23 15:36                   ` Xie, Huawei
     [not found]                     ` <C37D651A908B024F974696C65296B57B0F3F2694-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-23 15:44                       ` Pavel Boldin
2015-03-24  6:28 ` Xie, Huawei
     [not found]   ` <C37D651A908B024F974696C65296B57B0F3F46FB-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-24 11:10     ` Pavel Boldin
2015-03-24 16:20       ` Xie, Huawei
     [not found]         ` <C37D651A908B024F974696C65296B57B0F3F59D7-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-24 20:08           ` Pavel Boldin
2015-03-26  7:53             ` Xie, Huawei
2015-03-27 11:12     ` Thomas Monjalon
2015-03-26  7:56 ` Xie, Huawei
     [not found]   ` <C37D651A908B024F974696C65296B57B0F3FB942-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-26 15:17     ` Pavel Boldin
2015-03-27 11:10     ` Thomas Monjalon
2015-03-27 12:36       ` Pavel Boldin
     [not found]         ` <CACf4_B9ims0bL3fqk5Pm6sTHkm7pdHcTgFNXLvKYZf5Gip9LDg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-27 13:15           ` Thomas Monjalon
2015-03-26 15:20 ` Xie, Huawei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4710593.KA6H5ovzJI@xps13 \
    --to=thomas.monjalon-pdr9zngts4eavxtiumwx3w@public.gmane.org \
    --cc=dev-VfR2kkLFssw@public.gmane.org \
    --cc=huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.