From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 7CD4C11C5 for ; Mon, 23 Mar 2015 16:44:05 +0100 (CET) Received: by wgra20 with SMTP id a20so149253793wgr.3 for ; Mon, 23 Mar 2015 08:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Jw9P8dOYne8Uzb47OB5ZMBfWD03zV/wSjcKJgUZIfLo=; b=kI25tq7ohh9l77njK0q87kf7iCVnPKzAG2oWe/Yv1HS64R1y36OIg99V2ZICaFtqDe duxHoWEODAbrvCz+dS4m3/jZtbDGWlamH+8W3jlKZXow+KYV/QcMTFU4Yw8kjSkKobq7 /DK4iV3oI9byHMU2ma4Q/GCDi9o/W+QbcOSx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Jw9P8dOYne8Uzb47OB5ZMBfWD03zV/wSjcKJgUZIfLo=; b=bL3J1bZBsRygUTqhzbtydnPLBPkDxP4xuaLGjf6jymTrenlW1dHkSwfvtq+8lOIjKg 3duVR1MVjd31W6H2UKx/oS0oOxZTikbzkjnPWsvNrs9BSbx2Ei85f7VsBiV4JOjo7VU3 YtKobmnxgXk8ylfsaWA/iRiC6pyElPglqQIexyUolXOcKTpgRfK1IF2vU2dWN/e+bsQI QH9NTvAI3rVy6PpeGcNLNpl2UjdCHT80EO9/5TofWpbhFnN7D0+dC8tjOJJ78TjRtR/u prOG9gb6mp1u+1/QYFGwHE7wGdmYpVELwP/CBqhQKaH+26r2PlDbSYstvttcp/LTxWcl raPA== X-Gm-Message-State: ALoCoQniUNZH7t0E0ccww5y4ZUFy9sLqHP825TfXkFKlVbWWxI5t1kZG5rZUM+6L85c9FKluy/2m MIME-Version: 1.0 X-Received: by 10.194.59.112 with SMTP id y16mr191161734wjq.36.1427125445251; Mon, 23 Mar 2015 08:44:05 -0700 (PDT) Received: by 10.194.76.7 with HTTP; Mon, 23 Mar 2015 08:44:05 -0700 (PDT) In-Reply-To: References: <1427115225-14489-1-git-send-email-pboldin@mirantis.com> Date: Mon, 23 Mar 2015 17:44:05 +0200 Message-ID: From: Pavel Boldin To: "Xie, Huawei" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH] vhost: Fix `struct file' leakage in `eventfd_link' X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2015 15:44:05 -0000 On Mon, Mar 23, 2015 at 5:36 PM, Xie, Huawei wrote: > On 3/23/2015 11:27 PM, Pavel Boldin wrote: > > > On Mon, Mar 23, 2015 at 5:16 PM, Xie, Huawei huawei.xie@intel.com>> wrote: > On 3/23/2015 10:52 PM, Pavel Boldin wrote: > > > On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei huawei.xie@intel.com> huawei.xie@intel.com>>> wrote: > On 3/23/2015 10:37 PM, Pavel Boldin wrote: > > > On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei huawei.xie@intel.com> huawei.xie@intel.com>> huawei.xie@intel.com> huawei.xie@intel.com>>>> 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@mirantis.com> pboldin@mirantis.com>> pboldin@mirantis.com> pboldin@mirantis.com>>>> > > --- > > 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. > The code of this module received little to none review and requires some > love at the moment. > > I wanted to refactor the module completely but Thomas said it is not going > to go into the 2.0. So I decided to make a simple one-line fix. > Another isse is do we really need a src fd here? Could we just allocate a > unsed fd in the kernel and installed it with the target eventfd. > This is for DPDK team to decide and should be discussed separately. Pavel > > If you are interested this [0] is the latest version of the refactoring > patch. > > I can provide you with an application that checks that there is indeed no > leakage and ensures that the `eventfd' moving works. It is being used in > our builds as a test [1]. The code is "heredoc"ed in [2] > > [0] http://dpdk.org/dev/patchwork/patch/4113/ > [1] https://review.fuel-infra.org/#/c/4639/ > [2] https://review.fuel-infra.org/#/c/4639/3/tests/runtests.sh > > Pavel > > 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; > > > > > > > >