{"id":2223486,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2223486/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/261128.1776251770@warthog.procyon.org.uk/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.2/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<261128.1776251770@warthog.procyon.org.uk>","list_archive_url":null,"date":"2026-04-15T11:16:10","name":"netfs: Fix early put of sink folio in netfs_read_gaps()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"02b4ca22d894b95b7d7d73fc5db8e868bda1aaae","submitter":{"id":59,"url":"http://patchwork.ozlabs.org/api/1.2/people/59/?format=json","name":"David Howells","email":"dhowells@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/261128.1776251770@warthog.procyon.org.uk/mbox/","series":[{"id":499973,"url":"http://patchwork.ozlabs.org/api/1.2/series/499973/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=499973","date":"2026-04-15T11:16:10","name":"netfs: Fix early put of sink folio in netfs_read_gaps()","version":1,"mbox":"http://patchwork.ozlabs.org/series/499973/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223486/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223486/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-cifs+bounces-10832-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=BeFL/R0f;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10832-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=\"BeFL/R0f\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=170.10.133.124","smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=redhat.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwdtf55w7z1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 21:18:34 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 7550630EA797\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 11:16:34 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 8886F30ACF6;\n\tWed, 15 Apr 2026 11:16:25 +0000 (UTC)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 228BE3793C1\n\tfor <linux-cifs@vger.kernel.org>; Wed, 15 Apr 2026 11:16:24 +0000 (UTC)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-N87LYPymM8CIPtI7ZtY8Gw-1; Wed,\n 15 Apr 2026 07:16:19 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id D4C8B180057D;\n\tWed, 15 Apr 2026 11:16:16 +0000 (UTC)","from warthog.procyon.org.uk (unknown [10.44.34.160])\n\tby mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 62656180047F;\n\tWed, 15 Apr 2026 11:16:12 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776251785; cv=none;\n b=laKeKSrgOSbmaRsCFQI/bRMzVHwyPZ7wKrAsmZljBj5FoMLOV2+LmB3k4dkSuSomXi9pihUdwFBc5PYSM/Rrla+Rft8oa5wFH49sy5WRT2nAVuyY+rq8wO0Zl6xienx6GunrmDMDJt1QTZ7CGX9FZAHCt3PbxcOwOR4sPALVarA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776251785; c=relaxed/simple;\n\tbh=QvFkj94XYGJ047tpd5sGgOMH/mLcggwIb+6fRq6t5o4=;\n\th=From:To:Cc:Subject:MIME-Version:Content-Type:Date:Message-ID;\n b=aNnetK0V7cMVMBWNCuDehUoVmOuxT3ITKCeS7Vxa+jjx3vXZmL5muOL0OPOgeIR0fQCVlTzda20m0FtyucODBf1KyPAcljdYDbltv7f21hCU5cxkUNDMs473B8pFzbzxGjgTZ8c8OnmwPot7Q0MUbwqhx2s1SgK89LO4Hf4k4tU=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com;\n spf=pass smtp.mailfrom=redhat.com;\n dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=BeFL/R0f; arc=none smtp.client-ip=170.10.133.124","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1776251783;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\t content-transfer-encoding:content-transfer-encoding;\n\tbh=3dqApsnM+P4o09la4I1Tw9Wr5v2SnstRKsAAQ27vRWE=;\n\tb=BeFL/R0fUR92eacC0DWZWUZRu75I3o3/0tk7K9R2Mn987Nmj+pmsWQpTgwdCXv4uf2uWys\n\t0opQHeCjI507g465j+/ZjcrmF49UaHkwz0B1AlaGhRwomAiToJDMK68BsSAvFm1WRsQChj\n\tgL7Pwb29YDaQ0Z9TChgAvqqFe3D9Ubg=","X-MC-Unique":"N87LYPymM8CIPtI7ZtY8Gw-1","X-Mimecast-MFC-AGG-ID":"N87LYPymM8CIPtI7ZtY8Gw_1776251777","Organization":"Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley\n\tPlace, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United\n\tKingdom.\n\tRegistered in England and Wales under Company Registration No. 3798903","From":"David Howells <dhowells@redhat.com>","To":"Christian Brauner <christian@brauner.io>","Cc":"David Howells <dhowells@redhat.com>,\n    Paulo Alcantara <pc@manguebit.org>, netfs@lists.linux.dev,\n    linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org,\n    ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org,\n    linux-kernel@vger.kernel.org, Matthew Wilcox <willy@infradead.org>","Subject":"[PATCH] netfs: Fix early put of sink folio in netfs_read_gaps()","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-ID":"<261127.1776251770.1@warthog.procyon.org.uk>","Content-Transfer-Encoding":"quoted-printable","Date":"Wed, 15 Apr 2026 12:16:10 +0100","Message-ID":"<261128.1776251770@warthog.procyon.org.uk>","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93"},"content":"Fix netfs_read_gaps() to release the sink page it uses after waiting for\nthe request to complete.  The way the sink page is used is that an\nITER_BVEC-class iterator is created that has the gaps from the target folio\nat either end, but has the sink page tiled over the middle so that a single\nread op can fill in both gaps.\n\nThe bug was found by KASAN detecting a UAF on the generic/075 xfstest in\nthe cifsd kernel thread that handles reception of data from the TCP socket:\n\n BUG: KASAN: use-after-free in _copy_to_iter+0x48a/0xa20\n Write of size 885 at addr ffff888107f92000 by task cifsd/1285\n CPU: 2 UID: 0 PID: 1285 Comm: cifsd Not tainted 7.0.0 #6 PREEMPT(lazy)\n Call Trace:\n  dump_stack_lvl+0x5d/0x80\n  print_report+0x17f/0x4f1\n  kasan_report+0x100/0x1e0\n  kasan_check_range+0x10f/0x1e0\n  __asan_memcpy+0x3c/0x60\n  _copy_to_iter+0x48a/0xa20\n  __skb_datagram_iter+0x2c9/0x430\n  skb_copy_datagram_iter+0x6e/0x160\n  tcp_recvmsg_locked+0xce0/0x1130\n  tcp_recvmsg+0xeb/0x300\n  inet_recvmsg+0xcf/0x3a0\n  sock_recvmsg+0xea/0x100\n  cifs_readv_from_socket+0x3a6/0x4d0 [cifs]\n  cifs_read_iter_from_socket+0xdd/0x130 [cifs]\n  cifs_readv_receive+0xaad/0xb10 [cifs]\n  cifs_demultiplex_thread+0x1148/0x1740 [cifs]\n  kthread+0x1cf/0x210\n\nFixes: ee4cdf7ba857 (\"netfs: Speed up buffered reading\")\nReported-by: Steve French <sfrench@samba.org>\nSigned-off-by: David Howells <dhowells@redhat.com>\ncc: Paulo Alcantara <pc@manguebit.org>\ncc: Matthew Wilcox <willy@infradead.org>\ncc: netfs@lists.linux.dev\ncc: linux-fsdevel@vger.kernel.org\n---\n fs/netfs/buffered_read.c |    6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)","diff":"diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c\nindex c23173a061e8..dc50690fdd44 100644\n--- a/fs/netfs/buffered_read.c\n+++ b/fs/netfs/buffered_read.c\n@@ -459,9 +459,6 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)\n \n \tnetfs_read_to_pagecache(rreq, NULL);\n \n-\tif (sink)\n-\t\tfolio_put(sink);\n-\n \tret = netfs_wait_for_read(rreq);\n \tif (ret >= 0) {\n \t\tfolio_detach_private(folio);\n@@ -471,6 +468,9 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)\n \t\tflush_dcache_folio(folio);\n \t\tfolio_mark_uptodate(folio);\n \t}\n+\n+\tif (sink)\n+\t\tfolio_put(sink);\n \tfolio_unlock(folio);\n \tnetfs_put_request(rreq, netfs_rreq_trace_put_return);\n \treturn ret < 0 ? ret : 0;\n","prefixes":[]}