Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353811pxb; Mon, 20 Sep 2021 19:52:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiZmsgs9GaPDxPfbB1G3qVF1NQQisQtTS5nppGonct/bFtLAqEiAbiQwaqzH6D+EY7zxTu X-Received: by 2002:a05:6638:339e:: with SMTP id h30mr15539737jav.148.1632192757688; Mon, 20 Sep 2021 19:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192757; cv=none; d=google.com; s=arc-20160816; b=F6mk8hk8ntzTZxtIWCdNCquCHj2LfY1D4vowkbdzscGhq6d34NhcCeF/rQgJZsyW79 lw4bdkCmJC+3zbVQz/r74Zq/E/h86grANxmcHGjGN4YNl7E0XNKWTVrHR7HxRXJtP3dH JPq2UOLmTLW88C/nh4v0LIgIbv2RoiXSNQyUAZ453ig6WJFpND316oy2ZFMnyALKfVwS qzc6c6usrlo18xWF2jI+eVtwpXsZhoMyMzrNzZNPsPwKRFKAuaLCEpoZlQO7hzuIBDN+ /x0eyuiT1Ar/NGkfo/LbcU+IIMP02CldZcFyxEXtTCb3Yviucvou7qVJAz3RP6Xj20PR zkvQ== 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=Z9pqic25MXa3ximy2pXoYcGB1kxi9nkHnZff4xH/GfA=; b=BfgyVxzNiENN19VxaejJ/QV3faGrVx+ZIpO1XsrKMwI/CqIhC0P8bb5LnOSlq3EZ4c m//Ho7TX/G+2FBU+P+GcspcC/HHHqLExtACKMez3iNTrYgrjnq5bSu48YNi71DT7qbV1 VSR3UIK29DHoGQ9Zm/2D+9nV+tmEC8AozTrjsJnE/jZLJg1D8PwDDUVzOO5WDOgkcAdO EdeX+MHZJSBj6I052c4CGhBTvI96NXDuirVNy2ycvqa6P/kTgUgxSmqyzEuFWHe9qMMh vyYh4vFYIp04H+jT7exmYHScgrVXvA5EjyD5MkDxsf2fVw/35RCazib9Whu5NR5hhMLT KK1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l3QilqJP; 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 l2si9736774iln.84.2021.09.20.19.52.26; Mon, 20 Sep 2021 19:52:37 -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=l3QilqJP; 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 S1354209AbhITSrp (ORCPT + 99 others); Mon, 20 Sep 2021 14:47:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:56448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383233AbhITSoR (ORCPT ); Mon, 20 Sep 2021 14:44:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AA8D963353; Mon, 20 Sep 2021 17:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159142; bh=hG+7UnzuY21Kf9pUuVV2XycR5F+kwOT2KtokM/cSP+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3QilqJP44B77ZUiSDxs5IlNVdXo0f0/ghiJBGe47mvp/5pM1kc3gdBke/c39dKSR MY95M9LqhBGIb46KRngaJCtRWkjj3eGCWdhxLmke1d+juA0GltIx5aVsPiJVgj85Jl l35lJg7ofWrwecCqxeU7jyvb6B28xfPRU0V+lxXM= 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.14 094/168] fuse: fix use after free in fuse_read_interrupt() Date: Mon, 20 Sep 2021 18:43:52 +0200 Message-Id: <20210920163924.721426651@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 1c8f79b3dd06..dde341a6388a 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