From: David Howells <dhowells@redhat.com>
To: Enzo Matsumiya <ematsumiya@suse.de>
Cc: dhowells@redhat.com, Steve French <sfrench@samba.org>,
Paulo Alcantara <pc@manguebit.org>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>,
Wang Zhaolong <wangzhaolong@huaweicloud.com>,
Stefan Metzmacher <metze@samba.org>,
Mina Almasry <almasrymina@google.com>,
linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org
Subject: Re: [RFC PATCH 24/31] cifs: Convert SMB2 Negotiate Protocol request
Date: Fri, 08 Aug 2025 16:10:10 +0100 [thread overview]
Message-ID: <2926140.1754665810@warthog.procyon.org.uk> (raw)
In-Reply-To: <zt6f2jl6y5wpiuchryc2vdsmtkiia7s5mligm7helffkanxe3o@2f2ksngn5ekk>
Enzo Matsumiya <ematsumiya@suse.de> wrote:
> On 08/06, David Howells wrote:
> > ...
> > -static unsigned int
> >-build_netname_ctxt(struct smb2_netname_neg_context *pneg_ctxt, char *hostname)
> >+static size_t smb2_size_netname_ctxt(struct TCP_Server_Info *server)
> > {
> >+ size_t data_len;
> >+
> >+#if 0
> > struct nls_table *cp = load_nls_default();
> >+ const char *hostname;
> >
> >- pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID;
> >+ /* Only include up to first 100 bytes of server name in the NetName
> >+ * field.
> >+ */
> >+ cifs_server_lock(pserver);
> >+ hostname = pserver->hostname;
> >+ if (hostname && hostname[0])
> >+ data_len = cifs_size_strtoUTF16(hostname, 100, cp);
> >+ cifs_server_unlock(pserver);
> >+#else
> >+ /* Now, we can't just measure the length of hostname as, unless we hold
> >+ * the lock, it may change under us, so allow maximum space for it.
> >+ */
> >+ data_len = 400;
> >+#endif
> >+ return ALIGN8(sizeof(struct smb2_neg_context) + data_len);
> >+}
>
> Why was this commented out? Your comment implies that you can't hold
> the lock anymore there, but I couldn't find out why (with your patches
> applied).
The problem is that the hostname may change - and there's a spinlock to
protect it. However, now that I'm working out the message size before the
allocation, I need to find the size of the host name, do the alloc and then
copy the hostname in - but I can't hold the spinlock across the alloc, so the
hostname may change whilst the lock is dropped.
The obvious solution is to just allocate the maximum size for it. It's not
that big and this command isn't used all that often.
Remember that this is a work in progress, so you may find bits like this where
I may need to reconsider what I've chosen.
> >-static void
> >-assemble_neg_contexts(struct smb2_negotiate_req *req,
> >- struct TCP_Server_Info *server, unsigned int *total_len)
> >+static size_t smb2_size_neg_contexts(struct TCP_Server_Info *server,
> >+ size_t offset)
> > {
> >- unsigned int ctxt_len, neg_context_count;
> > struct TCP_Server_Info *pserver;
> >- char *pneg_ctxt;
> >- char *hostname;
> >-
> >- if (*total_len > 200) {
> >- /* In case length corrupted don't want to overrun smb buffer */
> >- cifs_server_dbg(VFS, "Bad frame length assembling neg contexts\n");
> >- return;
> >- }
> >
> > /*
> > * round up total_len of fixed part of SMB3 negotiate request to 8
> > * byte boundary before adding negotiate contexts
> > */
> >- *total_len = ALIGN8(*total_len);
> >+ offset = ALIGN8(offset);
> >+ offset += ALIGN8(sizeof(struct smb2_preauth_neg_context));
> >+ offset += ALIGN8(sizeof(struct smb2_encryption_neg_context));
> >
> >- pneg_ctxt = (*total_len) + (char *)req;
> >- req->NegotiateContextOffset = cpu_to_le32(*total_len);
> >+ /*
> >+ * secondary channels don't have the hostname field populated
> >+ * use the hostname field in the primary channel instead
> >+ */
> >+ pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
> >+ offset += smb2_size_netname_ctxt(pserver);
>
> If you're keeping data_len=400 above, you could just drop
> smb2_size_netname_ctxt() altogether and use
> "ALIGN8(sizeof(struct smb2_neg_context) + 400)" directly here.
Yeah. Probably would make sense to do that with a comment saying why 400.
David
next prev parent reply other threads:[~2025-08-08 15:10 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 20:36 [RFC PATCH 00/31] netfs: [WIP] Allow the use of MSG_SPLICE_PAGES and use netmem allocator David Howells
2025-08-06 20:36 ` [RFC PATCH 01/31] iov_iter: Move ITER_DISCARD and ITER_XARRAY iteration out-of-line David Howells
2025-08-06 20:36 ` [RFC PATCH 02/31] iov_iter: Add a segmented queue of bio_vec[] David Howells
2025-08-06 20:36 ` [RFC PATCH 03/31] netfs: Provide facility to alloc buffer in a bvecq David Howells
2025-08-06 20:36 ` [RFC PATCH 04/31] cifs, nls: Provide unicode size determination func David Howells
2025-08-06 20:36 ` [RFC PATCH 05/31] cifs: Introduce an ALIGN8() macro David Howells
2025-08-06 20:36 ` [RFC PATCH 06/31] cifs: Move the SMB1 transport code out of transport.c David Howells
2025-08-06 20:36 ` [RFC PATCH 07/31] cifs: Rename mid_q_entry to smb_message David Howells
2025-08-06 20:36 ` [RFC PATCH 08/31] cifs: Keep the CPU-endian command ID around David Howells
2025-08-06 20:36 ` [RFC PATCH 09/31] cifs: Rename SMB2_xxxx_HE to SMB2_xxxx David Howells
2025-08-06 20:36 ` [RFC PATCH 10/31] cifs: Make smb1's SendReceive() wrap cifs_send_recv() David Howells
2025-08-06 20:36 ` [RFC PATCH 11/31] cifs: Fix SMB1 to not require separate kvec for the rfc1002 header David Howells
2025-08-06 20:36 ` [RFC PATCH 12/31] cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flags David Howells
2025-08-06 20:36 ` [RFC PATCH 13/31] cifs: Institute message managing struct David Howells
2025-08-06 20:36 ` [RFC PATCH 14/31] cifs: Split crypt_message() into encrypt and decrypt variants David Howells
2025-08-06 20:36 ` [RFC PATCH 15/31] cifs: Use netfs_alloc/free_folioq_buffer() David Howells
2025-08-06 20:36 ` [RFC PATCH 16/31] cifs: Rewrite base TCP transmission David Howells
2025-08-07 5:40 ` Stefan Metzmacher
2025-08-07 10:12 ` David Howells
2025-08-07 10:14 ` David Howells
2025-08-06 20:36 ` [RFC PATCH 17/31] cifs: Rework smb2 decryption David Howells
2025-08-06 20:36 ` [RFC PATCH 18/31] cifs: Pass smb_message structs down into the transport layer David Howells
2025-08-08 14:21 ` Enzo Matsumiya
2025-08-06 20:36 ` [RFC PATCH 19/31] cifs: Clean up mid->callback_data and kill off mid->creator David Howells
2025-08-06 20:36 ` [RFC PATCH 20/31] cifs: Don't need state locking in smb2_get_mid_entry() David Howells
2025-08-06 20:36 ` [RFC PATCH 21/31] cifs: [DEBUG] smb_message refcounting David Howells
2025-08-06 20:36 ` [RFC PATCH 22/31] cifs: Add netmem allocation functions David Howells
2025-08-06 20:36 ` [RFC PATCH 23/31] cifs: Add more pieces to smb_message David Howells
2025-08-06 20:36 ` [RFC PATCH 24/31] cifs: Convert SMB2 Negotiate Protocol request David Howells
2025-08-08 14:44 ` Enzo Matsumiya
2025-08-08 15:10 ` David Howells [this message]
2025-08-06 20:36 ` [RFC PATCH 25/31] cifs: Convert SMB2 Session Setup request David Howells
2025-08-06 20:36 ` [RFC PATCH 26/31] cifs: Convert SMB2 Logoff request David Howells
2025-08-06 20:36 ` [RFC PATCH 27/31] cifs: Convert SMB2 Tree Connect request David Howells
2025-08-06 20:36 ` [RFC PATCH 28/31] cifs: Convert SMB2 Tree Disconnect request David Howells
2025-08-06 20:36 ` [RFC PATCH 29/31] cifs: Rearrange Create request subfuncs David Howells
2025-08-06 20:36 ` [RFC PATCH 30/31] cifs: Convert SMB2 Posix Mkdir request David Howells
2025-08-06 20:36 ` [RFC PATCH 31/31] cifs: Convert SMB2 Open request David Howells
2025-08-07 5:23 ` [RFC PATCH 00/31] netfs: [WIP] Allow the use of MSG_SPLICE_PAGES and use netmem allocator Stefan Metzmacher
2025-08-07 6:24 ` David Howells
2025-08-07 6:54 ` Stefan Metzmacher
2025-08-07 7:12 ` David Howells
2025-08-08 14:15 ` Enzo Matsumiya
2025-08-08 17:25 ` David Howells
2025-08-08 19:58 ` Enzo Matsumiya
2025-08-08 20:33 ` David Howells
2025-08-10 23:29 ` David Howells
2025-08-11 12:25 ` Enzo Matsumiya
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2926140.1754665810@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=almasrymina@google.com \
--cc=ematsumiya@suse.de \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=metze@samba.org \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.org \
--cc=sfrench@samba.org \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=wangzhaolong@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®