From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179169; b=O9Fxs8DqY3otr9V7B6BPY7WT7OZU4gQ6rpmjPUMoBp5ZH3/iCwmeHrL53HAdAJQlUgNO N1ICGzUhuSOcmoW7HZGhKg147dG+61SBvHUhGL86UVd2qm6le6IuuTyyBwd2i5+akX9m1 o9k4QFeKOLERJNJ8qkMjvbM6tx7GSPpxDUbjKR8/Fqr6HX3LqaR7E/zXk+dTNp/COB7xG ACGG53n9h9PBL8AkIHYekqo5gHc040OFrXl9/mzdubAi0/ob/3epukit36WWFJMCPCdIz E0Riln8Wbk34ljWw4FudeuK68AUtWiFnqmUbM6ylaHQO6YQsClUid/d20kQMXcLiqQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179169; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=uYM6bE3hfstdDWUjpvRSDQ+mOPm6FPie6rLt8UvL9Ag=; b=NXlGj2HpBJSGsFxtUEup+ZkYFo4xN31GrehqM+9Ob5IjGa/A5//taflcDWTQungfPlEB 3ek1h6iAvMgt9kwJHWh2/Zk0mDndf9MTn2exVwZ/7erEOoq9VzLahpAtC+6k1H8ChxSXG RMxENOQOLzaLg0z5onX6rvZpua+blwGSEdK7QluGKz5FwPKS26WW2T9w2c1G4bxy5DyIy 36dKfqxWPS2ovXYWPqr3iPo6SerT6gIoKXoj7LoNA1x/k2xm1ChOLW4RSuzoQuIYKz97j jZ/rh3AuGWWDS/J/w93oJjRA0tR+VxCda+Oj/9WX8fNCebdVZGvx00R7NNGlBJdtpgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=kEv1hb89; arc=none smtp.remote-ip=209.85.216.71 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EBC560A2602 for ; Wed, 2 Dec 2026 02:39:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8EBC560A2602 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=kEv1hb89 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-3ae19907a31so12436239a91.0 for ; Tue, 01 Dec 2026 18:39:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179169; x=1796783969; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uYM6bE3hfstdDWUjpvRSDQ+mOPm6FPie6rLt8UvL9Ag=; b=kEv1hb896QzyA4eKxU1WvnOtzonCkmLbyv6pXol1jmybxkmVPfarplHii3MjdlDD9h 1QsgYP7Qr2k3qIGhNC2wZHxrxSwcpusYG8n0jbDDijqG/w4cYuvmyLkvnMrRY26suRj0 +OOT9xU+O0MLZi0uWgW+imTjOg9vASdzRGjszEeRurkoqO5aonwk9VG9LhZLxBby8C75 +cLuXp178ob7WkKc1zhZ9bYIgCQhNfOMbHp4SjF5sgXYelL5rs67h+RrtesriGY6mhPD b206QzccbOWZCsVRNF34jc7hlE2dCibU8tmojvo/HxEdFJP99cUSSKaLCbJdn3Q76pMu Q9dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179169; x=1796783969; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uYM6bE3hfstdDWUjpvRSDQ+mOPm6FPie6rLt8UvL9Ag=; b=H34dLW5DwbPdhmi/x1MfOUaT0encSZxkjr/LmPcFt/cX08mz0BoINNP6ldAqI98gxT gBfuzTT94JMWNdImth5CqMKzbuI9A2fBo/qGkGIxRs1AjHFEy7kEALRHMgzOeTC1LuP6 xQ7qGTA6YeQ3/uNQgsnshcLjvrXS+/+HTsxHAZl2LCVUkFTQtZGTyJrAIZO2NBcDSPiX 3lKLcfxqRTnpzYG79oyUVYKa8cltymKN5tyupeEPWJ0Da1WoEmX/WZNUmqKuZg7vOHzG De/FYZlQ/vV6I9n12Oevp9mBaUdCScE7lvEE/J8/mwNgEMj9Kn0LCpQFPso0rD0Q90QM +R2Q== X-Forwarded-Encrypted: i=1; AL+hErEPeucnUDcdX2aYEdRZa/1DW6trb7OhdTO6Ax0kjL9z6NEJn3harm3kDAKqFzmmpQohfb7hLMTfynBX3qnR@vger.kernel.org X-Gm-Message-State: APuU4Z/mtNCt1R53Wc9iOzZ2SHvqCSBaHJfI1vqAZ/jgw017P1W9/hN5 ayw8ftsegStNTbzIpU/UKeWLO3Gymxbw7htOCMoUkqQQfz1GHkY5+h10tfVQT3K5753I2CkQBNi A7zlf9MPrz1gDHPDs2Tmy2g== X-Received: from pjbov16.prod.google.com ([2002:a17:90b:2590:b0:3b4:c0b:389d]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3e81:b0:3a8:337d:228a with SMTP id 98e67ed59e1d1-3b41c7bc57cmr25880218a91.6.1796179168402; Tue, 01 Dec 2026 18:39:28 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:09 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202023920.595207-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202023920.595207-3-jthoughton@google.com> Subject: [PATCH v2 02/12] btrfs: Don't copy encoded read data to user memory when canceled From: James Houghton To: Andrew Morton , Alexander Viro , Arnd Bergmann Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , David Hildenbrand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Madhavan Srinivasan , Chris Zankel , Max Filippov , Dinh Nguyen , Simon Schuster , David Sterba , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , KP Singh , Matt Bobrowski , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Steven Rostedt , Masami Hiramatsu , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" btrfs_uring_read_finished() copies the data of an io_uring encoded read to the submitter's buffers with copy_page_to_iter(). It runs as io_uring task work, but io_uring may also run it with tw.cancel set from other contexts when the submitting task can't run it: from a kworker when the submitting task has exited (io_tctx_fallback_work()), or from io_cancel_local_task_work() when a DEFER_TASKRUN ring is torn down. In a kworker, current->mm is NULL, and the copy does not reliably fail: the user half of the address space belongs to whatever mm happens to be lazily loaded, if any, so the data may be written into an unrelated process. Don't copy the data when the task work is canceled, and complete the command with -ECANCELED. Fixes: 34310c442e17 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)") Reviewed-by: Jens Axboe Signed-off-by: James Houghton --- fs/btrfs/ioctl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index ba239d0d1a6d..51ac911c8afd 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4633,6 +4633,16 @@ static void btrfs_uring_read_finished(struct io_tw_req tw_req, io_tw_token_t tw) goto out; } + /* + * If the request is being canceled, e.g. because the submitting task + * has exited, this may run from a kworker or in a different task, so + * don't copy the data to the submitter's buffers. + */ + if (unlikely(tw.cancel)) { + ret = -ECANCELED; + goto out; + } + if (priv->compressed) { index = 0; page_offset = 0; -- 2.56.1.911.g883d8bcb20-goog