Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp6817ybl; Tue, 27 Aug 2019 14:48:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyx/z1AX/Q/HcN4vVTurVYo11d7qPmIz2jqrYln9+wHH3PhOn3Ivw/YVZ3CeFt9lAJ40O1g X-Received: by 2002:a05:6a00:cd:: with SMTP id e13mr785697pfj.202.1566942524486; Tue, 27 Aug 2019 14:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566942524; cv=none; d=google.com; s=arc-20160816; b=hrFJshfMwLtfisoisC4JzIB7GfcytcFjVUjPSFyt41IOmmTX8hqYkJ/hRIMZrMWTJF mox5uNFBxXcyfjP9f5HuXRkXoCjFUG17vSrDiJf3QgqSMSCEGL9bNLtnHkstQlsrFf15 KjgKqMaPh1MrCnllyEEuRHxkeSivlkNHfT4kDpGyYejMmatohoRjMAm6+xYGfex/tDPx S0TJtnAee+M4JTObo/FXm3wVt53yCNnEbjCxnljALs3odP6kQrd7rz5j89a5726l1kMo 3VjFXSicGKZ76dOewlZtt6UYmX92ciA7WLe9GGlDIDRohkusK2uxk8m2LGNMnQfby2Gl 4Zfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:dkim-signature; bh=UKwNCZ3kYbqKK0CEnypD41umaTIfpON2HwG6q7KFDlI=; b=02yIMhLRKSGbMvtrOkuwRnlIw6UBFlKvRTyU+xFYtVCRWpfNAqJcRkv4Rs79GX4vxt +uATSml28TuKwL+5ZVdKBumTd7lAKl5iWMIozB//Edy6zE1xwKO8ul2E1Ni2Kl7eWjf1 zr0YB5bJqjTcSkh1y7lSvOeq3oLMpTbIctTg4YruR+XnrsyzB9HzhURYZ5vM1aC4TkTj /Rwq2S3rOqQOWOaAtlQmccOz32pQ69j+8EwRXce393uaHUwl5E8jVvnRQmWT94xfFEPh UIPKivp2Nx8TPF5Xe5Z+2+ROkeQBVE1wQzFqYsRhYhRm1X/BFK7iwtjJWXA3zzG09vxo lvOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oQAowJpw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si220952pjn.77.2019.08.27.14.48.28; Tue, 27 Aug 2019 14:48:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oQAowJpw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbfH0Vpu (ORCPT + 99 others); Tue, 27 Aug 2019 17:45:50 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39687 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726606AbfH0Vpu (ORCPT ); Tue, 27 Aug 2019 17:45:50 -0400 Received: by mail-wr1-f66.google.com with SMTP id t16so310765wra.6 for ; Tue, 27 Aug 2019 14:45:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UKwNCZ3kYbqKK0CEnypD41umaTIfpON2HwG6q7KFDlI=; b=oQAowJpwokGyA7CyiOV+GSrCQJvxChQfZevZu1BLUnGoxo609uYzfiHOohYW+2Go3s xir3yP2cD30zuXAkniV6fA/YXpyekCxqLfDVhB53xEMSQC4dRvv5psVbnEgIK3BRIk4a 6BBmkDS/PIVst70jZCVj/KQ+7XtmdW9do8OPuT2LiJGR6Lg9gu6Z7NeAkQok5Kzv1+A5 65GTrcwSe1W8UW3+dHIVW6RXQX4OP9/KHeXPCeaEaYK+10iGHDA8SCYxFLrbeIqNFyCz NwN/wQn2S3FqsdHzfat4o21Jw/NbIgEOpIhIje4bbw/lTFmd/2bEuKkDiq6ewqx5rtx+ 5xPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UKwNCZ3kYbqKK0CEnypD41umaTIfpON2HwG6q7KFDlI=; b=A1U1ocJ6RqzqckJDFtXacJAtAAVb6UaEmkFPohgX6yTZ015NJ7fx87AaFCzUWCz3+T fXlJbJqAJpkDhS9a2kYFdKCT/3AHlFsK4IxmFlHN4FKyakPA0/aPea+eDaw3GnRX1F8D hMW3ay2xjMfmcJSAHwJaokJxxaUTfJsQ0LpTZ/qCYMrLPS4D9BT/BkJLiZb2QR38V9pr XKkgcCgDrXuRX+CFDX2B/JFWCPwvZPZTjM3yyk6Z9JsMX1bhjcuRrlYf5TpP0WddYXaU CRT3Hf8PZ18+ID1THQgL9usncE54mFi1pFiBmGYYlkZeC47ZO7fpLkScEtxpfv86e+Mp +tBw== X-Gm-Message-State: APjAAAWLNrucWYWrO6V8OQ5NDU+jYRQROQhQtmiTcXXMW/g1HZtPD9sa ayZZSVm4a83EZCMNnYsyOnUDsQ== X-Received: by 2002:a5d:5388:: with SMTP id d8mr262118wrv.299.1566942348151; Tue, 27 Aug 2019 14:45:48 -0700 (PDT) Received: from [192.168.86.29] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id c11sm186282wrs.86.2019.08.27.14.45.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Aug 2019 14:45:47 -0700 (PDT) From: Srinivas Kandagatla Subject: Re: [PATCH 4/5] misc: fastrpc: fix double refcounting on dmabuf To: Jorge Ramirez-Ortiz Cc: Greg KH , arnd@arndb.de, linux-arm-msm , Linux Kernel Mailing List , Mayank Chopra References: <20190823100622.3892-1-srinivas.kandagatla@linaro.org> <20190823100622.3892-5-srinivas.kandagatla@linaro.org> Message-ID: Date: Tue, 27 Aug 2019 22:45:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/08/2019 16:23, Jorge Ramirez-Ortiz wrote: > can you add me as a co-author to this patch please? No problem I can do that if you feel so! > since I spent about a day doing the analysis, sent you  a fix that > maintained the API used by the library and explained you how to > reproduce the issue I think it is just fair. > the  fact that the api could be be modified and the fix be done a bit > differently- free dma buf ioctl removed- seems just a minor > implementation detail to me. No, that's not true, this is a clear fastrpc design issue. Userspace is already doing a refcount via mmap/unmap on that dmabuf fd, having an additional api adds another level of refcount which is totally redundant and is the root cause for this leak. --srini > > also you can add my tested-by if you want > > TIA > > On Fri, 23 Aug 2019 at 12:07, Srinivas Kandagatla > > > wrote: > > dma buf refcount has to be done by the driver which is going to use > the fd. > This driver already does refcount on the dmabuf fd if its actively > using it > but also does an additional refcounting via extra ioctl. > This additional refcount can lead to memory leak in cases where the > applications fail to call the ioctl to decrement the refcount. > > So remove this extra refcount in the ioctl > > More info of dma buf usage at drivers/dma-buf/dma-buf.c > > Reported-by: Mayank Chopra > > Reported-by: Jorge Ramirez-Ortiz > > Signed-off-by: Srinivas Kandagatla > > --- >  drivers/misc/fastrpc.c | 25 ------------------------- >  1 file changed, 25 deletions(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index 38829fa74f28..eee2bb398947 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -1198,26 +1198,6 @@ static int fastrpc_device_open(struct inode > *inode, struct file *filp) >         return 0; >  } > > -static int fastrpc_dmabuf_free(struct fastrpc_user *fl, char __user > *argp) > -{ > -       struct dma_buf *buf; > -       int info; > - > -       if (copy_from_user(&info, argp, sizeof(info))) > -               return -EFAULT; > - > -       buf = dma_buf_get(info); > -       if (IS_ERR_OR_NULL(buf)) > -               return -EINVAL; > -       /* > -        * one for the last get and other for the ALLOC_DMA_BUFF ioctl > -        */ > -       dma_buf_put(buf); > -       dma_buf_put(buf); > - > -       return 0; > -} > - >  static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char > __user *argp) >  { >         struct fastrpc_alloc_dma_buf bp; > @@ -1253,8 +1233,6 @@ static int fastrpc_dmabuf_alloc(struct > fastrpc_user *fl, char __user *argp) >                 return -EFAULT; >         } > > -       get_dma_buf(buf->dmabuf); > - >         return 0; >  } > > @@ -1322,9 +1300,6 @@ static long fastrpc_device_ioctl(struct file > *file, unsigned int cmd, >         case FASTRPC_IOCTL_INIT_CREATE: >                 err = fastrpc_init_create_process(fl, argp); >                 break; > -       case FASTRPC_IOCTL_FREE_DMA_BUFF: > -               err = fastrpc_dmabuf_free(fl, argp); > -               break; >         case FASTRPC_IOCTL_ALLOC_DMA_BUFF: >                 err = fastrpc_dmabuf_alloc(fl, argp); >                 break; > -- > 2.21.0 >