Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp6032405rwe; Tue, 18 Apr 2023 15:46:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YisTD19adw+3EENroiNQwvo9yB08Hkrn1xUknsN50VHMEUE5+FezKVMgCg/s4SlSTRPNab X-Received: by 2002:a05:6a20:258f:b0:f0:df6b:d233 with SMTP id k15-20020a056a20258f00b000f0df6bd233mr1401718pzd.4.1681857960091; Tue, 18 Apr 2023 15:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681857960; cv=none; d=google.com; s=arc-20160816; b=eOJd1WPQAvMEMKxu5P+rzvZJ0MEq7UHjyVlUD2nTHhj4SHy3mgGf1lyZHcR9oArkSN hMwdqj50HFLv/Y6LtObIZc9YxRXgGliF8Co/+Y7kOeVI/yzJYdZkErsHXS/57A38b3fU pZbeumlUHJpCERqLq1YLb+5gQcjBXqXsCD1dvsP8cf/n6P6SoNI/vSNaicwvS1lwKww/ qX9uYDz21HCbfv9dVVoL6lCzfMdEscSfv3asprXwJt8FyhyF7oaBrsooZFTRE4QVlbPF TMFWWwM5IovGVS5qynJwiWcjf6IOqWhIdYBjAUoYL2TbLT0GTCA40LzF5IYSYK89sQZx Tlvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :mime-version:subject:cc:to:from:organization:dkim-signature; bh=88WLzUQfui8MOyB5NEFokobl+41u8GpMubwgrVgH7UQ=; b=Key604vaZq0ALQDEaYcC5cL6QrGxRh3ndtvmrIIzUPBJ2owkgKHuwVsRJx0QyGzGdf CstFQLetrdrdSPlvUFgvJy/v/SYeQDYff8HNIaRVX6cOFYMzdHKK3oZc5G09PTzP/nkn DYukFuFvXTuvkJqsasjBsFdACyAUwNyJ4eoQ7LtCCCZNAQgVXIQgC0C90lLMcw2bd1Vr zz8gmO3TrrbYEN08SsxhFV8T3i7xIwwJVMNAjEDKL0KbjFA4T1yeghSC5mTsBjyxxJ8P M9ADkl6xaDF4Eo1ZmoAIEqMjWWqDK1uyFpbPyXYvzaPwH7u9Tm4AS7oqZLbfZ/j6mOfR ttog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q+iR+24o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a630f54000000b0051393805ccesi14928957pgp.418.2023.04.18.15.45.45; Tue, 18 Apr 2023 15:46:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q+iR+24o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232763AbjDRWlW (ORCPT + 99 others); Tue, 18 Apr 2023 18:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232796AbjDRWlN (ORCPT ); Tue, 18 Apr 2023 18:41:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBB78A248 for ; Tue, 18 Apr 2023 15:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681857615; 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; bh=88WLzUQfui8MOyB5NEFokobl+41u8GpMubwgrVgH7UQ=; b=Q+iR+24ow2YPAm1IAEbJ4CibZ8O8viGtSzMVHo8qtqS/8EthsMQGdJqP30PbuV1K869Q7z weQaiiOs3PIYmVL5VUL1DrZ3Hy95a8x1KHFtyg2lCn2UG0brYrfYruiOvc2MnoSW1/hv4G wa23QBRzJ9TqxnuPHaDmsZL4QlKTWAs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-ld5D_CZpP5eRYdorAN4ycA-1; Tue, 18 Apr 2023 18:40:09 -0400 X-MC-Unique: ld5D_CZpP5eRYdorAN4ycA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 290F3101A531; Tue, 18 Apr 2023 22:40:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE26540BC798; Tue, 18 Apr 2023 22:40:07 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Steve French cc: dhowells@redhat.com, Paulo Alcantara , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Long Li , Enzo Matsumiya , Shyam Prasad N , Rohith Surabattula , Jeff Layton , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cifs: Fix unbuffered read MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 18 Apr 2023 23:40:07 +0100 Message-ID: <1692048.1681857607@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If read() is done in an unbuffered manner, such that, say, cifs_strict_readv() goes through cifs_user_readv() and thence __cifs_readv(), it doesn't recognise the EOF and keeps indicating to userspace that it returning full buffers of data. This is due to ctx->iter being advanced in cifs_send_async_read() as the buffer is split up amongst a number of rdata objects. The iterator count is then used in collect_uncached_read_data() in the non-DIO case to set the total length read - and thus the return value of sys_read(). But since the iterator normally gets used up completely during splitting, ctx->total_len gets overridden to the full amount. However, prior to that in collect_uncached_read_data(), we've gone through the list of rdatas and added up the amount of data we actually received (which we then throw away). Fix this by removing the bit that overrides the amount read in the non-DIO case and just going with the total added up in the aforementioned loop. This was observed by mounting a cifs share with multiple channels, e.g.: mount //192.168.6.1/test /test/ -o user=3Dshares,pass=3D...,max_channels= =3D6 and then reading a 1MiB file on the share: strace cat /xfstest.test/1M >/dev/null Through strace, the same data can be seen being read again and again. =20=20=20=20 Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather = than a page list") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: J=C3=A9r=C3=B4me Glisse cc: Long Li cc: Enzo Matsumiya cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org --- fs/cifs/file.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 321f9b7c84c9..f8877dc91cc5 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4010,7 +4010,6 @@ static void collect_uncached_read_data(struct cifs_aio_ctx *ctx) { struct cifs_readdata *rdata, *tmp; - struct iov_iter *to =3D &ctx->iter; struct cifs_sb_info *cifs_sb; int rc; =20 @@ -4076,9 +4075,6 @@ collect_uncached_read_data(struct cifs_aio_ctx *ctx) kref_put(&rdata->refcount, cifs_readdata_release); } =20 - if (!ctx->direct_io) - ctx->total_len =3D ctx->len - iov_iter_count(to); - /* mask nodata case */ if (rc =3D=3D -ENODATA) rc =3D 0;