{"id":2229602,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229602/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428131756.922303-18-dhowells@redhat.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/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":""},"msgid":"<20260428131756.922303-18-dhowells@redhat.com>","date":"2026-04-28T13:17:47","name":"[v5,17/24] netfs: Fix early put of sink folio in netfs_read_gaps()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"ad68f0343b90b0c13fcf67c157fe845ccf1ce4d4","submitter":{"id":59,"url":"http://patchwork.ozlabs.org/api/1.1/people/59/?format=json","name":"David Howells","email":"dhowells@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428131756.922303-18-dhowells@redhat.com/mbox/","series":[{"id":501852,"url":"http://patchwork.ozlabs.org/api/1.1/series/501852/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501852","date":"2026-04-28T13:17:35","name":"netfs: Miscellaneous fixes","version":5,"mbox":"http://patchwork.ozlabs.org/series/501852/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229602/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229602/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11202-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=KSanz9Wp;\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-11202-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=\"KSanz9Wp\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=170.10.129.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 4g4hx70Mcnz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 00:03:39 +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 251A9314038C\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 13:27:57 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 936C447DF8C;\n\tTue, 28 Apr 2026 13:19:32 +0000 (UTC)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.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 3ADB247DD6C\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 13:19:30 +0000 (UTC)","from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-KETjkhGDMKu4F8BaFxma3A-1; Tue,\n 28 Apr 2026 09:19:27 -0400","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 0F46F1955F25;\n\tTue, 28 Apr 2026 13:19:25 +0000 (UTC)","from warthog.procyon.org.com (unknown [10.44.32.126])\n\tby mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id CC3251955F21;\n\tTue, 28 Apr 2026 13:19:21 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777382372; cv=none;\n b=il7bTX54tsggaMewGG1xoDs4kHyYJI4qAX24eWaXNJ1KTRAneBtpMXTGxXLq9+mw2SqMtBhv92jOpCkf5cSG6cqHF67YYxXUwbIFoQgIfDpC6mbeSaKSAOYu2QIqTix4M6QJvjl9BkFXJIwp2sowUlA8su9asvsok11JGNzrqAk=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777382372; c=relaxed/simple;\n\tbh=J6xbkiUXEBxqGua30Ly2BO3cTSDIQVPMlA1JsgMbaAg=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=e262ga+ucg4QSYQH/eRG2MF+N6AUlHviRksa+JMY6FhnGDluOnMXFQG91Q68yx3/wAbnRR7h3VMxh80ABUmKAlkg0rd67UxesahYdBu/DIPq40dH5FRizdUNiCeOekJRp1+murA0ntSjHbQSWOBXdR5lfsSZDDqARmbVPEL+AJo=","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=KSanz9Wp; arc=none smtp.client-ip=170.10.129.124","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1777382369;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=zPw8vG2tI8x7LyUiAgQo8fFB7ZuQxgP71N5NQ3zP9Ok=;\n\tb=KSanz9Wp+A9ypRMVQM6BulZHNRXdwDEsR23r6pOQ6HZ2QC1ErSakf6vyJPrUE7Icbu2Zbl\n\tDqnZVne6AXydq9fMAt/YHfFjF3WzU7K5udTkRnQndM4NdMVJBUWrI9ylsQooFIh8oz6+zA\n\t2tvbw/hZy2CA7U/YwUoWaKf4GM6SDkY=","X-MC-Unique":"KETjkhGDMKu4F8BaFxma3A-1","X-Mimecast-MFC-AGG-ID":"KETjkhGDMKu4F8BaFxma3A_1777382365","From":"David Howells <dhowells@redhat.com>","To":"Christian Brauner <christian@brauner.io>","Cc":"David Howells <dhowells@redhat.com>,\n\tPaulo Alcantara <pc@manguebit.org>,\n\tnetfs@lists.linux.dev,\n\tlinux-afs@lists.infradead.org,\n\tlinux-cifs@vger.kernel.org,\n\tceph-devel@vger.kernel.org,\n\tlinux-fsdevel@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tSteve French <sfrench@samba.org>,\n\tMatthew Wilcox <willy@infradead.org>","Subject":"[PATCH v5 17/24] netfs: Fix early put of sink folio in\n netfs_read_gaps()","Date":"Tue, 28 Apr 2026 14:17:47 +0100","Message-ID":"<20260428131756.922303-18-dhowells@redhat.com>","In-Reply-To":"<20260428131756.922303-1-dhowells@redhat.com>","References":"<20260428131756.922303-1-dhowells@redhat.com>","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-Transfer-Encoding":"8bit","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12"},"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>\nReviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>\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 c0a7f9e60f0c..18c8e00626c9 100644\n--- a/fs/netfs/buffered_read.c\n+++ b/fs/netfs/buffered_read.c\n@@ -457,9 +457,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\tif (group)\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":["v5","17/24"]}