Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2350905pxb; Mon, 20 Sep 2021 19:46:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEz5Gk/MAqxEM9tBNWi3ahZECQFK7NWGc1EQVVlHh3vbsYDTOzQac6e0avFT/U+Xji9+6Q X-Received: by 2002:a17:907:3e05:: with SMTP id hp5mr31772695ejc.527.1632192384576; Mon, 20 Sep 2021 19:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192384; cv=none; d=google.com; s=arc-20160816; b=m/OD/OSwFsunF/wXxG6z6tGlE2y+VhF265YpvC8w2P1VQyFj5p8YfY/MBuZzltSb6j kmUHsKWh37fG4GWdTewv7K8DG+mLsbVrT/q3i59EB5LPFk8rRoeT2Z7qOnJgYmefQWqt mdL34wOSgT2o/sFmP/48mR2e+J8yYWscvLuzu4nCpBrCCF3vGPkhoc1hAKxxUlgLpSnN T5WHeqW1QTKVlxasFW6gmEM0ndZbh2H8Dy57Fn++4RogENwNUJkCweu1d3Id8izTVpNS 49UcpRefSYum9EO0SXtbRMlU2gds9HnbWKYVNPp6RlXv3DAEK0Uq65RbC9t6BcwJs+1u lt4A== 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=KGTusWRlNqxFel0D2/n3vU1ILNQw8YxACm4U76ln/SA=; b=JikVv9E/1rTIoEerW0aKfVbVyhnyQzVgAWytH0msezDnaB/91d84QciNSPRTc6Jvm0 6lMl+QQjk6FB9XqgXNRhNrgdKiYvzFaEACtDrfCPzxA1+YZP9jUSVNZ+8blq8Dp7aCIi 4q+3yRUHh9EkdNruRu8gtXmHHeDXtV6s6pXFc4fQEHjEgmGUQZ8e7jTMkfFjpWntN/EG XTnBOmr8RE0oQAqd7T7Qcs4eEEbZAjVCKy6oG6uS3PMBFh5F0qqipRPvA/1q7A99KfzA F+CappNsei+rqEuK+hJASJiGOkbI1X2xsp5xnau6sNxO9KjXu5oQfA4ewfpp9/KHTOyn SdFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CeqZSUeD; 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 16si11259243ejf.233.2021.09.20.19.46.00; Mon, 20 Sep 2021 19:46:24 -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=CeqZSUeD; 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 S1378869AbhITS0v (ORCPT + 99 others); Mon, 20 Sep 2021 14:26:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377693AbhITSUT (ORCPT ); Mon, 20 Sep 2021 14:20:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B65D632AA; Mon, 20 Sep 2021 17:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158610; bh=t2iXuvRApkXkndxKEFV8qBh7oCRTavfhVfmUtTDE7LU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CeqZSUeDrk+lxF243lVVkSTdIgTib5rbGTYvn1qsjD44l8rM73+u6mvTAmylD/W5M fFCZ3KUcwGO0dDyXhqehn/qLU2rUiXvN01YMQi9gnvAFVyGDtWd8meIWTsMFUjU035 97RJBgewkRAnPY610agz2g//isJnwYX/hw+FTt2Y= 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.4 236/260] fuse: fix use after free in fuse_read_interrupt() Date: Mon, 20 Sep 2021 18:44:14 +0200 Message-Id: <20210920163939.145541437@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 16aa55b73ccf..7205a89fbb5f 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -282,10 +282,10 @@ void fuse_request_end(struct fuse_conn *fc, 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