From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC5953EDE7A for ; Tue, 4 Aug 2026 09:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835102; cv=none; b=MExR3qReLjV1cmS4QWiVaxa+IKDuE4YB3GYK0YX18lTDeAQ7pOQLtpG0tzyiCMhgvLQYiQXpK69v3Z+9NX8jCw8k93GGcGZamrkc79DjgH583QWkvPNBetsj7iIHSd0trR4xehZoM0Er9j/aBvjoizhFJHQINziBXYOhwtFCR5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835102; c=relaxed/simple; bh=+JfP1gbbEZxAYpS9FbypkcJck3cynRxZRgE5Qr05GrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=blnMW150njHZNVYe7F3bATSHuRSESrDriGIwmNikknVDHHhzM/0ceU3eZGlNFJymmOu9/YqX+h2MeJvTr4wKYIVssu0dv+Kufg1lSoOAcjkhBTYaBLVO5+NW3FOdVmVAfnm3s15xRyFu+9WDjJPNBq78Bb+Q+5he7NP4bAXPHHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h+c2Uy1g; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h+c2Uy1g" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2ceb096e675so51371835ad.0 for ; Tue, 04 Aug 2026 02:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785835100; x=1786439900; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M6DADmIX820j0VkQtSmHS96HmvLl3nEhITSRy3Q0IpM=; b=h+c2Uy1g9Jm3lscS8az7oBABC9VsRw7DKH3S/huSgvO5iPUQ32Pa2J53OApJ/RNKni n2rrZFHHRq62HApuagrbK6Ox7g5JPSD1FNGJgY89wWJ14hvNv/0Pe/bYj1SCdNNT33cC zjrS6kLWCxlLYi4NEN6iOI9BUxWdYEvg0VZOXWRqpRC3saQqkbuCdP1HTJ75nLfDbwGJ DErGoIR/PWdnI8rSOovjaSYLON1+lYYyOwxorenBWOdYQesQw8RDO5v9qr/tFUDDSnVo 020w/R7DrgqzoI5ejFpBBgW4zqiyJv8KzSJ7oJSZ/hSDyKrqBAjmtP+OGsOSVFlsas7E j8hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785835100; x=1786439900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=M6DADmIX820j0VkQtSmHS96HmvLl3nEhITSRy3Q0IpM=; b=fR8c8kr9g368Ne/8IyFv43cPIbBhEBQARGqwmxNsMJ6D0ytyYm6GmTNBhw9d/O5HjP wJOXQ4Q99RMJLRJtF7NCoiW2YvW+vsBv5R2ROPOtV7j8HNtg5SyFt4ZpIfsF9PqddgI2 QX5Xz5hIZ+XGaYSHkUx69gJCEOvBbV0UhiaiNZkyzjWwhU+wuFtFWZ0tNfl2tTy/A5Gg mj0Ei6XbyeOxx9QLQDfrhw7FrBNLg/BLw+ECaXUrERImwpYkt9LLTEMVVzDHvBiHXoQn YiAlQcT9gA0f3YQorQXM8WXIBNEag7yajXJ32WYZ5Oh2MkuVDR0aBiWP4cDyRYC8JLd9 Sn9w== X-Forwarded-Encrypted: i=1; AHgh+Ro57ARlYhodrRQ4tZt/W2gvwVu/7CgF0Gr+8bzglK9fxOUPnsl7jSCAq7ds1m198IdPzYi7h0TSj6k6wvA=@vger.kernel.org X-Gm-Message-State: AOJu0YwP8DdEeE6sj5tizd7bmj3LoxNAKGAjE/Gp864Od8e9ZjYEMyTu EPzXrroTu2d6FkhGqzC9u7G0CJeaShjsYOsyRXtu+S3aVDwM9eQ/RveC X-Gm-Gg: AR+sD104ZiayppAUkmaPk5X5O8gTSqfGNtUQIWQbQ2wdRNvjwZ1myTgxYXH8L06xgto FOyA5I0Kkb/626mRBLqsu/KEeNn0fwz3UAfe1Xk6qpclMItyQoMqf8flWzJ3MlRyt7SyCasXNKI 6DYpQ5ljzWU5kQ7ZCVczEErGaUeSPY2kQImGfPj5gwExSViwGB/8sFxJ5Ey/+nvXsYlDQ8tG0LO X/qiITZV9RRyLjeng70ftit5Rix/zmW1Rqps1kejZIK9RhXZ9BKrjj0qsBuZiyUeWd5yOElcHDe 67g+Obi2YXHhzHVLNoZdzZQN+8YWVlKicpsT/PUoo3siSKWpazSR0uvcV8c8J+oE3rDK61s0cxH mx8O/PRzSwYVA9ldJe1n0ojS6pDPeo2+Uxls6TMn/MaNRywKGm6CiPsMtDPB569ocuOGV/J872V /XG8jPV69JhPVSB6BlwGJDNcyj8BkOZXZUOHmC81xcHV/vLkRO+l3Km9NpxtFUOxU= X-Received: by 2002:a17:903:2f03:b0:2cc:f7c6:8320 with SMTP id d9443c01a7336-2d052416431mr133850745ad.46.1785835099883; Tue, 04 Aug 2026 02:18:19 -0700 (PDT) Received: from TENCENT64.site ([103.7.29.106]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d0a9f8fee7sm3681065ad.16.2026.08.04.02.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 02:18:19 -0700 (PDT) From: Jun Yang X-Google-Original-From: Jun Yang To: Miklos Szeredi , fuse-devel@lists.linux.dev Cc: Zhao Chen , linux-kernel@vger.kernel.org, Jun Yang , stable@kernel.org, TencentOS Corvus AI Subject: [PATCH 1/2] fuse: set FR_PENDING under fiq->lock in fuse_chan_resend() Date: Tue, 4 Aug 2026 17:17:08 +0800 Message-ID: <20260804091757.503476-2-junvyyang@tencent.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260804091757.503476-1-junvyyang@tencent.com> References: <20260804091757.503476-1-junvyyang@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit FR_PENDING means "queued on fiq->pending, protected by fiq->lock". It is the sole predicate fuse_remove_pending_req() uses to unlink a request and drop the queue's reference. fuse_chan_resend() breaks that invariant. It splices every fpq->processing list onto a stack-local to_queue and drops fch->lock, then sets FR_PENDING on each request while holding no lock at all. From that moment the request advertises "I am on fiq->pending" while it is in fact reachable only through the caller's stack. A waiter whose wait is interrupted takes fiq->lock, sees FR_PENDING, unlinks the request from to_queue and drops its reference, and fuse_chan_send() then drops the last one -- so the request can be released while fuse_chan_resend() is still iterating over it. fiq->lock serialises nothing here, because the request is not on an fiq-protected list. fuse_chan_resend() then walks that same list, and on the !fiq->connected path it drops fiq->lock and walks it with a non-safe list_for_each_entry(). Publish FR_PENDING under fiq->lock, immediately before the splice that actually puts the requests on fiq->pending, and fold the intr_entry cleanup into the same locked walk. A waiter that arrives while the requests are still on the stack now sees FR_PENDING clear, so fuse_remove_pending_req() returns false and it falls through to wait_event(FR_FINISHED) -- the same handling a request already handed to userspace gets. The !fiq->connected path no longer needs to clear the bit, because it was never set. Confirmed on v7.2-rc6 (075b74841bd0). Fixes: 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI Assisted-by: tencentos-corvus-ai:kimi-k3 Signed-off-by: Jun Yang --- A KASAN reproducer for this issue is available if requested. fs/fuse/dev.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 5763a7cd3b37..e62c7ed8bcf4 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1781,26 +1781,22 @@ void fuse_chan_resend(struct fuse_chan *fch) } spin_unlock(&fch->lock); - list_for_each_entry_safe(req, next, &to_queue, list) { - set_bit(FR_PENDING, &req->flags); - clear_bit(FR_SENT, &req->flags); - /* mark the request as resend request */ - req->in.h.unique |= FUSE_UNIQUE_RESEND; - } - spin_lock(&fiq->lock); if (!fiq->connected) { spin_unlock(&fiq->lock); - list_for_each_entry(req, &to_queue, list) - clear_bit(FR_PENDING, &req->flags); fuse_dev_end_requests(&to_queue); return; } - /* - * Remove interrupt entries for resent requests to prevent stale - * intr_entry on fiq->interrupts after the request is re-queued. - */ - list_for_each_entry(req, &to_queue, list) { + list_for_each_entry_safe(req, next, &to_queue, list) { + /* must be set under fiq->lock, see fuse_remove_pending_req() */ + set_bit(FR_PENDING, &req->flags); + clear_bit(FR_SENT, &req->flags); + /* mark the request as resend request */ + req->in.h.unique |= FUSE_UNIQUE_RESEND; + /* + * Remove interrupt entries for resent requests to prevent stale + * intr_entry on fiq->interrupts after the request is re-queued. + */ if (test_bit(FR_INTERRUPTED, &req->flags)) list_del_init(&req->intr_entry); } -- 2.43.7