Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1202677pxb; Fri, 6 Nov 2020 03:50:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXVEbjc5YcFvQ/sXChRFSc+uA46Nh9WW19ZHw/Bz7nEE5Ow0FMjkdeTekIeXxJVjqfe+3r X-Received: by 2002:a50:b224:: with SMTP id o33mr1522517edd.21.1604663404351; Fri, 06 Nov 2020 03:50:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604663404; cv=none; d=google.com; s=arc-20160816; b=pzhuW0At4BNTtjwjHxvl9rn58JFMXkWDcUCyTbzZ6SYkqEqciNLLkn7M7Lc2tkYWr1 u94EhEksRP/Qkvs820sUWP/IiVxvAE2vzuxdzdAQdlApo5raICsMG5eHJGan/6424+px vuivJ7dHO8zGBUUjf5QfsbQPNhSsG8sDhjo747W6nruu2N9tvmBlrCV8IISoLSApkk1o 919Sq4wWJ3N4IifGKOSEb6XW9gT6g0d6pUypcQme2rWsR9HdzRDnxqGCbOCrqCrxBqTv boequy3nW5DCb/zup6vJQ7+GxHmiM5Y3n+NFrOTjzrQalwL4FZLKFEdLQ6PNrcr73kdE herg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EHBGsJ+axiVeE8GmrzxBefG74B7GrWvtyoVrJ1bJNe4=; b=q+wh7Sc90M8OjETvDLV0WmhHz5Hc893MAAPhH9deN2fAVj1aDfDAZ/ZjuzIUtHPZFQ jAPm8XRqNtLfH7pv0n+n1b009rBxXtiJ/++1IxmaV6X5RjzwgsWGsekRepFNCeQ/VZz7 ObJSL1fpcnAlVeqleO799rH0/a/Q4DK2UiPvFPbuzvO2A4CBLfwJ2sevR2h6r+ITzNyE bc2ANEhQ6QA/mVrbEIYrOm4T+R9QOJN89gbrBSX3oN8l9df+/Cplf0wc3qbDoL+ShxRE 7Z/jxheT+3DyZ3efKBYl7hm+uvvVGYpdX/5HqXQu73zuaKRgReunAsc1dW6v6HeTOzFo 97Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dwBxmPRi; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj24si636060ejb.567.2020.11.06.03.49.34; Fri, 06 Nov 2020 03:50:04 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=dwBxmPRi; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727186AbgKFLsM (ORCPT + 99 others); Fri, 6 Nov 2020 06:48:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbgKFLsM (ORCPT ); Fri, 6 Nov 2020 06:48:12 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBB83C0613CF; Fri, 6 Nov 2020 03:48:11 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id k3so1475774ejj.10; Fri, 06 Nov 2020 03:48:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EHBGsJ+axiVeE8GmrzxBefG74B7GrWvtyoVrJ1bJNe4=; b=dwBxmPRis0CiuAvK3dpOVlXXCno92VoLNCF1plCpOyt21fe2HVq2z6F84DJPbrQF4y 0J9okR7YYlAYxRqf+Dz8r9mKuiULzAsOf5AF3Hc/S5Ywjvftp9XrZgxQzWBdZ+eTeYsR jWe04yebEH/9RyBNzawmtcYPrsJ0aLi6bS/P6GABAf0jO3H5KVomei5TdK8hJBvTWbb6 FEKDthSvgXbSF48Z7njmHcOCSPpext8ymP5f9Goy62lvTZc6BnWB7Ez/Ie9LvPYT8r/R CzScPtmKb8LsbbGsHY0Mz2nJg0jR4KtUoiLMkvbfsFmGc1jpjoLlQVAL2zaVn1PlXOZq XhFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EHBGsJ+axiVeE8GmrzxBefG74B7GrWvtyoVrJ1bJNe4=; b=HwTIESxnmnpolpE3ypfd8hrai/imnY15iI1QTzsSjQxe+aUwIHC3UfKeiD9JisOdBv DdNw6Pvhjrc0cC0+5cXN9PbcGmw4gIzIY/gjCdakWIq548JIFMtz+kP/BtHujDNYUUXJ KAgTP61RpmiLZHaqZF6P27SVpPoYb8AuHW4WOSefU/oTHCW2JIXpIqO1HLRKczpGXsjR 7crFykfr7wwPtDyHLSvhZNuYz/odtKwJMkfbJ3EDBYJiNkSqAIxdEIkFkWG2B5AKW4YS 9YahkaWlZkJxDw7OZYTmahJpjEKrAgqQzpWU7WJLls93gi16m2nmdLJ2diroXH9kC6Si Uatw== X-Gm-Message-State: AOAM5327th+1TLxgWsV1ri3NoNvU9HkpVnACYal/2YlJmDnNVp8m0D/C kmBhZAbMM/giAkgvAg8LXUc= X-Received: by 2002:a17:907:119e:: with SMTP id uz30mr1681508ejb.125.1604663290625; Fri, 06 Nov 2020 03:48:10 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:c066:c9fc:f8c2:d50b]) by smtp.gmail.com with ESMTPSA id j8sm875933edk.79.2020.11.06.03.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 03:48:10 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: [PATCH 1/2] mm: mmap: fix fput in error path v2 Date: Fri, 6 Nov 2020 12:48:05 +0100 Message-Id: <20201106114806.46015-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201106114806.46015-1-christian.koenig@amd.com> References: <20201106114806.46015-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Patch "495c10cc1c0c CHROMIUM: dma-buf: restore args..." adds a workaround for a bug in mmap_region. As the comment states ->mmap() callback can change vma->vm_file and so we might call fput() on the wrong file. Revert the workaround and proper fix this in mmap_region. v2: drop the extra if in dma_buf_mmap as well Signed-off-by: Christian König Reviewed-by: Jason Gunthorpe --- drivers/dma-buf/dma-buf.c | 20 +++----------------- mm/mmap.c | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 0eb80c1ecdab..282bd8b84170 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1166,9 +1166,6 @@ EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access); int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, unsigned long pgoff) { - struct file *oldfile; - int ret; - if (WARN_ON(!dmabuf || !vma)) return -EINVAL; @@ -1186,22 +1183,11 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, return -EINVAL; /* readjust the vma */ - get_file(dmabuf->file); - oldfile = vma->vm_file; - vma->vm_file = dmabuf->file; + fput(vma->vm_file); + vma->vm_file = get_file(dmabuf->file); vma->vm_pgoff = pgoff; - ret = dmabuf->ops->mmap(dmabuf, vma); - if (ret) { - /* restore old parameters on failure */ - vma->vm_file = oldfile; - fput(dmabuf->file); - } else { - if (oldfile) - fput(oldfile); - } - return ret; - + return dmabuf->ops->mmap(dmabuf, vma); } EXPORT_SYMBOL_GPL(dma_buf_mmap); diff --git a/mm/mmap.c b/mm/mmap.c index d91ecb00d38c..30a4e8412a58 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1899,8 +1899,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; unmap_and_free_vma: + fput(vma->vm_file); vma->vm_file = NULL; - fput(file); /* Undo any partial mapping done by a device driver. */ unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); -- 2.25.1