Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2352435pxb; Mon, 20 Sep 2021 19:49:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwscXilYd7WbT84ClYp2hKFU3P5OlqY0eKeDV08J9YeIo1waTBSzPm22ty/kRWHkyEaWmwi X-Received: by 2002:a17:906:2f15:: with SMTP id v21mr32321205eji.444.1632192575269; Mon, 20 Sep 2021 19:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192575; cv=none; d=google.com; s=arc-20160816; b=hLQnq29Znkmw4F+kBNL6LzktSIJTFfZRUWjqGRypEIJG2+oSEGRSK90giXrBCp0rRT aPWYqU9+BhHZsWlFd636yUYNOZYxpi3TWlHcAVZMwtQbj9kaFoTWZh+fPlOZcp31rNaz F+G9hLrqTjKDkkHSRRQ5RCWOI4mj1syvP1w1oeNjkKl1Zy19RlDfU6+satYqi02rCPne 98TJsNCCUF/QpXRDhRL1UlGKw/iq1YhXQaU8zd97nza828idLY/adcci8EBZmhCncFVR baMOKzTdcETYKCygUtoHMEJKLSoGmEGGnzztAF4LyhY+fP2jcvcpacrwBbx218aYXZ9O iLpg== 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=ISvTtBEL9Jy6ooqc8lrkKgNa9HROfrAKdKK3wHgP4zY=; b=z772O3zMZGZOssmb4/lxFLTlI0nM6bOam8nl4hL6EWLe37NF0cMT7KLW53PoH9KVcY fO3dorpaTEB+xkvP9mhv1AgBvquvBdIJbcC30C0Pm4NsajOdUcbCJM2LjBwYm9qx9TZ+ wLRJu+wWjVCjS7krQpJ7rPmCrnffUh3JA/flGy4iTdPWrcQj5IDRpBrihfu1vNI0Wx7R U3RgyKD2ppT9Pcok3oA87+CsMLi4O+ErojAjRKlfHn1EcyXYnrI4wsJ/W4eCqNu7YxWF Mj94N/DTW6FOEGc61F3tZdU2N0eAT2zzKvVQD8L9yCOfHXXeF3+mvojpx4e/+StzqsSA QWSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mJFq9bOg; 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=pass (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 p10si10061650ejl.495.2021.09.20.19.49.12; Mon, 20 Sep 2021 19:49:35 -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=@linuxfoundation.org header.s=korg header.b=mJFq9bOg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381444AbhITSiE (ORCPT + 99 others); Mon, 20 Sep 2021 14:38:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380244AbhITSdA (ORCPT ); Mon, 20 Sep 2021 14:33:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 754A261AA9; Mon, 20 Sep 2021 17:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158887; bh=f51RfyND1n5AOWohNmVh519ztoFsZG6geBRYA01Fg6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJFq9bOgSl2feHf4WMwkLFgLKsx4h9R3MdNO9N8kakeFBYE240K440Hcz2D8h7Nya ID8KdQA6SxRKM62JbaWKTEVNYTSqiTTwOQLpG6ldac8k4AsueFAmCx6joGBpHjGLcx 6uc2hXT2FAe2gtm+euJcUwdzW19hloRaOjor7oMc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, lijiazi , Miklos Szeredi , Sasha Levin Subject: [PATCH 5.10 058/122] fuse: fix use after free in fuse_read_interrupt() Date: Mon, 20 Sep 2021 18:43:50 +0200 Message-Id: <20210920163917.684052361@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163915.757887582@linuxfoundation.org> References: <20210920163915.757887582@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 [ Upstream commit e1e71c168813564be0f6ea3d6740a059ca42d177 ] There is a potential race between fuse_read_interrupt() and fuse_request_end(). TASK1 in fuse_read_interrupt(): delete req->intr_entry (while holding fiq->lock) TASK2 in fuse_request_end(): req->intr_entry is empty -> skip fiq->lock wake up TASK3 TASK3 request is freed TASK1 in fuse_read_interrupt(): dereference req->in.h.unique ***BAM*** Fix by always grabbing fiq->lock if the request was ever interrupted (FR_INTERRUPTED set) thereby serializing with concurrent fuse_read_interrupt() calls. FR_INTERRUPTED is set before the request is queued on fiq->interrupts. Dequeing the request is done with list_del_init() but FR_INTERRUPTED is not cleared in this case. Reported-by: lijiazi Signed-off-by: Miklos Szeredi Signed-off-by: Sasha Levin --- fs/fuse/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 4140d5c3ab5a..f943eea9fe4e 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -288,10 +288,10 @@ void fuse_request_end(struct fuse_req *req) /* * test_and_set_bit() implies smp_mb() between bit - * changing and below intr_entry check. Pairs with + * changing and below FR_INTERRUPTED check. Pairs with * smp_mb() from queue_interrupt(). */ - if (!list_empty(&req->intr_entry)) { + if (test_bit(FR_INTERRUPTED, &req->flags)) { spin_lock(&fiq->lock); list_del_init(&req->intr_entry); spin_unlock(&fiq->lock); -- 2.30.2