From patchwork Fri Oct 9 15:03:37 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: 11826173 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 81B3014D5 for ; Fri, 9 Oct 2020 15:03:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F1DD222BA for ; Fri, 9 Oct 2020 15:03:49 +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="aa4N1QGk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F1DD222BA 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 3D6506B009A; Fri, 9 Oct 2020 11:03:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 386F66B009B; Fri, 9 Oct 2020 11:03:48 -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 24DF66B009C; Fri, 9 Oct 2020 11:03:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id E95636B009A for ; Fri, 9 Oct 2020 11:03:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E733233CD for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) X-FDA: 77352706452.08.trick86_1913f99271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id BD83F1819E766 for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) X-Spam-Summary: 1,0,0,bb2b02f198c30e14,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.208.68:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.84.100;04y8zheo869od9t5ig6iaa3pz5ghyoceexai9z3n1wr11o9bej65ks87ms5y1tu.txkm4wwdt8hdudcgf8ptbrp8iobko5cukkimn1yxc16ogh77whrg55o3cqarx39.h-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,LFtim X-HE-Tag: trick86_1913f99271e1 X-Filterd-Recvd-Size: 5173 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id i5so9683015edr.5 for ; Fri, 09 Oct 2020 08:03:46 -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=HfGOHdnl8P4UkAJXJm+asFhJ2S9PMVltmlEIidPYuz0=; b=aa4N1QGk9MW7oVueE84pS3IhklP/XdU7RdM9t04ujPc6+KsxPbCNzpAmnfSeiYSmsC KZHr/LYqlvTGsoZDC8fMF7aq5OM7PcEj+UFzb/n5MBMqNsV4HiFNcfPx+U870RxwOmLw GRoRXjF2T5oyi2JVye4+SIOr5LZDF+F7fqGvrZu/jXjQRTccEH+EzI3DH/xZJp/mz+yO OwWK8xhq3V2y4QsDyDIf+dMsxIEbHlQTRm4WK0p8lbBa0q8jYQfoCm/ZoqeSuAefFrVZ 0MuUPGHPEXS1TyeXAZHNNS1KCQ/ZLCrRDgD86GSjDsitEqB1cZOrUExVxuVKJacSGZqs I2BA== 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=HfGOHdnl8P4UkAJXJm+asFhJ2S9PMVltmlEIidPYuz0=; b=gM4ZsN70Lj2HifcJdVBHYl+iQxkxOmb/J/OAUj69A2S/NnwFXeAPHsUzL8lzMY94on o5aUDzGSNZl1TKGg7B0ayFxoSBJ0a0EdlhQirdKAkyXjOnpXCVhnYA/tfTZyojgy2RkI /CoIApDkdoelVbFxaiWt0pAbWdCqsLmkvaAETHbD0usqvONLIpm/oppEjukoXe21JPpJ 2HwDbStCK8t8V7+ruOgLbsOoYAvBuzQ3T+am2zXm0N6lDg0gD+EJgJAaaPgmjhVgvLpQ 0VQJMAXZiSDaKLUOMZUgXGHm5/W762lOoEVJGZ4jFhimwiOvac1NEMsO22aHsDKhAaeS 5iMw== X-Gm-Message-State: AOAM533VpuzTsR1F3eVm0SmEIB/8N0XA5iEcyWkS6Yogf1bYcorXv9SV HTy8CJXDeqlJ0cP8rLLTbOnKIM0J6E0= X-Google-Smtp-Source: ABdhPJyibPjE78lcVPlBYyG6PW0fP1GpDj3X5Tpm1VzsO7r6v4QYdB2IMOhxokvqNlnbjQNZuzUauQ== X-Received: by 2002:aa7:cc18:: with SMTP id q24mr8619083edt.108.1602255824666; Fri, 09 Oct 2020 08:03:44 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:65f3:51d4:50d0:15b0]) by smtp.gmail.com with ESMTPSA id v14sm789364edy.68.2020.10.09.08.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:43 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: 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, akpm@linux-foundation.org, daniel@ffwll.ch, sumit.semwal@linaro.org, willy@infradead.org, jhubbard@nvidia.com, jgg@ziepe.ca Subject: [PATCH 1/6] mm: mmap: fix fput in error path Date: Fri, 9 Oct 2020 17:03:37 +0200 Message-Id: <20201009150342.1979-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. Signed-off-by: Christian König Reviewed-by: Jason Gunthorpe --- drivers/dma-buf/dma-buf.c | 22 +++++----------------- mm/mmap.c | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index a6ba4d598f0e..edd57402a48a 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,13 @@ 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; - vma->vm_pgoff = pgoff; + if (vma->vm_file) + fput(vma->vm_file); - 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; + vma->vm_file = get_file(dmabuf->file); + vma->vm_pgoff = pgoff; + 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);