From patchwork Mon Oct 12 08:52:02 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: 11831943 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 73C9A697 for ; Mon, 12 Oct 2020 08:52:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E956120E65 for ; Mon, 12 Oct 2020 08:52:08 +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="lw+tUQcX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E956120E65 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 105E9940007; Mon, 12 Oct 2020 04:52:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0B617900002; Mon, 12 Oct 2020 04:52:08 -0400 (EDT) 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 EE77A940007; Mon, 12 Oct 2020 04:52:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id C040F900002 for ; Mon, 12 Oct 2020 04:52:07 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 42C168249980 for ; Mon, 12 Oct 2020 08:52:07 +0000 (UTC) X-FDA: 77362656294.28.chain21_2a103a8271f9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 1EFBE6C05 for ; Mon, 12 Oct 2020 08:52:07 +0000 (UTC) X-Spam-Summary: 1,0,0,441f861345647ab0,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:1381: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:6737:7903:8660:9413:9592:10004:10400:11026:11473:11658:11914:12043:12048: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.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.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 X-HE-Tag: chain21_2a103a8271f9 X-Filterd-Recvd-Size: 5246 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 12 Oct 2020 08:52:06 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id md26so22066782ejb.10 for ; Mon, 12 Oct 2020 01:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=yMIANltJzggMKevCuA/64ylJ5xrfMe99CRAziEtSDMY=; b=lw+tUQcX6E58leo0iNUqUuxVirmooB9X9E28JBa9u2lgsb0RDv0+NxJBs03bTu7r0B D5EPdSramySPYUis9ltXlotS4rQuxBR+Lpg3kMC59NVAL4HKTGbhmk92F5o8LIbmtzv7 iMpjDgh6fHILhflZmN61tUTEN+tVt4sHxRVmsmlXUWFTWigpqtu+/NNfdmgb6t9xuYQJ UR1KOZokmCcW8f1eYTtWvUlJrfmNcsSSOy5zYIB6J+97c1BT/O3HLomn+xovaPPdAKVB dQVqbzeDFYRKcQP3MlkRlIElHDn3nkr52Yh/OQIpwBDSFtHpuLbXkazdkd5l455I7zZ6 nJlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=yMIANltJzggMKevCuA/64ylJ5xrfMe99CRAziEtSDMY=; b=WdbfwN7GKXXeBIPbANCq86adsxRQxs31VCqhK7Fq8ykcVbLSRG0xHGm5ToNqLa4yGt YOG4GljfZlTI7pffrwgxyIhUjASUTkKbssUyGsSpoGVNkV91wUGpIY1MVNXGDUmu8k6O eOop9FpRdic+IZ2AvkVmx9L6jsxPYgtDtv5d4Dt35/4219spiJAUY31J7YUIrCcPVddo /RWXKoQJV7CbmsUAdcuap/o5+oNVPh5MddchHH+JmRlTJNGDhu7snk4HgJbv/B+6+zW4 oaeQL506Lbnb9ljV3VEfch2ut09CtPTK0xaYQX26WBfyygpNkGhBSIjlohLuRXq5DvUs ZD8g== X-Gm-Message-State: AOAM532sFK2b7gE02ffzwhaEA/q0XAMpUHPHdADvKCO9j5ZytTMmNfZL BAOZ6x910o/mIL38DQzq4AY= X-Google-Smtp-Source: ABdhPJxnwEuylsU7eSmkWOtF42j8bglh0/rf5pkHlz0ZkTIK1CSAgwpiELeW85OngsabmXKbddLIWw== X-Received: by 2002:a17:906:95c5:: with SMTP id n5mr27686729ejy.111.1602492725376; Mon, 12 Oct 2020 01:52:05 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:6a6c:c67:2644:1d74]) by smtp.gmail.com with ESMTPSA id o35sm8622988edd.4.2020.10.12.01.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:52:04 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: akpm@linux-foundation.org, 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, chris@chris-wilson.co.uk, airlied@redhat.com, daniel@ffwll.ch, sumit.semwal@linaro.org, willy@infradead.org, jhubbard@nvidia.com, jgg@ziepe.ca, linmiaohe@huawei.com Subject: [PATCH 1/2] mm: mmap: fix fput in error path v2 Date: Mon, 12 Oct 2020 10:52:02 +0200 Message-Id: <20201012085203.56119-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 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 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 a6ba4d598f0e..08630d057cf2 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1143,9 +1143,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; @@ -1163,22 +1160,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 40248d84ad5f..3a2670d73355 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1852,8 +1852,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);