Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3214233pxb; Mon, 9 Nov 2020 05:46:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqE8SbmjIs2b3JcVPSqkquoqBoqdlsM8vkydxwcntxDh4wqTzDShakun6iOXsewLFCvulj X-Received: by 2002:a50:ab15:: with SMTP id s21mr15355627edc.88.1604929604575; Mon, 09 Nov 2020 05:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929604; cv=none; d=google.com; s=arc-20160816; b=OQaeEyaRT5KpIhJ/ObonHQNrEgh/IuEmDuSgVBfu0mSl639rsyAFpFephhxPhq1Dvc pkS5/1zU2J+qBvi02n68D4tUX3bVGRbGbr75uS5GykK/gedmYKlX0v3U+uS4NHj7io3C hbtCNLa7kw1vnK8dYs/HmNhOxpj+N+2X1DN0WJgMgZM2e7ovXCOwVpUqUbxXVz5KBfqz +YfoQJFNMr/RgQQD5UQ+ZOKSnbVqAheiOSJk8xEoNnNtx+3DXuaZBOc3pyfvenxY5VGO hpQY9ARUSiUHoTsTaj6LzZjQtzv0qgKHmj6thXHCOPxnS1npaGjCg+C7cNfuJ2CnaD9V D9uQ== 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=YgSmJwAAzaJhhfs7/VwU1Zbpu0ipd4rVsffoCwXmVJc=; b=ZQ5XtNcughzN+tpTjsJl4znopJOKLdDAbnzg2C+rVZ9ufsOnzjp/pot4+rwUFTui5k u9+2GIZ606pmBlHdug21stT1/J/09oOXXzKQgm5AoVkd6QiZmXAdueG1coxQn9MHWxD+ B78UoL/CMtx8lOWH9jjt2d4TrUpU8fygjAeqyUtE8kufrHfOKwCdMfq1SCqCeo66pEDa 3wLG6uWHnNnDo93Cjr0sF7X6/RVn4fMLLMCPeZjy/0xGduNcy0dX169+rVvDZ3b1It5O bgEgRXrpWPlBfyaXUyjOV3+BrD2OM+K975jWaadZesmucMwZFk4bQ5LMx1T8sRxEht2E InMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bUOw/4JA"; 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 d12si8283315ejj.33.2020.11.09.05.46.21; Mon, 09 Nov 2020 05:46:44 -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="bUOw/4JA"; 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 S1730506AbgKINAc (ORCPT + 99 others); Mon, 9 Nov 2020 08:00:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:54490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730483AbgKINAU (ORCPT ); Mon, 9 Nov 2020 08:00:20 -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 A87DF20684; Mon, 9 Nov 2020 13:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926820; bh=yq56alpSp8nwIw3snokF1ceZ19rUu9MMXV9XI93QnR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bUOw/4JAL6sdk4gT1dPV5z8w26S49+SkO5+49JyVUOK+ltSmjWZS6T4m0ByVdUvxb k/hu+3eoN31rmY3WTlK/MUWngRoSGro/lfXyq3MWLZBwQWijd/cR1WfgvEKfEHs5Ac 70gc6Hf5RDdZSTsKIgYuNjYZ9qW2PgD1RCEMCcBY= 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.9 008/117] fuse: fix page dereference after free Date: Mon, 9 Nov 2020 13:53:54 +0100 Message-Id: <20201109125026.044111558@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -846,15 +846,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; @@ -894,7 +895,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); @@ -913,14 +914,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); @@ -929,10 +935,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, @@ -944,14 +950,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;