From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24908C44501 for ; Thu, 16 Jul 2026 10:33:59 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4h18Xj4g1Jz3bdq; Thu, 16 Jul 2026 20:33:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1784198037; cv=none; b=WECkQaHj0iYUN41r9PxF4dZn3O/KyxRGWbwTiXXLJbDS4caOfd7bIAgysazxdOnykbPcjQFlTtKtAsA5kdy1TyMod/TMFuKpo9POx9iu7c36X8pZXNvb4wL8OwVWYSQxl2YQAGOP4WBT7eDCVlfvnoGH/3wqcsroGC9sElXK/Hi6FIcTBzSJfpiXPGf3b4l1z/+dx2DKfN5rs8gCn65tHFidyc1/AMYAIHTi36ocIm2G2PNVIXmQiVv+CXIxFkls6x+DCHpy1Ym/q+Jec/t2BlOqoXt3s7y3DCkb/eAulVhUG6zPtPE0MRXffY0T6Mskr1VDRJ0/RnZHRsvGhWP3aQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1784198037; c=relaxed/relaxed; bh=Jan3vghf2Vc14x+82r17g0Y0sRBDaUkg2ZVqVnQ4LUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=fu8VpT9py9K4Rj6v8kpKFu8ijcnoO1856cYYWXVNhyZT8fda1vv5wkP6yj31hiS7OR0FYtyh6jQR5LyeKMGiNgjYvGqnBzVo8/PzoWBzOoD+DkoClRyxrOuYch+25YXfflCLW0fZXy0aMF+kxn4bLcDTJU60VbMZy4jndiKWGesktcttyNrAt5rDJWtBsNUfaQYRc0QduymjK2awftB6Hzz0WF94fupjz17MulUI65xEiq0bTPM9FZzlfh7n2GyWdIg8FbmwyDEARbmQuPDg8FEEQDw8SjPum0CzrOg34EZkjz76cgiBlGymxb54O1Lb5SXA9hWlUnfricJtkNwFtw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjtQpJnA; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjtQpJnA; dkim-atps=neutral; spf=permerror (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=dhowells@redhat.com; receiver=lists.ozlabs.org) smtp.mailfrom=redhat.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjtQpJnA; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjtQpJnA; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=permerror (SPF Permanent Error: Void lookup limit of 2 exceeded) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=dhowells@redhat.com; receiver=lists.ozlabs.org) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4h18Xh5D3Lz2y8F for ; Thu, 16 Jul 2026 20:33:56 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784198034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jan3vghf2Vc14x+82r17g0Y0sRBDaUkg2ZVqVnQ4LUA=; b=gjtQpJnAhgqaUUjCRUXxzpokkKyoaMHM3CjTNSBc8RJN6OjDxFl+/oaBh/tJlhkBE0NEKz TbCIm3xmIS0HiVRuumTDCaJEMwOsPZKlY9xgyIfLj76UZyGVqeQDFmjaW+AZIxRBg9iZ5a 6qhuPbo7oSME4IKaiYkeEEQmJOOFGYE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784198034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jan3vghf2Vc14x+82r17g0Y0sRBDaUkg2ZVqVnQ4LUA=; b=gjtQpJnAhgqaUUjCRUXxzpokkKyoaMHM3CjTNSBc8RJN6OjDxFl+/oaBh/tJlhkBE0NEKz TbCIm3xmIS0HiVRuumTDCaJEMwOsPZKlY9xgyIfLj76UZyGVqeQDFmjaW+AZIxRBg9iZ5a 6qhuPbo7oSME4IKaiYkeEEQmJOOFGYE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-VDNIchY6NA-h5FEKwBGzqQ-1; Thu, 16 Jul 2026 06:33:49 -0400 X-MC-Unique: VDNIchY6NA-h5FEKwBGzqQ-1 X-Mimecast-MFC-AGG-ID: VDNIchY6NA-h5FEKwBGzqQ_1784198027 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03A1A1956067; Thu, 16 Jul 2026 10:33:47 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.44.33.159]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 218B4424; Thu, 16 Jul 2026 10:33:40 +0000 (UTC) From: David Howells To: Christian Brauner , Matthew Wilcox , Christoph Hellwig Cc: David Howells , Paulo Alcantara , Jens Axboe , Leon Romanovsky , Steve French , ChenXiaoSong , Marc Dionne , Stefan Metzmacher , Eric Van Hensbergen , Dominique Martinet , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 22/24] netfs: Check for too much data being read Date: Thu, 16 Jul 2026 11:30:21 +0100 Message-ID: <20260716103030.3065561-23-dhowells@redhat.com> In-Reply-To: <20260716103030.3065561-1-dhowells@redhat.com> References: <20260716103030.3065561-1-dhowells@redhat.com> X-Mailing-List: linux-erofs@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-MFC-PROC-ID: kJ5dWzNWaOCHcY3Xs-S7apPKGPkqYiogv7kHRAJu604_1784198027 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Put in a check in read subreq termination to detect more data being read for a subrequest than was requested. Signed-off-by: David Howells cc: Paulo Alcantara cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/read_collect.c | 18 ++++++++++++++++++ include/trace/events/netfs.h | 1 + 2 files changed, 19 insertions(+) diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c index 802d1c40cce5..c0170f80d67f 100644 --- a/fs/netfs/read_collect.c +++ b/fs/netfs/read_collect.c @@ -227,6 +227,8 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) notes |= HIT_PENDING; smp_rmb(); /* Read counters after IN_PROGRESS flag. */ transferred = READ_ONCE(front->transferred); + if (transferred > front->len) + transferred = front->len; /* If we can now collect the next folio, do so. We don't want * to defer this as we have to decide whether we need to copy @@ -543,6 +545,22 @@ void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq) break; } + /* If the subrequest read more than it was supposed to, abort + * the request with EIO as we may have clobbered other parts + * of the buffer that are already read. + */ + if (subreq->transferred > subreq->len) { + trace_netfs_sreq(subreq, netfs_sreq_trace_too_much); + __set_bit(NETFS_SREQ_FAILED, &subreq->flags); + __clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); + subreq->transferred = 0; + subreq->error = -EIO; + trace_netfs_failure(rreq, subreq, subreq->error, netfs_fail_read); + trace_netfs_rreq(rreq, netfs_rreq_trace_set_pause); + set_bit(NETFS_RREQ_PAUSE, &rreq->flags); + goto skip_error_checks; + } + /* Deal with retry requests, short reads and errors. If we retry * but don't make progress, we abandon the attempt. */ diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h index 071d20e80f13..723cb7315308 100644 --- a/include/trace/events/netfs.h +++ b/include/trace/events/netfs.h @@ -132,6 +132,7 @@ EM(netfs_sreq_trace_submit, "SUBMT") \ EM(netfs_sreq_trace_superfluous, "SPRFL") \ EM(netfs_sreq_trace_terminated, "TERM ") \ + EM(netfs_sreq_trace_too_much, "!TOOM") \ EM(netfs_sreq_trace_wait_for, "_WAIT") \ EM(netfs_sreq_trace_write, "WRITE") \ EM(netfs_sreq_trace_write_skip, "SKIP ") \