From nobody Thu Dec 18 12:32:33 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A664C2D3EDF for ; Wed, 6 Aug 2025 20:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754512773; cv=none; b=Xln2zl+wQIoH73hTN0RYygfHxq9vq8GTMpnfPuPnHTYhJgZV3zV009skwhwBkYhOK8JsTQsRs8mIOkBmT/29w5K7txEAiEVbJR5Wulyb/s0oqTluPYgMJp6pNI3CSDdNSaqDgjRT0dGrICNXuxbUBC0DDODDrYdvygbnTMVwrzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754512773; c=relaxed/simple; bh=EmcC1MzHMapaCFx8ngoOknAJSipRgtspC2cISwSR4YA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=siiJcSuti0rhLHs3tw2A9pz4/3WSjxSx3zq8lAhcYzaLJaTjCLLKlB87YUnNk9snwtZlF4Ra9pyfsFWE+bKtVgDbVvKHbBYCEHm7IxaOJRXHQfONACKfxATbL3OaBWh4ibLBOGWHotMyhQQ9K1LBvtnATQBstFvbOk77/n6lFdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AP1I3w1Z; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AP1I3w1Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754512770; 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=1N8y8Gx1EbPTw63BonzmbK2SbB3Yno56oTacfPQuS/A=; b=AP1I3w1Z+UcCTPN5IyHipNg3zabF+Mhb6mN/fImdOv0wu23nEE3LSMasRmKcpk43RXC9t/ BnYBHQpHZCQeDvmXbEPZb9+6VUhvjkS+V/El8SLD2OiuQ/MOWzA9bmiLQoskyj84TaDrIi gRkRDbFQMlrYRBXuavm43VZL6tffItc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-sf-38EwgNMepm8E2h_JoXw-1; Wed, 06 Aug 2025 16:39:27 -0400 X-MC-Unique: sf-38EwgNMepm8E2h_JoXw-1 X-Mimecast-MFC-AGG-ID: sf-38EwgNMepm8E2h_JoXw_1754512765 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 501691800346; Wed, 6 Aug 2025 20:39:25 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.17]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D9C8619560AD; Wed, 6 Aug 2025 20:39:21 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Wang Zhaolong , Stefan Metzmacher , Mina Almasry , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 27/31] cifs: Convert SMB2 Tree Connect request Date: Wed, 6 Aug 2025 21:36:48 +0100 Message-ID: <20250806203705.2560493-28-dhowells@redhat.com> In-Reply-To: <20250806203705.2560493-1-dhowells@redhat.com> References: <20250806203705.2560493-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Tom Talpey cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/smb2pdu.c | 71 +++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index c63c62cd6638..4300ae311ee2 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -2277,57 +2277,43 @@ int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, struct cifs_tcon *tcon, const struct nls_table *cp) { - struct smb_rqst rqst; + struct TCP_Server_Info *server =3D cifs_pick_channel(ses); struct smb2_tree_connect_req *req; struct smb2_tree_connect_rsp *rsp =3D NULL; - struct kvec iov[2]; - struct kvec rsp_iov =3D { NULL, 0 }; - int rc =3D 0; - int resp_buftype; - int unc_path_len; - __le16 *unc_path =3D NULL; + struct smb_message *smb =3D NULL; + int unc_path_size; int flags =3D 0; - unsigned int total_len; - struct TCP_Server_Info *server =3D cifs_pick_channel(ses); + int rc =3D 0; =20 cifs_dbg(FYI, "TCON\n"); =20 if (!server || !tree) return -EIO; =20 - unc_path =3D kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL); - if (unc_path =3D=3D NULL) - return -ENOMEM; - - unc_path_len =3D cifs_strtoUTF16(unc_path, tree, strlen(tree), cp); - if (unc_path_len <=3D 0) { - kfree(unc_path); - return -EINVAL; - } - unc_path_len *=3D 2; + unc_path_size =3D cifs_size_strtoUTF16(tree, INT_MAX, cp); =20 /* SMB2 TREE_CONNECT request must be called with TreeId =3D=3D 0 */ tcon->tid =3D 0; atomic_set(&tcon->num_remote_opens, 0); - rc =3D smb2_plain_req_init(SMB2_TREE_CONNECT, tcon, server, - (void **) &req, &total_len); - if (rc) { - kfree(unc_path); - return rc; - } + + smb =3D smb2_create_request(SMB2_TREE_CONNECT, server, tcon, + sizeof(*req), sizeof(*req) + unc_path_size, 0, + SMB2_REQ_DYNAMIC); + if (!smb) + return -ENOMEM; =20 if (smb3_encryption_required(tcon)) flags |=3D CIFS_TRANSFORM_REQ; =20 - iov[0].iov_base =3D (char *)req; - /* 1 for pad */ - iov[0].iov_len =3D total_len - 1; - /* Testing shows that buffer offset must be at location of Buffer[0] */ - req->PathOffset =3D cpu_to_le16(sizeof(struct smb2_tree_connect_req)); - req->PathLength =3D cpu_to_le16(unc_path_len); - iov[1].iov_base =3D unc_path; - iov[1].iov_len =3D unc_path_len; + req->PathOffset =3D cpu_to_le16(smb->ext_offset); + req->PathLength =3D cpu_to_le16(unc_path_size); + + rc =3D cifs_strtoUTF16(smb->request + smb->ext_offset, tree, strlen(tree)= , cp); + if (rc <=3D 0) { + rc =3D -EINVAL; + goto tcon_exit; + } =20 /* * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 @@ -2341,22 +2327,17 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *= ses, const char *tree, ((ses->user_name !=3D NULL) || (ses->sectype =3D=3D Kerberos))) req->hdr.Flags |=3D SMB2_FLAGS_SIGNED; =20 - memset(&rqst, 0, sizeof(struct smb_rqst)); - rqst.rq_iov =3D iov; - rqst.rq_nvec =3D 2; - /* Need 64 for max size write so ask for more in case not there yet */ if (server->credits >=3D server->max_credits) req->hdr.CreditRequest =3D cpu_to_le16(0); else req->hdr.CreditRequest =3D cpu_to_le16( - min_t(int, server->max_credits - - server->credits, 64)); + min_t(int, server->max_credits - server->credits, 64)); =20 - rc =3D cifs_send_recv(xid, ses, server, - &rqst, &resp_buftype, flags, &rsp_iov); - cifs_small_buf_release(req); - rsp =3D (struct smb2_tree_connect_rsp *)rsp_iov.iov_base; + rc =3D smb_send_recv_messages(xid, ses, server, smb, flags); + smb_clear_request(smb); + + rsp =3D (struct smb2_tree_connect_rsp *)smb->response; trace_smb3_tcon(xid, tcon->tid, ses->Suid, tree, rc); if ((rc !=3D 0) || (rsp =3D=3D NULL)) { cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT); @@ -2403,9 +2384,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *se= s, const char *tree, if (tcon->share_flags & SMB2_SHAREFLAG_ISOLATED_TRANSPORT) server->nosharesock =3D true; tcon_exit: - - free_rsp_buf(resp_buftype, rsp); - kfree(unc_path); + smb_put_messages(smb); return rc; =20 tcon_error_exit: