From patchwork Fri Nov 6 11:48:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11887017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09677921 for ; Fri, 6 Nov 2020 11:48:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8B90206F4 for ; Fri, 6 Nov 2020 11:48:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dwBxmPRi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8B90206F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EF95C6B005D; Fri, 6 Nov 2020 06:48:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E0C1D6B0068; Fri, 6 Nov 2020 06:48:12 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C32056B006C; Fri, 6 Nov 2020 06:48:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 949666B005D for ; Fri, 6 Nov 2020 06:48:12 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 38558181AEF10 for ; Fri, 6 Nov 2020 11:48:12 +0000 (UTC) X-FDA: 77453820024.23.birds62_4711af1272d2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 181E33760C for ; Fri, 6 Nov 2020 11:48:12 +0000 (UTC) X-Spam-Summary: 1,0,0,44984fa9d06f4788,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1542:1593:1594:1676:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2899:3138:3139:3140:3141:3142:3353:3865:3868:3870:4321:4385:4605:5007:6261:6653:7903:8660:9413:9592:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13148:13230:13894:14093:14096:14097:14181:14394:14659:14687:14721:14877:21080:21444:21451:21627:21666:21740:21939:21990:30045:30054:30064:30069:30070,0,RBL:209.85.218.54:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yfgwpfn1nwepauwsiixtjfp1wcfopwsyha6ghftyi5dxxxdbc6u71wqc49kwj.s8o9b1x9eeqdcgdjd8ai4k5odhzxr9xkxf8xyku8qd8x7iohobpxzfk7xq5785g.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:69 ,LUA_SUM X-HE-Tag: birds62_4711af1272d2 X-Filterd-Recvd-Size: 5251 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 11:48:11 +0000 (UTC) Received: by mail-ej1-f54.google.com with SMTP id oq3so1485437ejb.7 for ; 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=gxuCEtiFuIdNvjKzCBfFSaK7zDlaap4bz3P/qWFcrQjYn9fgXEVWKDfhumIs1hLsSK h/tKRVnaUw24r/oAupH5y6JEyjQBhY8nHVLcAciozUzFJf5F2cddAWzleW6VXyFfVHOm mqEtyuetKOusI7MWxoOIcVGCD6sBg7zaw4bod6et37c8W9mddt2BCKd1cy0HvTA7TR5E 3LtgfIlELOSd17zAcWLillGGJkwlVTiM0tDYx8Auyx76GOQb1nvSzaSAY5B03XR8MvVb tFkZfz08G9a2OoTU+0yD1fL9WkD/0+9wchQ/o07EaDwpHBD5ZvtysxpS1x98PdR2ziln B/lQ== X-Gm-Message-State: AOAM533+hbEXABjNpoCjY0s43j0y7g20qMPlhXO7lHl29vqt+qRuAdEX PZCbFafNIrfzgP07XHpz0E7J8NtCUP4= X-Google-Smtp-Source: ABdhPJzcrRQtSzVw6Cx/8bs9wFTOEqntQvRxu+IoDSCnHLgYmCyzUgZk5DO9jYm3No8iZLoVYt4mvg== 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_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Andrew Morton --- 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);