Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4488311ivc; Tue, 3 Nov 2020 13:21:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzytoz8Rto/OGXm0mX2DdLCCNFnX1WnoNXVhcHvaNck83yEGXyvUJTy1+HGnhcf/hALcNXq X-Received: by 2002:a50:f392:: with SMTP id g18mr7145381edm.140.1604438513656; Tue, 03 Nov 2020 13:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438513; cv=none; d=google.com; s=arc-20160816; b=xsxPXM7zVz9uYp+byHRLfpeFiTPT6PQ7z3WPaIVHVYfJAMzevsiqctLMrA3lA/saeu tbKh2l19ItTxDk4wfyFyAm5Vry5jLEaHj3Hok8yiZAeTyp2FU+p1oWpYjHcPeMv27Cp2 k4yT6X1+LpX0PejCdMTkHKaF52mec3aQnRamevhh09ICbN7Hkj0T6u7kYG0UXkyXwdnM EyzaVmQ39Yg+AQB1uxDZU0vOTweNpEtmCm53FwXfj2d3Zjv3GWMR1FUmd4RphCf7pgm8 K7TnulPmkhcLwXMcFXcRmXPsyq47vyLjwNA+/TeIPyUaH4UA4j5Vu+AYKmjP7PFaUlal 85DA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cR7CFHbMGMT7r0nzLVuESBtBlXsSRH3rugj7cmOyt6s=; b=Ko/WFq4g2ZEUAC059e6DthivhiOkDsWSksmRF5ThsV1ePPG8fPSYGGntx+043egcww aAkPae04Bp+J2wC6p2BbVPpDhNoPKu3ASuotPzMEKAaU9eP75hKwWKRJCPLWcEyHIR7A HjoS7Lr15m57kQq3RTudb/e1fhht5qAjpS5vJXBFWT4q8nB2Lcd3R+/xlh4uO0dhXxhn GHzErmJXaUcglckQZBm/WTNw/7EWeY6vCC7jOKZ3ucgAjTz5Oza8YnSWjaRp7uxYbzo3 Qtjtys1SjcI+3pF2tDA11eJRz5JIIIErxwLr5+JhgYLYvWJCxEQqnCJH8wwB0Mud0gN2 3mhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L+9QrBxB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o60si14175318eda.61.2020.11.03.13.21.30; Tue, 03 Nov 2020 13:21:53 -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=@kernel.org header.s=default header.b=L+9QrBxB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389035AbgKCVTC (ORCPT + 99 others); Tue, 3 Nov 2020 16:19:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:49600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388520AbgKCVJb (ORCPT ); Tue, 3 Nov 2020 16:09:31 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41B2E207BC; Tue, 3 Nov 2020 21:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437770; bh=DGM/X/a9t9GYZ2siAxQ06ZsOOPNmq5LLGDLadmqlSgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L+9QrBxBeKsZpPKehcdxssKk03ewne8asXkn7K9ipFacPUo1gXrd66htZMmcPZ3uG bGgbG/fCD6StJl2MVWN4XsSJq1k8FZJMokzkGlNXA4JUj2GE3fx9XBE1PRWS6YocKE Kz6TplJB5qcCxxYOHVsHvkbu8KlmPzG5GUHS6jbg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pradeep P V K , Miklos Szeredi Subject: [PATCH 4.14 009/125] fuse: fix page dereference after free Date: Tue, 3 Nov 2020 21:36:26 +0100 Message-Id: <20201103203158.107723172@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Miklos Szeredi commit d78092e4937de9ce55edcb4ee4c5e3c707be0190 upstream. After unlock_request() pages from the ap->pages[] array may be put (e.g. by aborting the connection) and the pages can be freed. Prevent use after free by grabbing a reference to the page before calling unlock_request(). The original patch was created by Pradeep P V K. Reported-by: Pradeep P V K Cc: Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -845,15 +845,16 @@ static int fuse_try_move_page(struct fus struct page *newpage; struct pipe_buffer *buf = cs->pipebufs; + get_page(oldpage); err = unlock_request(cs->req); if (err) - return err; + goto out_put_old; fuse_copy_finish(cs); err = pipe_buf_confirm(cs->pipe, buf); if (err) - return err; + goto out_put_old; BUG_ON(!cs->nr_segs); cs->currbuf = buf; @@ -893,7 +894,7 @@ static int fuse_try_move_page(struct fus err = replace_page_cache_page(oldpage, newpage, GFP_KERNEL); if (err) { unlock_page(newpage); - return err; + goto out_put_old; } get_page(newpage); @@ -912,14 +913,19 @@ static int fuse_try_move_page(struct fus if (err) { unlock_page(newpage); put_page(newpage); - return err; + goto out_put_old; } unlock_page(oldpage); + /* Drop ref for ap->pages[] array */ put_page(oldpage); cs->len = 0; - return 0; + err = 0; +out_put_old: + /* Drop ref obtained in this function */ + put_page(oldpage); + return err; out_fallback_unlock: unlock_page(newpage); @@ -928,10 +934,10 @@ out_fallback: cs->offset = buf->offset; err = lock_request(cs->req); - if (err) - return err; + if (!err) + err = 1; - return 1; + goto out_put_old; } static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, @@ -943,14 +949,16 @@ static int fuse_ref_page(struct fuse_cop if (cs->nr_segs == cs->pipe->buffers) return -EIO; + get_page(page); err = unlock_request(cs->req); - if (err) + if (err) { + put_page(page); return err; + } fuse_copy_finish(cs); buf = cs->pipebufs; - get_page(page); buf->page = page; buf->offset = offset; buf->len = count;