Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1982367pxx; Sat, 31 Oct 2020 04:46:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZu7e2I3uVYt5kGMLP6wf0Nnnrd/Ng9em6+M42I1oLXnOQ3F7+zhixqXDshFRpkU3M0kRS X-Received: by 2002:a17:906:911:: with SMTP id i17mr6723306ejd.40.1604144817922; Sat, 31 Oct 2020 04:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604144817; cv=none; d=google.com; s=arc-20160816; b=I8AjPpYMs/2mkkurEM5xfkDgTF2g++0fGJu8zavVYAR/1QUC7OxRU/ChvhFZNvOhtv PJ5HOEWh1C3pwnt2GBKemG0nC+K62hp7ELSYNpmOYf2jwPPYSGUKISON1itYgeeuh2kc D0YEXfizZtF+hNMOFugb6kKEhmzOVDoHJxfpWTyoyN8YFdLnerKXSC66cbI7bP+NHqnL W5QZF0PUQoM/XrlAaKmNP/eIzz1E7dgX2heOs2XPh35s4Y2G6UGPbHWzZwPWxto5Pcd8 9vdRG1Aezn+lR72bmDwhXW4a68LLo6rgKBOy5qIirDa1/8rsMJBTQW6teJ0zshFGqCSI +ktA== 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=3wRcN3g8AiwfhxMcb2WhE7XTBZ0ILGUJ3bLYIQj2wBI=; b=jFHqM11NWqGb0OsHQ5EoFkTVIcrrcOczD/ARVU5s109+BydTd1x7s+tMI+tBzvcV8M aTAFfQwdx9BFGEjLe73hYMJ/wgU/mcJAypwUEk14Kow1ScE/Qc9eXH+WCQcMsg7e25uq O5bX/LRsvbfEpC0apDVQ+pm2WTVqUMv+ZuEJdB56JdE6IZm6tHF1ugpSdd5szqB7tXwt sKAs8r/ps14OJUFs+juzD5GtA0471/NbPRMZw+mqlTr7GNbqRJy7A4b59WOc8kP5amvb Yt+xu6kdd5baESyE7nhAcwMVbXjJFOrS5auVAWIHfSV0RskTB6LcFxiHNPVIWzjaEDc8 pdXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r8UzeQCa; 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 3si6197521ejz.513.2020.10.31.04.46.34; Sat, 31 Oct 2020 04:46:57 -0700 (PDT) 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=r8UzeQCa; 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 S1727955AbgJaLnJ (ORCPT + 99 others); Sat, 31 Oct 2020 07:43:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:42844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727959AbgJaLnB (ORCPT ); Sat, 31 Oct 2020 07:43:01 -0400 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 DA7FF205F4; Sat, 31 Oct 2020 11:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604144580; bh=hSLxWkerlkKsPDjUKT0hD7QonBWMhEzCMqL/hrYaWm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r8UzeQCafAw0t4dtz0jwvJtCasyIDON8aWv8T9hl7NH6ELenyk7Qp9zdrVEo070QU qqiVioqnmBSgeacupq6EYhG19yHKGK+t+zNXKSP0cz43nG/R424Io53x6lAwxycu7Y 3NKGVI48zDYcJs+qjE96kMV5wCtJ79vV2ZUMi4lI= 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 5.8 55/70] fuse: fix page dereference after free Date: Sat, 31 Oct 2020 12:36:27 +0100 Message-Id: <20201031113502.134703501@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201031113459.481803250@linuxfoundation.org> References: <20201031113459.481803250@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 @@ -785,15 +785,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; @@ -833,7 +834,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); @@ -852,14 +853,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); @@ -868,10 +874,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, @@ -883,14 +889,16 @@ static int fuse_ref_page(struct fuse_cop if (cs->nr_segs >= cs->pipe->max_usage) 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;