From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179170; b=4bQqNVKzTLsjQIfb6SfpfzOE4joyyeAL7gF7NTYO77eI3xA+/mysIpjmCzGGGsUyDNR4 Ntfs7xmrdFA2+PD7I4Lf/mPS70oDgLki2u9BRoUXBvbDB1VPH1qlBuVld733+IuLTvq4X oqnCu/EVArOPFzCaYgE2tOD4SmlSWtEMkepscsSGfeC6nZ5de3hwXb5//V6xpduWr09TP coiWVg5VTj0b1vjKO3Xg+4XTBSoOFnhVHWZbCYlP9hp8Ry6AHaJ+rXVC4VksU8Dw9rFRq dotVcghcDS/kGA+Vj6M0Qk+JLTZ14flkG4AoSaOX3bCwjUCtAaIUnYhnZ+Jd/Ac3UHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179170; 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=OSut/5oPJFuxLcxNpHZ5K+LPojFfV0mXgLPZhQ/qk0EEnW7MsbW44IXOZB09uXqBauvW OyJqYtTo/4co5MFuO9wVyFQ1Vp2WW7L8T4NPRBjtL+urP6MR9qtGhJLiWJ2+ObGu7loQT 1mFXv3dda6kxmKvKjHb/KI0G/sCG2GuFzcnZC7iAR0fhJKqWID3z6+PBE7plmmWky+4MH Tk9BpuIXD7l889yg+0DAa4wycK3Lw26UEIjWVTbgpWP1rqH6vLrqrH7PpMb1OwOJNQ6/6 CQXNxnjtforw1ac87y5gKd4lcjBhye1B8wmSIxeqbVMgTlrrWrruzfd6ODTJ6nyuBVQ== 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.70 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 9422D60A2606 for ; Wed, 2 Dec 2026 02:39:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9422D60A2606 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-f70.google.com with SMTP id 98e67ed59e1d1-3b3b4208826so8935155a91.1 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=bx04MBzqWzhrg7u7kto8deyszKITiDMubx4tZBMABvPspF/m6J7naBjCwQISdNTTa6 hyIxCc1yFF+cwJ3zPZjiFekfTBx3QPS9y970rIKB4iVrdV4eLub2wFqKDXhKlvzTvrSg xlMOMMK7NrI7bnEOgteM8TluPyjv4JjG0gO60PBGNVUvEKpOybkLQ+F1AGJt8H4PaZLd X8Qkye9+JGYu9nLTbH0TKdKi6vAAM8m7umLGSuHuvJkYVCzhUlYcETH5T4unbxXZXVtj LBQ0GHC61aL0JHo0QYu3e8Tw2oyKUZSl+QmFxU26fO0x+le9IE+nx7Yzg7HfwKggzOPp VJdg== X-Forwarded-Encrypted: i=1; AL+hErFTJ3BEVA48Kc1yI8C5eN5pLxL2g60/Wj7n40iWlOkpJfsq03vPOYLieEBZlhQ/6DCXR0sqn3LXswiyRRI=@vger.kernel.org X-Gm-Message-State: APuU4Z/WvWYdQR2gfH6/ho6qrqqT0cStKt10b4s8Kt5iMBof0qZEZYE8 /tq/Ken6aEkekfu/RlZXq6jBxxqqU9BCKqWK2mtYm2ubZ3gd4xln9eA18bVzIAwvccOMtglel20 mJyCibwhVMzzmBY3jb37k2g== 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-kernel@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