From patchwork Mon Sep 23 15:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13809706 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 033CACF9C72 for ; Mon, 23 Sep 2024 15:09:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A57A66B0099; Mon, 23 Sep 2024 11:09:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D59D6B009B; Mon, 23 Sep 2024 11:09:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89D7D6B009C; Mon, 23 Sep 2024 11:09:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 501746B0099 for ; Mon, 23 Sep 2024 11:09:02 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C9F041413E1 for ; Mon, 23 Sep 2024 15:09:01 +0000 (UTC) X-FDA: 82596335682.18.42909E9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 0F54E40027 for ; Mon, 23 Sep 2024 15:08:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cEhydjC1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727104105; a=rsa-sha256; cv=none; b=yaqJxZ7sGkor8QHJKbFCXhz11qPNGSf2KfRDXEV0uXqG6bnq2Hp7hhaCIQ/2P7vTrcYfvm lmP8SeeNjFifBNBuAhkkb6g752MlaGxwFW81w4Qd2R+z3ZC026naQCR0s9L2KVVmZUSo54 7Cft6k9QGfoan0d2uxUqNLK1rNnJLXw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cEhydjC1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727104105; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=en0FbhjuTrTUZN9cCFkNjaE5g8iEA8EQ8DfNicZc0lg=; b=x1ZbGX1lbga83QN9z/kdQFjkwwntDNoBjVlgKHOuakP9c6Wc00qlzy7mPsSp98kyYtJs3W b8pgY6WZCJKHrQcQfYQjHj1GLu4qhHBar5lEJ2cycISw4/XSh3G9hmgo945EL6QxfVc5H6 ee1n8ZHrnZ7faZjJgJewKR9X3EqOeXI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727104139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=en0FbhjuTrTUZN9cCFkNjaE5g8iEA8EQ8DfNicZc0lg=; b=cEhydjC1V1avq9scUG1Gg6LQIQSX6CUnhkkWZEZPwvWCpqJ+WW+pQpErhhaMZkwUzPlPQ5 03JsfS1kP1dlzMwWZQIjzcfbsQbkJMg7sOn2dFQbH5dfqURhVilUhpI2HCxX45reQUY3G1 lh/8xixiUFBTVcm5uE5dz0sqdcW3Bnw= Received: from mx-prod-mc-03.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-118-hNdBfCa9Nk6QzasA8zlp7Q-1; Mon, 23 Sep 2024 11:08:57 -0400 X-MC-Unique: hNdBfCa9Nk6QzasA8zlp7Q-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 102351895D51; Mon, 23 Sep 2024 15:08:50 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.145]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C5CF4197700E; Mon, 23 Sep 2024 15:08:42 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Marc Dionne Cc: David Howells , Paulo Alcantara , Jeff Layton , Matthew Wilcox , 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-mm@kvack.org, linux-kernel@vger.kernel.org, Shyam Prasad N , Rohith Surabattula Subject: [PATCH 7/8] cifs: Fix reversion of the iter in cifs_readv_receive(). Date: Mon, 23 Sep 2024 16:07:51 +0100 Message-ID: <20240923150756.902363-8-dhowells@redhat.com> In-Reply-To: <20240923150756.902363-1-dhowells@redhat.com> References: <20240923150756.902363-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspam-User: X-Rspamd-Queue-Id: 0F54E40027 X-Rspamd-Server: rspam01 X-Stat-Signature: 7cpt75c3aur6an3f5ntq8abhxrm9ciwr X-HE-Tag: 1727104139-917195 X-HE-Meta: U2FsdGVkX18s+JboWWE2FKmgSW5pTNpFSYJAy5j1m6vyZoy6DjUE9VlAVNsQM2NXDvZbAVdHVQGluN2AWn6NQqrwzR/dDVctJ2aqOqnj21Pslb9ah0gvSVszVtpCWTYuFcQVDUhWGvO9phh7721LfyaD+yHOrCTUy6VwsdtyoVXM9TLPQVmR+Fw9YLkEsz5/UYkfpSAY8Zg76lAAvv6+O52bCNz5Yj89U4irxtSlIrpyJY7XZ++IzMxQK3s1Cks5ReZDTqRm1aUlUbveLhXbX5Hs4P2QiYQ+h0Mxkfex3uOaQOrc4cRenIsIZROTwYU5vDWi8hJKyFgrtTi82nnWKTHqrkB/K0+vEMpPS5QjxDHs6XwbY7HSIjmG/9tAa9jH0i6J2eJFnBhMsYqGEllpqJKVyoRR1NTvrAb8LLjwvjT04sCYvKVMrEQodq9xWfZ21NaC9Iqp1nsDhHRFJzPEUHF6tNR/Wngn1HLRc2BnZEm6S6XwIgh99h5c46Js9XEt9AvAvOR5IE2ivVEWP6nHLyXku7ksaTe2f3en7iUubagdpusAWXQK/4F1dnFzABbVqsbyYtGXvQOTQItG2lkZLopI6cVwMl36V+mYKoFChimaWitxnLmmkmH0gRkPHAIRumO5A64IlGuTi1pjkeKIZGRiUiI+vsK47fCeP70hYQrG2V1WDf6DS4OsZ4nSwUUXauuZUfRog1K4qHt2NMYheWMVsty/cLPrrir3RaHqJGDai2HWV4Zt87BYquS6Z7e9gSc05jpKeesENNNNn3V86zM/xdaM6Cspy75dzvOBJZzH0XU9Z9k2BnnRqNbG+vMRJ5Im5+8QIerdRt0D0bcPrNpbuUfPYiIxvxvdXH6Oeu4Ccy0gqilACLyO8qe62vfzDtc55jdsLInQxCsXYEq6RS9GufZPvl/EFiwoYzmxZDf1z5U/gh7g37m11P39IKmLcG6XhDF56el1jZ8tp3h mSLaTYfx 8/RPYGUQTeQ8/rgm55T8q/GCeRvxMw/kx/u8xQRFLZ7LC3HjQSSsjXGsuJMlW5vEafcS52b2Lg5lrDk920QxKLlkftkpEGBOrmg+4fdcfez6uW8e7aO/6dmoi7CdziNUbMFZUWnGleUecTeHOqDB9hi3X1CWDsNVAqGHAnr1ZIzg82eizNX390Ikita77pCMbe5SCW7bKTuXF9bJrv9+9IDK2ytPAW6/MaE5nQ3Uty2uUvVvT5woNi8tzZS+V3fiM66xLV2R6CWkXh3qi/Yxp77omKrvmRXw6I8RSqXiYJ3zIgPxfk7rOBEPbDK1h49DroaO7hUuBFdhc3WFzhGleZsYZ+FQgLFLUmrCicZ2hd8Qqu2/oKPWzDMnNxNRXeGHRWC8dUKXPpL97z5M59PyZ3NA+WLUOz887GNavWim4ejKnC77ABk8FfWKhRd+ViEturceEMd7JYOEfFpfluugV62x3942hPzJsQO+CkBjWiEez5EXK1HNwgpElQFB24L+8MvSl1gCSFMJqCI+3N2+EVLyCJUqTKbM6GQuGDVgnkhZAgOtE2IwoARhk/obub9IjuR0srMBVi+W/PcYWxV5cmEnAdVIr7M7OQ+kf X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: cifs_read_iter_from_socket() copies the iterator that's passed in for the socket to modify as and if it will, and then advances the original iterator by the amount sent. However, both callers revert the advancement (although receive_encrypted_read() zeros beyond the iterator first). The problem is, though, that cifs_readv_receive() reverts by the original length, not the amount transmitted which can cause an oops in iov_iter_revert(). Fix this by: (1) Remove the iov_iter_advance() from cifs_read_iter_from_socket(). (2) Remove the iov_iter_revert() from both callers. This fixes the bug in cifs_readv_receive(). (3) In receive_encrypted_read(), if we didn't get back as much data as the buffer will hold, copy the iterator, advance the copy and use the copy to drive iov_iter_zero(). As a bonus, this gets rid of some unnecessary work. This was triggered by generic/074 with the "-o sign" mount option. Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/connect.c | 6 +----- fs/smb/client/smb2ops.c | 9 ++++++--- fs/smb/client/transport.c | 3 --- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 08a41c7aaf72..be6e632388f8 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -811,13 +811,9 @@ cifs_read_iter_from_socket(struct TCP_Server_Info *server, struct iov_iter *iter unsigned int to_read) { struct msghdr smb_msg = { .msg_iter = *iter }; - int ret; iov_iter_truncate(&smb_msg.msg_iter, to_read); - ret = cifs_readv_from_socket(server, &smb_msg); - if (ret > 0) - iov_iter_advance(iter, ret); - return ret; + return cifs_readv_from_socket(server, &smb_msg); } static bool diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 7381ec333c6d..1ee2dd4a1cae 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -4869,9 +4869,12 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, goto discard_data; server->total_read += rc; - if (rc < len) - iov_iter_zero(len - rc, &iter); - iov_iter_revert(&iter, len); + if (rc < len) { + struct iov_iter tmp = iter; + + iov_iter_advance(&tmp, rc); + iov_iter_zero(len - rc, &tmp); + } iov_iter_truncate(&iter, dw->len); rc = cifs_discard_remaining_data(server); diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c index fd5a85d43759..91812150186c 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -1817,11 +1817,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) length = data_len; /* An RDMA read is already done. */ else #endif - { length = cifs_read_iter_from_socket(server, &rdata->subreq.io_iter, data_len); - iov_iter_revert(&rdata->subreq.io_iter, data_len); - } if (length > 0) rdata->got_bytes += length; server->total_read += length;