From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id E983EB62 for ; Mon, 23 Mar 2015 16:27:51 +0100 (CET) Received: by wgra20 with SMTP id a20so148862369wgr.3 for ; Mon, 23 Mar 2015 08:27:51 -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=+fEjDWYuOwQeDDKh/42QffImptQugCFYsW5hqxxTDdY=; b=ccuaR0tlb5/x2QmnmtrdRNrf15wj2W3I0I3+BaeTOjzwNHKjqCtE9icpzCTrB0LBtL J6ZMh4G2nhXBXjGIJgCHC69Uw5HYmNTIY8sFCUXiJsJlkbiDMjSG1bzVfB1jNbvqv5le gEv1nOAGLiRst5z2Sl1nj1YzzTHXck3l789Hc= 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=+fEjDWYuOwQeDDKh/42QffImptQugCFYsW5hqxxTDdY=; b=mWBIY38oc8OyWUosF2pc5h4ySqlHBdm+gFI6gxocyU/pc7R/LcsxmLWn7xE8lUbCT0 wBKpzTN/QrMounATaPhUMWmrLAhu9Pv9zSXP1panjAPRMDnjy9D4fAESWH5jiZur5cZ2 kSN9AXR10HFWsXbwbr4JiGy9AA9jWakRxeh768BxcmGy8CHFHOce4HBZq5km5gCI13Oi s7Ats6sDA5B7g+Plb86/RH8uvF0Cf1YkrOtjtHcbKuEaCawMw4cujMlZ2PUhO7hMfSgK Hhw7BQ3qK95McaZyjB9OJG3pHvcvq1D32IRXDPzFzziBda+72paTEJU6pfSExHBcdStw JvgQ== X-Gm-Message-State: ALoCoQmvLoayfU+hlB0DBO5YM+3FH38Nmb4c9HF/NR/g9UC5+uUs1STJK7VF1g9MmcNRwWttcAUK MIME-Version: 1.0 X-Received: by 10.195.12.97 with SMTP id ep1mr189689929wjd.134.1427124471391; Mon, 23 Mar 2015 08:27:51 -0700 (PDT) Received: by 10.194.76.7 with HTTP; Mon, 23 Mar 2015 08:27:51 -0700 (PDT) In-Reply-To: References: <1427115225-14489-1-git-send-email-pboldin@mirantis.com> Date: Mon, 23 Mar 2015 17:27:51 +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:27:52 -0000 On Mon, Mar 23, 2015 at 5:16 PM, Xie, Huawei 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>> 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>>> 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>>> > > --- > > 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. 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; > > > > > >