Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2515909ybt; Sun, 21 Jun 2020 23:39:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIYvcJLM/sATpKHC1rSGGyGaODMTTyWpvnkIh5qv0kCYvc05ZoCQV2DYgOXEQBizFOrYL3 X-Received: by 2002:a17:906:f6d6:: with SMTP id jo22mr14045095ejb.310.1592807990008; Sun, 21 Jun 2020 23:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592807990; cv=none; d=google.com; s=arc-20160816; b=B7IC/0rSdgWTPzcsvclPWt4lwewtCRebxBxON4pxnbA9HyUlXsZ7qRFX2SjbP6G7KE U6HI0sna9cTVIPQ6axP+h3Kvtq3wmUqpZCnnTdgdeEfia/Uq2sitoS9RBBBo9Q9K4jsb NWDRhbK7FQ1+A2YNJxK+F6+dAxXJ+WHjECt5wHTjD1lF9oQ8F3k6vxVnKycve/3HVhe0 jnNXt/uBfS2N8SEv8WemE7jEG38c5PVXYO3ruzCCS9bbGOluDWBbV88KqB7qmvmUedrd q28a9NIsqfCBVqbMqE8RH0YQ+hPk98bBHIeXdyC1kD7D/T4nrW83qme/yukogHBW/+1u QZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fA+O46nAmMQU+XrEe2RpDVyUBd8QOlVEvixhrlksQsk=; b=LaVt3hQbkd/aZzuxbmdY/3skyyRr+5MafyuaF66/3+qh6v5Gh7b9qTL/1XLuIhv/GK cbzmtiLbaDxkDeIzpiaxWFWhfqicuzumlAlifCiKOBT3mcgo9W8G2ZxgEFP991eaqGpp L+HhPljexPajc3PxXbdFf1GKqzB82YY1VMBcdOqDQxKzofpK+gEmRVSvp4WWQsG2Y+9A nlJX/qDKdp91GgO82tI+CVATykv50xnrYKRnySWxvSgsISOVnhokkBRVLi1+u2/o2UCl IXpI0ig/57xtc+4AsdqEO0JnZ/wQvwdX3VrXinLH00ClobABBXNDREPwlr4v9txhT/Ou krng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b9/LB+2u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id w17si3535553edx.522.2020.06.21.23.39.27; Sun, 21 Jun 2020 23:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b9/LB+2u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731292AbgFVGe3 (ORCPT + 99 others); Mon, 22 Jun 2020 02:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731248AbgFVGe2 (ORCPT ); Mon, 22 Jun 2020 02:34:28 -0400 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48F25C061795 for ; Sun, 21 Jun 2020 23:34:28 -0700 (PDT) Received: by mail-ot1-x344.google.com with SMTP id t6so12168595otk.9 for ; Sun, 21 Jun 2020 23:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fA+O46nAmMQU+XrEe2RpDVyUBd8QOlVEvixhrlksQsk=; b=b9/LB+2uOPC2C+s6xNSxYSTXptcjEphcExsNN+CkhnNfNoRXsHKjNJYc3YIrGGzPDH ++YxJtnCQUmP3PD/YQoMg/BlUCiy2n33EYzQBEfkxbebiB4hcx+BikkxstWpvr+y3jeX qgY4neCyplc7bi0sc+Gdk8vAKpmLkwwstm8khaq3fbVVb7HDadQ1Q458wU68MPQxzS/Z sKdhLfpy4uFaJz0QHpn96Y+zk/5kQNrBiA9YhzfBvyyxrYtyVmgmVok3dFllvH+gkabs KUE7uG1jIz+vpHmlB+wXVLblZD793pLEMsMXUA69TEoyqALcnB7iSbmSmSPNwdOOR0j+ bmgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fA+O46nAmMQU+XrEe2RpDVyUBd8QOlVEvixhrlksQsk=; b=gbWfu+/oIwT0CF/L5BaNPZNHPgyORo2whU0K7EP/F0DAhMcbdyffXP0rPUwOq8P84h xZE/NEgvGzDHq7672C5jKH5Mhq2FBGn7Mj2BX4PyaipdY9oS2Xsgz7eILfBgRnQ/b60A n3Eh0ilXYqX97l0Z3mbjUJoYS6azIVUkar725PY7Ovc4p9ycbTiydCrpudQtMkI83hG4 GIWg2xaOtM/ci8NDgNQ4Br2OLsabprZl8VRX1ELunnDjEjY1ZF2Ii9C0YbgJ8XV/yN/1 M8ZCXjy9/T/MB68OkhCojVHPbAHI5TmWPdG+yBPuIhD783LXhmBZDMBanPesYXc0L2EZ x4vw== X-Gm-Message-State: AOAM530XwZgHqtoKfVMsIpu3FMcP/rXc/upqpODpvhxm9Or4JvZjGppW b7Na/dOenyiD/bFxiG0K8zpO1dzn98bquvEMJvFlwg== X-Received: by 2002:a9d:64da:: with SMTP id n26mr7434635otl.36.1592807667489; Sun, 21 Jun 2020 23:34:27 -0700 (PDT) MIME-Version: 1.0 References: <20200611114418.19852-1-sumit.semwal@linaro.org> <59f0062d-5ca9-84f1-ba92-c3463ff0e73d@codeaurora.org> In-Reply-To: <59f0062d-5ca9-84f1-ba92-c3463ff0e73d@codeaurora.org> From: Sumit Semwal Date: Mon, 22 Jun 2020 12:04:16 +0530 Message-ID: Subject: Re: [PATCH v2] dma-buf: Move dma_buf_release() from fops to dentry_ops To: Charan Teja Kalla Cc: "open list:DMA BUFFER SHARING FRAMEWORK" , DRI mailing list , Chenbo Feng , LKML , Linaro MM SIG , syzbot+3643a18836bce555bff6@syzkaller.appspotmail.com, "# 3.4.x" , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Charan, On Tue, 16 Jun 2020 at 19:13, Charan Teja Kalla wrote: > > Thanks Sumit for the fix. > > On 6/11/2020 5:14 PM, Sumit Semwal wrote: > > Charan Teja reported a 'use-after-free' in dmabuffs_dname [1], which > > happens if the dma_buf_release() is called while the userspace is > > accessing the dma_buf pseudo fs's dmabuffs_dname() in another process, > > and dma_buf_release() releases the dmabuf object when the last reference > > to the struct file goes away. > > > > I discussed with Arnd Bergmann, and he suggested that rather than tying > > the dma_buf_release() to the file_operations' release(), we can tie it to > > the dentry_operations' d_release(), which will be called when the last ref > > to the dentry is removed. > > > > The path exercised by __fput() calls f_op->release() first, and then calls > > dput, which eventually calls d_op->d_release(). > > > > In the 'normal' case, when no userspace access is happening via dma_buf > > pseudo fs, there should be exactly one fd, file, dentry and inode, so > > closing the fd will kill of everything right away. > > > > In the presented case, the dentry's d_release() will be called only when > > the dentry's last ref is released. > > > > Therefore, lets move dma_buf_release() from fops->release() to > > d_ops->d_release() > > > > Many thanks to Arnd for his FS insights :) > > > > [1]: https://lore.kernel.org/patchwork/patch/1238278/ > > > > Fixes: bb2bb9030425 ("dma-buf: add DMA_BUF_SET_NAME ioctls") > > Reported-by: syzbot+3643a18836bce555bff6@syzkaller.appspotmail.com > > Cc: [5.3+] > > Cc: Arnd Bergmann > > Reported-by: Charan Teja Reddy > > Reviewed-by: Arnd Bergmann > > Signed-off-by: Sumit Semwal > > > > Tested this patch for Android running on Snapdragon hardware and see no > issues. > Tested-by: Charan Teja Reddy Thanks for your tested-by, appreciate it! Chris, any luck with your CI to test if this also helps your dma_buf_release() bug that you guys have seen? If you've not been able to test, and there are no more objections by EOD today, I will merge this to the drm-misc-fixes branch. > > > --- > > v2: per Arnd: Moved dma_buf_release() above to avoid forward declaration; > > removed dentry_ops check. > > --- Best, Sumit.