Skip to contentSkip to conversation

cifs: implementation id context as negotiate context

PATCH In review [email protected] 6 participants 15 messages Mar 4 – Mar 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: implementation id context as negotiate context

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
 fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
 fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
 2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
 #include <linux/pagemap.h>
 #include <linux/xattr.h>
 #include <linux/netfs.h>
+#include <linux/utsname.h>
 #include <trace/events/netfs.h>
 #include "cifsglob.h"
 #include "cifsproto.h"
@@ -45,6 +46,7 @@
 #include "cached_dir.h"
 #include "compress.h"
 #include "fs_context.h"
+#include "cifsfs.h"
 
 /*
  *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
 	pneg_ctxt->Name[15] = 0x7C;
 }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+	struct nls_table *cp = load_nls_default();
+	struct new_utsname *uts = utsname();
+	const char *impl_domain = "kernel.org";
+	const char *impl_name = "fs/smb/client";
+	const char *os_name = "Linux";
+	unsigned int data_len = 0;
+	__u8 *data_ptr;
+	int len;
+
+	pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+	data_ptr = pneg_ctxt->Data;
+
+	/* ImplDomain */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+			      SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+	pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* ImplName */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+			      SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+	pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* ImplVersion - CIFS_VERSION from cifsfs.h */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+			      SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+	pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* HostName - from utsname()->nodename */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+			      SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+	pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* OSName */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+			      SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+	pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* OSVersion - from utsname()->release */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+			      SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+	pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* Arch - from utsname()->machine */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+			      SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+	pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+	data_len += len * 2;
+
+	pneg_ctxt->Reserved2 = 0;
+	pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+	/* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+	return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
 static void
 assemble_neg_contexts(struct smb2_negotiate_req *req,
 		      struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
 		neg_context_count++;
 	}
 
+	/* Add implementation ID context */
+	ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+				pneg_ctxt);
+	*total_len += ctxt_len;
+	pneg_ctxt += ctxt_len;
+	neg_context_count++;
+
 	/* check for and add transport_capabilities and signing capabilities */
 	req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +32 -0
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
 #define SMB2_TRANSPORT_CAPABILITIES		cpu_to_le16(6)
 #define SMB2_RDMA_TRANSFORM_CAPABILITIES	cpu_to_le16(7)
 #define SMB2_SIGNING_CAPABILITIES		cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID	cpu_to_le16(0xF100)
 #define SMB2_POSIX_EXTENSIONS_AVAILABLE		cpu_to_le16(0x100)
 
 struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
 	/*  Followed by padding to 8 byte boundary (required by some servers) */
 } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN	128
+#define SMB2_IMPL_ID_MAX_NAME_LEN	260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN	260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN	64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN	64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN	64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN	64
+
+struct smb2_implementation_id_context {
+	__le16	ContextType; /* 9 */
+	__le16	DataLength;
+	__le32	Reserved;
+	__le16	ImplDomainLength;
+	__le16	ImplNameLength;
+	__le16	ImplVersionLength;
+	__le16	HostNameLength;
+	__le16	OSNameLength;
+	__le16	OSVersionLength;
+	__le16	ArchLength;
+	__le16	Reserved2;
+	/* Followed by variable length UTF-16 strings:
+	 * ImplDomain, ImplName, ImplVersion, HostName,
+	 * OSName, OSVersion, Arch
+	 */
+	__u8	Data[];
+} __packed;
+
 #define POSIX_CTXT_DATA_LEN	16
 struct smb2_posix_neg_context {
 	__le16	ContextType; /* 0x100 */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 174 lines · On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote:

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
 fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
 fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
 2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
 #include <linux/pagemap.h>
 #include <linux/xattr.h>
 #include <linux/netfs.h>
+#include <linux/utsname.h>
 #include <trace/events/netfs.h>
 #include "cifsglob.h"
 #include "cifsproto.h"
@@ -45,6 +46,7 @@
 #include "cached_dir.h"
 #include "compress.h"
 #include "fs_context.h"
+#include "cifsfs.h"
 
 /*
  *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
        pneg_ctxt->Name[15] = 0x7C;
 }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+       struct nls_table *cp = load_nls_default();
+       struct new_utsname *uts = utsname();
+       const char *impl_domain = "kernel.org";
+       const char *impl_name = "fs/smb/client";
+       const char *os_name = "Linux";
+       unsigned int data_len = 0;
+       __u8 *data_ptr;
+       int len;
+
+       pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+       data_ptr = pneg_ctxt->Data;
+
+       /* ImplDomain */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+                             SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+       pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* ImplName */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+                             SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+       pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* ImplVersion - CIFS_VERSION from cifsfs.h */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+                             SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+       pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* HostName - from utsname()->nodename */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+                             SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+       pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* OSName */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+                             SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+       pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* OSVersion - from utsname()->release */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+                             SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+       pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+       data_ptr += len * 2;
+       data_len += len * 2;
+
+       /* Arch - from utsname()->machine */
+       len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+                             SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+       pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+       data_len += len * 2;
+
+       pneg_ctxt->Reserved2 = 0;
+       pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+       /* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+       return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
 static void
 assemble_neg_contexts(struct smb2_negotiate_req *req,
                      struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
                neg_context_count++;
        }
 
+       /* Add implementation ID context */
+       ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+                               pneg_ctxt);
+       *total_len += ctxt_len;
+       pneg_ctxt += ctxt_len;
+       neg_context_count++;
+
        /* check for and add transport_capabilities and signing capabilities */
        req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +32 -1
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
 #define SMB2_TRANSPORT_CAPABILITIES            cpu_to_le16(6)
 #define SMB2_RDMA_TRANSFORM_CAPABILITIES       cpu_to_le16(7)
 #define SMB2_SIGNING_CAPABILITIES              cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID      cpu_to_le16(0xF100)
 #define SMB2_POSIX_EXTENSIONS_AVAILABLE                cpu_to_le16(0x100)
 
 struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
        /*  Followed by padding to 8 byte boundary (required by some servers) */
 } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN    128
+#define SMB2_IMPL_ID_MAX_NAME_LEN      260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN   260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN  64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN   64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN        64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN      64
+
+struct smb2_implementation_id_context {
+       __le16  ContextType; /* 9 */
+       __le16  DataLength;
+       __le32  Reserved;
+       __le16  ImplDomainLength;
+       __le16  ImplNameLength;
+       __le16  ImplVersionLength;
+       __le16  HostNameLength;
+       __le16  OSNameLength;
+       __le16  OSVersionLength;
+       __le16  ArchLength;
+       __le16  Reserved2;
+       /* Followed by variable length UTF-16 strings:
+        * ImplDomain, ImplName, ImplVersion, HostName,
+        * OSName, OSVersion, Arch
+        */
+       __u8    Data[];
+} __packed;
+
 #define POSIX_CTXT_DATA_LEN    16
 struct smb2_posix_neg_context {
        __le16  ContextType; /* 0x100 */
--
Quoted 2 lines

2.43.0

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Signature · 2 lines
Regards,
Shyam
#2 lore raw

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

Thanks,

Signature · 2 lines
Henrique
SUSE Labs
#3 lore raw
Quoted 10 lines · Henrique Carvalho

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

It does get incremented every 10 weeks.

Quoted 4 lines

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

We do bump the module version every kernel release, e.g. we are at 2.59 in Linux 7.0 (7.0-rc2)
Would bump it when someone does a 'full backport' of most cifs fixes to an earlier kernel.

Quoted 2 lines

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I thought this was for the reverse - so the server support team can get metrics on whether the client is an old client with known bugs

Quoted 3 lines

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

presumably primarily for customer support to be able to recognise known client problems on clients accessing a server

Signature · 3 lines
Thanks,

Steve
maintainer
#4 lore raw
Quoted 20 lines · Steve French
Quoted 10 lines · Henrique Carvalho

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

It does get incremented every 10 weeks.

Quoted 4 lines

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

Quoted 4 lines

We do bump the module version every kernel release, e.g. we are at 2.59 in Linux 7.0 (7.0-rc2)
Would bump it when someone does a 'full backport' of most cifs fixes to an earlier kernel.

Who?

Quoted 5 lines
Quoted 2 lines

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I thought this was for the reverse - so the server support team can get metrics on whether the client is an old client with known bugs

The client version is entirely pointless, especially for distribution kernels. The support team can't figure out by just looking at the client version as the backports are what really matter in terms of a distro kernel. Most distro kernels don't even bother backporting those commits that bump the client version, which makes it even more inaccurate.

Quoted 6 lines
Quoted 3 lines

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

presumably primarily for customer support to be able to recognise known client problems on clients accessing a server

Neither the client or kernel version will tell you _exactly_ where the problem is in distro kernels.

#5 lore raw
Quoted 47 lines · Paulo Alcantara
Quoted 20 lines · Steve French
Quoted 10 lines · Henrique Carvalho

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

It does get incremented every 10 weeks.

Quoted 4 lines

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

Quoted 4 lines

We do bump the module version every kernel release, e.g. we are at 2.59 in Linux 7.0 (7.0-rc2)
Would bump it when someone does a 'full backport' of most cifs fixes to an earlier kernel.

Who?

Quoted 5 lines
Quoted 2 lines

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I thought this was for the reverse - so the server support team can get metrics on whether the client is an old client with known bugs

The client version is entirely pointless, especially for distribution kernels. The support team can't figure out by just looking at the client version as the backports are what really matter in terms of a distro kernel. Most distro kernels don't even bother backporting those commits that bump the client version, which makes it even more inaccurate.

Quoted 4 lines
Quoted 3 lines

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

Quoted 5 lines
Quoted 2 lines

presumably primarily for customer support to be able to recognise known client problems on clients accessing a server

Neither the client or kernel version will tell you _exactly_ where the problem is in distro kernels.

The combination of the various version fields would be 99% likely to be able to match to a particular distro version (at least for the major ones, SuSE, Redhat, Ubuntu, Mariner). Unfortunately there are many customers out there who run kernels more than four years old so can be helpful to know client os version

Signature · 3 lines
Thanks,

Steve
#7 lore raw
In reply to Steve French
Quoted 8 lines · Steve French
Quoted 6 lines · Henrique Carvalho

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Quoted 7 lines
Quoted 4 lines

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

It does get incremented every 10 weeks.

Okay. I guess we've skipped sometimes.

Quoted 16 lines
Quoted 4 lines

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

We do bump the module version every kernel release, e.g. we are at 2.59 in Linux 7.0 (7.0-rc2)
Would bump it when someone does a 'full backport' of most cifs fixes to an earlier kernel.

Quoted 2 lines

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I thought this was for the reverse - so the server support team can get metrics on whether the client is an old client with known bugs

Quoted 7 lines
Quoted 3 lines

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

presumably primarily for customer support to be able to recognise known client problems on clients accessing a server

Yes, but also the server will be able to send back context as well, correct? This may allow more than bug triaging.

Signature · 2 lines
Henrique
SUSE Labs
#8 lore raw
In reply to [email protected]

Hi!

I wonder which servers are expected to be implementing this? I suppose this protocol extension is not proposed without a server vendor interested in actually implementing it, otherwise the whole metrics story doesn't make sense.

*scratches head*

Thanks!
-slow

Quoted 172 lines · On 3/4/26 1:27 PM, [email protected] wrote:

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
  fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
  fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
  2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
  #include <linux/pagemap.h>
  #include <linux/xattr.h>
  #include <linux/netfs.h>
+#include <linux/utsname.h>
  #include <trace/events/netfs.h>
  #include "cifsglob.h"
  #include "cifsproto.h"
@@ -45,6 +46,7 @@
  #include "cached_dir.h"
  #include "compress.h"
  #include "fs_context.h"
+#include "cifsfs.h"
 
  /*
   *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
  	pneg_ctxt->Name[15] = 0x7C;
  }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+	struct nls_table *cp = load_nls_default();
+	struct new_utsname *uts = utsname();
+	const char *impl_domain = "kernel.org";
+	const char *impl_name = "fs/smb/client";
+	const char *os_name = "Linux";
+	unsigned int data_len = 0;
+	__u8 *data_ptr;
+	int len;
+
+	pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+	data_ptr = pneg_ctxt->Data;
+
+	/* ImplDomain */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+			      SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+	pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* ImplName */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+			      SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+	pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* ImplVersion - CIFS_VERSION from cifsfs.h */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+			      SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+	pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* HostName - from utsname()->nodename */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+			      SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+	pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* OSName */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+			      SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+	pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* OSVersion - from utsname()->release */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+			      SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+	pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+	data_ptr += len * 2;
+	data_len += len * 2;
+
+	/* Arch - from utsname()->machine */
+	len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+			      SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+	pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+	data_len += len * 2;
+
+	pneg_ctxt->Reserved2 = 0;
+	pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+	/* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+	return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
  static void
  assemble_neg_contexts(struct smb2_negotiate_req *req,
  		      struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
  		neg_context_count++;
  	}
 
+	/* Add implementation ID context */
+	ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+				pneg_ctxt);
+	*total_len += ctxt_len;
+	pneg_ctxt += ctxt_len;
+	neg_context_count++;
+
  	/* check for and add transport_capabilities and signing capabilities */
  	req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +32 -0
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
  #define SMB2_TRANSPORT_CAPABILITIES		cpu_to_le16(6)
  #define SMB2_RDMA_TRANSFORM_CAPABILITIES	cpu_to_le16(7)
  #define SMB2_SIGNING_CAPABILITIES		cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID	cpu_to_le16(0xF100)
  #define SMB2_POSIX_EXTENSIONS_AVAILABLE		cpu_to_le16(0x100)
 
  struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
  	/*  Followed by padding to 8 byte boundary (required by some servers) */
  } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN	128
+#define SMB2_IMPL_ID_MAX_NAME_LEN	260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN	260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN	64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN	64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN	64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN	64
+
+struct smb2_implementation_id_context {
+	__le16	ContextType; /* 9 */
+	__le16	DataLength;
+	__le32	Reserved;
+	__le16	ImplDomainLength;
+	__le16	ImplNameLength;
+	__le16	ImplVersionLength;
+	__le16	HostNameLength;
+	__le16	OSNameLength;
+	__le16	OSVersionLength;
+	__le16	ArchLength;
+	__le16	Reserved2;
+	/* Followed by variable length UTF-16 strings:
+	 * ImplDomain, ImplName, ImplVersion, HostName,
+	 * OSName, OSVersion, Arch
+	 */
+	__u8	Data[];
+} __packed;
+
  #define POSIX_CTXT_DATA_LEN	16
  struct smb2_posix_neg_context {
  	__le16	ContextType; /* 0x100 */
#6 lore raw
In reply to Paulo Alcantara
Quoted 47 lines · Paulo Alcantara
Quoted 20 lines · Steve French
Quoted 10 lines · Henrique Carvalho

On Wed, Mar 04, 2026 at 06:04:05PM +0530, Shyam Prasad N wrote: > On Wed, Mar 4, 2026 at 5:59 PM <[email protected]> wrote: From: Shyam Prasad N <[email protected]>

Quoted 3 lines

A proof-of-concept based on this draft from Bharath. Looking for comments on how to improve.

Looks good.

Just one minor thing for now. To me the cifs.ko module version doesn't say much as it seems to be not reliable (apologies if I'm mistaken).

It does get incremented every 10 weeks.

Quoted 4 lines

Also, the same version could have different implementations in different distributions. modinfo -F srcversion cifs is a better way to differentiate cifs versions but not to compare versions. So the solution is either remove this or bump it in every change using X.Y.Z.

Quoted 4 lines

We do bump the module version every kernel release, e.g. we are at 2.59 in Linux 7.0 (7.0-rc2)
Would bump it when someone does a 'full backport' of most cifs fixes to an earlier kernel.

Who?

Quoted 5 lines
Quoted 2 lines

Further, have you thought about how the client can use this in its favor other than diagnosing/debugging a faulty server?

I thought this was for the reverse - so the server support team can get metrics on whether the client is an old client with known bugs

The client version is entirely pointless, especially for distribution kernels. The support team can't figure out by just looking at the client version as the backports are what really matter in terms of a distro kernel. Most distro kernels don't even bother backporting those commits that bump the client version, which makes it even more inaccurate.

Quoted 4 lines
Quoted 3 lines

I think we need to be clear on what is allowed here, to me it seems quirks, workarounds and perf tuning? Maybe this can be used to improve interaction between linux client and linux server?

Quoted 5 lines
Quoted 2 lines

presumably primarily for customer support to be able to recognise known client problems on clients accessing a server

Neither the client or kernel version will tell you _exactly_ where the problem is in distro kernels.

Hi Paulo / Henrique,

Good points.
srcversion is probably something that can be unique for a specific version. But is there a common place where srcversion values are documented by distros today?
If that is the case, perhaps that with the combination of the kernel version can tell us what cifs.ko the client machine is actually running.

Signature · 2 lines
Regards,
Shyam
#9 lore raw
In reply to Ralph Boehme
Quoted 7 lines · Ralph Boehme

Hi!

I wonder which servers are expected to be implementing this? I suppose this protocol extension is not proposed without a server vendor interested in actually implementing it, otherwise the whole metrics story doesn't make sense.

Hi Ralph,

This is supposed to give the server an idea of what version of cifs.ko the client is actually running.
This can be useful for servers like Azure SMB servers, where it is not easy to explain client side behaviour without knowing what exact version of the code is running on the client.

Quoted 180 lines

*scratches head*

Thanks!
-slow

Quoted 172 lines · On 3/4/26 1:27 PM, [email protected] wrote:

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
  fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
  fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
  2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
  #include <linux/pagemap.h>
  #include <linux/xattr.h>
  #include <linux/netfs.h>
+#include <linux/utsname.h>
  #include <trace/events/netfs.h>
  #include "cifsglob.h"
  #include "cifsproto.h"
@@ -45,6 +46,7 @@
  #include "cached_dir.h"
  #include "compress.h"
  #include "fs_context.h"
+#include "cifsfs.h"
 
  /*
   *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
      pneg_ctxt->Name[15] = 0x7C;
  }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+     struct nls_table *cp = load_nls_default();
+     struct new_utsname *uts = utsname();
+     const char *impl_domain = "kernel.org";
+     const char *impl_name = "fs/smb/client";
+     const char *os_name = "Linux";
+     unsigned int data_len = 0;
+     __u8 *data_ptr;
+     int len;
+
+     pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+     data_ptr = pneg_ctxt->Data;
+
+     /* ImplDomain */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+                           SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+     pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+                           SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+     pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplVersion - CIFS_VERSION from cifsfs.h */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+                           SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+     pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* HostName - from utsname()->nodename */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+                           SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+     pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+                           SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+     pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSVersion - from utsname()->release */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+                           SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+     pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* Arch - from utsname()->machine */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+                           SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+     pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+     data_len += len * 2;
+
+     pneg_ctxt->Reserved2 = 0;
+     pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+     /* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+     return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
  static void
  assemble_neg_contexts(struct smb2_negotiate_req *req,
                    struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
              neg_context_count++;
      }
 
+     /* Add implementation ID context */
+     ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+                             pneg_ctxt);
+     *total_len += ctxt_len;
+     pneg_ctxt += ctxt_len;
+     neg_context_count++;
+
      /* check for and add transport_capabilities and signing capabilities */
      req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +32 -0
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
  #define SMB2_TRANSPORT_CAPABILITIES         cpu_to_le16(6)
  #define SMB2_RDMA_TRANSFORM_CAPABILITIES    cpu_to_le16(7)
  #define SMB2_SIGNING_CAPABILITIES           cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID    cpu_to_le16(0xF100)
  #define SMB2_POSIX_EXTENSIONS_AVAILABLE             cpu_to_le16(0x100)
 
  struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
      /*  Followed by padding to 8 byte boundary (required by some servers) */
  } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN  128
+#define SMB2_IMPL_ID_MAX_NAME_LEN    260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN 260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN        64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN 64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN      64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN    64
+
+struct smb2_implementation_id_context {
+     __le16  ContextType; /* 9 */
+     __le16  DataLength;
+     __le32  Reserved;
+     __le16  ImplDomainLength;
+     __le16  ImplNameLength;
+     __le16  ImplVersionLength;
+     __le16  HostNameLength;
+     __le16  OSNameLength;
+     __le16  OSVersionLength;
+     __le16  ArchLength;
+     __le16  Reserved2;
+     /* Followed by variable length UTF-16 strings:
+      * ImplDomain, ImplName, ImplVersion, HostName,
+      * OSName, OSVersion, Arch
+      */
+     __u8    Data[];
+} __packed;
+
  #define POSIX_CTXT_DATA_LEN 16
  struct smb2_posix_neg_context {
      __le16  ContextType; /* 0x100 */
Signature · 2 lines
Regards,
Shyam
#10 lore raw

Hi Shyam,

Quoted 3 lines · Shyam Prasad N

This can be useful for servers like Azure SMB servers, where it is not easy to explain client side behaviour without knowing what exact version of the code is running on the client.

so it is planned that MS is going to implement this in their servers?

I was kind of assuming this which made me wonder why is this made an community extension instead of a protocol feature will full MS backing including inclusion in MS-SMB2.

Thanks!
-slow

#12 lore raw
In reply to Shyam Prasad N
Quoted 9 lines · Shyam Prasad N
Quoted 7 lines · Ralph Boehme

Hi!

I wonder which servers are expected to be implementing this? I suppose this protocol extension is not proposed without a server vendor interested in actually implementing it, otherwise the whole metrics story doesn't make sense.

Quoted 4 lines

Hi Ralph,

This is supposed to give the server an idea of what version of cifs.ko the client is actually running.

I agree with others on this point -- cifs.ko version is useless to match to a particular behaviour or pinpoint a specific bug.

Quoted 3 lines

This can be useful for servers like Azure SMB servers, where it is not easy to explain client side behaviour without knowing what exact version of the code is running on the client.

If the proposal is going to be bidirectional, it would be much better, for cifs.ko, to have servers sending such information to clients instead; even when there's a problem on the server, it'll usually reflect on the client (crashes, misbehaviour, etc).

Also useful for cases where customers don't have direct/easy access to their SMB infrastructure (e.g. external/3rd party hosting, or 1000s of servers mixed with DFS and/or clusters).

Cheers,

Enzo

Quoted 185 lines
Quoted 179 lines

*scratches head*

Thanks!
-slow

Quoted 172 lines · On 3/4/26 1:27 PM, [email protected] wrote:

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
  fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
  fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
  2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
  #include <linux/pagemap.h>
  #include <linux/xattr.h>
  #include <linux/netfs.h>
+#include <linux/utsname.h>
  #include <trace/events/netfs.h>
  #include "cifsglob.h"
  #include "cifsproto.h"
@@ -45,6 +46,7 @@
  #include "cached_dir.h"
  #include "compress.h"
  #include "fs_context.h"
+#include "cifsfs.h"
 
  /*
   *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
      pneg_ctxt->Name[15] = 0x7C;
  }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+     struct nls_table *cp = load_nls_default();
+     struct new_utsname *uts = utsname();
+     const char *impl_domain = "kernel.org";
+     const char *impl_name = "fs/smb/client";
+     const char *os_name = "Linux";
+     unsigned int data_len = 0;
+     __u8 *data_ptr;
+     int len;
+
+     pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+     data_ptr = pneg_ctxt->Data;
+
+     /* ImplDomain */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+                           SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+     pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+                           SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+     pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplVersion - CIFS_VERSION from cifsfs.h */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+                           SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+     pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* HostName - from utsname()->nodename */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+                           SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+     pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+                           SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+     pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSVersion - from utsname()->release */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+                           SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+     pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* Arch - from utsname()->machine */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+                           SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+     pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+     data_len += len * 2;
+
+     pneg_ctxt->Reserved2 = 0;
+     pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+     /* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+     return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
  static void
  assemble_neg_contexts(struct smb2_negotiate_req *req,
                    struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
              neg_context_count++;
      }
 
+     /* Add implementation ID context */
+     ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+                             pneg_ctxt);
+     *total_len += ctxt_len;
+     pneg_ctxt += ctxt_len;
+     neg_context_count++;
+
      /* check for and add transport_capabilities and signing capabilities */
      req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +32 -0
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
  #define SMB2_TRANSPORT_CAPABILITIES         cpu_to_le16(6)
  #define SMB2_RDMA_TRANSFORM_CAPABILITIES    cpu_to_le16(7)
  #define SMB2_SIGNING_CAPABILITIES           cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID    cpu_to_le16(0xF100)
  #define SMB2_POSIX_EXTENSIONS_AVAILABLE             cpu_to_le16(0x100)
 
  struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
      /*  Followed by padding to 8 byte boundary (required by some servers) */
  } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN  128
+#define SMB2_IMPL_ID_MAX_NAME_LEN    260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN 260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN        64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN 64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN      64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN    64
+
+struct smb2_implementation_id_context {
+     __le16  ContextType; /* 9 */
+     __le16  DataLength;
+     __le32  Reserved;
+     __le16  ImplDomainLength;
+     __le16  ImplNameLength;
+     __le16  ImplVersionLength;
+     __le16  HostNameLength;
+     __le16  OSNameLength;
+     __le16  OSVersionLength;
+     __le16  ArchLength;
+     __le16  Reserved2;
+     /* Followed by variable length UTF-16 strings:
+      * ImplDomain, ImplName, ImplVersion, HostName,
+      * OSName, OSVersion, Arch
+      */
+     __u8    Data[];
+} __packed;
+
  #define POSIX_CTXT_DATA_LEN 16
  struct smb2_posix_neg_context {
      __le16  ContextType; /* 0x100 */
Signature · 2 lines
Regards,
Shyam
#11 lore raw
In reply to Ralph Boehme
Quoted 7 lines · Ralph Boehme

Hi Shyam,

Quoted 3 lines · Shyam Prasad N

This can be useful for servers like Azure SMB servers, where it is not easy to explain client side behaviour without knowing what exact version of the code is running on the client.

Quoted 9 lines

so it is planned that MS is going to implement this in their servers?

I was kind of assuming this which made me wonder why is this made an community extension instead of a protocol feature will full MS backing including inclusion in MS-SMB2.

Thanks!
-slow

Hi Ralph,

We are working with the responsible team to get it into MS-SMB2. However, we also wanted to get an early POC and review comments on the proposed draft and the client changes.

Signature · 2 lines
Regards,
Shyam
#13 lore raw
In reply to Enzo Matsumiya
Quoted 11 lines · Enzo Matsumiya
Quoted 9 lines · Shyam Prasad N
Quoted 7 lines · Ralph Boehme

Hi!

I wonder which servers are expected to be implementing this? I suppose this protocol extension is not proposed without a server vendor interested in actually implementing it, otherwise the whole metrics story doesn't make sense.

Quoted 7 lines
Quoted 4 lines

Hi Ralph,

This is supposed to give the server an idea of what version of cifs.ko the client is actually running.

I agree with others on this point -- cifs.ko version is useless to match to a particular behaviour or pinpoint a specific bug.

Acked. Can you suggest an alternative field that will make the matching easier?

Quoted 5 lines
Quoted 4 lines

This can be useful for servers like Azure SMB servers, where it is not easy to explain client side behaviour without knowing what exact version of the code is running on the client.

Quoted 8 lines

If the proposal is going to be bidirectional, it would be much better, for cifs.ko, to have servers sending such information to clients instead; even when there's a problem on the server, it'll usually reflect on the client (crashes, misbehaviour, etc).

Also useful for cases where customers don't have direct/easy access to their SMB infrastructure (e.g. external/3rd party hosting, or 1000s of servers mixed with DFS and/or clusters).

Good point. Let me rework the draft on this.

Quoted 191 lines

Cheers,

Enzo

Quoted 185 lines
Quoted 170 lines

*scratches head*

Thanks!
-slow

Quoted 164 lines · On 3/4/26 1:27 PM, [email protected] wrote:

From: Shyam Prasad N <[email protected]>

MS-SMB2 does not allow any fields for the client to communicate the client version details to the server. This change is a proof-of-concept to add client details in a new negotiate context.

---
  fs/smb/client/smb2pdu.c | 78 +++++++++++++++++++++++++++++++++++++++++
  fs/smb/common/smb2pdu.h | 32 +++++++++++++++++
  2 files changed, 110 insertions(+)
fs/smb/client/smb2pdu.c +78 -0
index ef655acf673df..9c89f6b4a6709 100644
@@ -24,6 +24,7 @@
  #include <linux/pagemap.h>
  #include <linux/xattr.h>
  #include <linux/netfs.h>
+#include <linux/utsname.h>
  #include <trace/events/netfs.h>
  #include "cifsglob.h"
  #include "cifsproto.h"
@@ -45,6 +46,7 @@
  #include "cached_dir.h"
  #include "compress.h"
  #include "fs_context.h"
+#include "cifsfs.h"
 
  /*
   *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -724,6 +726,75 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
      pneg_ctxt->Name[15] = 0x7C;
  }
 
+static unsigned int
+build_implementation_id_ctxt(struct smb2_implementation_id_context *pneg_ctxt)
+{
+     struct nls_table *cp = load_nls_default();
+     struct new_utsname *uts = utsname();
+     const char *impl_domain = "kernel.org";
+     const char *impl_name = "fs/smb/client";
+     const char *os_name = "Linux";
+     unsigned int data_len = 0;
+     __u8 *data_ptr;
+     int len;
+
+     pneg_ctxt->ContextType = SMB2_IMPLEMENTATION_ID_CONTEXT_ID;
+     data_ptr = pneg_ctxt->Data;
+
+     /* ImplDomain */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_domain,
+                           SMB2_IMPL_ID_MAX_DOMAIN_LEN, cp);
+     pneg_ctxt->ImplDomainLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, impl_name,
+                           SMB2_IMPL_ID_MAX_NAME_LEN, cp);
+     pneg_ctxt->ImplNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* ImplVersion - CIFS_VERSION from cifsfs.h */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, CIFS_VERSION,
+                           SMB2_IMPL_ID_MAX_VERSION_LEN, cp);
+     pneg_ctxt->ImplVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* HostName - from utsname()->nodename */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->nodename,
+                           SMB2_IMPL_ID_MAX_HOSTNAME_LEN, cp);
+     pneg_ctxt->HostNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSName */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, os_name,
+                           SMB2_IMPL_ID_MAX_OS_NAME_LEN, cp);
+     pneg_ctxt->OSNameLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* OSVersion - from utsname()->release */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->release,
+                           SMB2_IMPL_ID_MAX_OS_VERSION_LEN, cp);
+     pneg_ctxt->OSVersionLength = cpu_to_le16(len * 2);
+     data_ptr += len * 2;
+     data_len += len * 2;
+
+     /* Arch - from utsname()->machine */
+     len = cifs_strtoUTF16((__le16 *)data_ptr, uts->machine,
+                           SMB2_IMPL_ID_MAX_ARCH_LEN, cp);
+     pneg_ctxt->ArchLength = cpu_to_le16(len * 2);
+     data_len += len * 2;
+
+     pneg_ctxt->Reserved2 = 0;
+     pneg_ctxt->DataLength = cpu_to_le16(data_len + 14); /* 14 = 7 length fields * 2 bytes */
+     /* Context size is DataLength + minimal smb2_neg_context, aligned to 8 */
+     return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);
+}
+
  static void
  assemble_neg_contexts(struct smb2_negotiate_req *req,
                    struct TCP_Server_Info *server, unsigned int *total_len)
@@ -797,6 +868,13 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
              neg_context_count++;
      }
 
+     /* Add implementation ID context */
+     ctxt_len = build_implementation_id_ctxt((struct smb2_implementation_id_context *)
+                             pneg_ctxt);
+     *total_len += ctxt_len;
+     pneg_ctxt += ctxt_len;
+     neg_context_count++;
+
      /* check for and add transport_capabilities and signing capabilities */
      req->NegotiateContextCount = cpu_to_le16(neg_context_count);
 
fs/smb/common/smb2pdu.h +27 -0
index e482c86ceb00d..1ad7b57ce2952 100644
@@ -457,6 +457,7 @@ struct smb2_tree_disconnect_rsp {
  #define SMB2_TRANSPORT_CAPABILITIES         cpu_to_le16(6)
  #define SMB2_RDMA_TRANSFORM_CAPABILITIES    cpu_to_le16(7)
  #define SMB2_SIGNING_CAPABILITIES           cpu_to_le16(8)
+#define SMB2_IMPLEMENTATION_ID_CONTEXT_ID    cpu_to_le16(0xF100)
  #define SMB2_POSIX_EXTENSIONS_AVAILABLE             cpu_to_le16(0x100)
 
  struct smb2_neg_context {
@@ -596,6 +597,37 @@ struct smb2_signing_capabilities {
      /*  Followed by padding to 8 byte boundary (required by some servers) */
  } __packed;
 
+/*
+ * For implementation ID context see MS-SMB2 2.2.3.1.8
+ * Maximum string lengths per specification
+ */
+#define SMB2_IMPL_ID_MAX_DOMAIN_LEN  128
+#define SMB2_IMPL_ID_MAX_NAME_LEN    260
+#define SMB2_IMPL_ID_MAX_VERSION_LEN 260
+#define SMB2_IMPL_ID_MAX_HOSTNAME_LEN        64
+#define SMB2_IMPL_ID_MAX_OS_NAME_LEN 64
+#define SMB2_IMPL_ID_MAX_OS_VERSION_LEN      64
+#define SMB2_IMPL_ID_MAX_ARCH_LEN    64
+
+struct smb2_implementation_id_context {
+     __le16  ContextType; /* 9 */
+     __le16  DataLength;
+     __le32  Reserved;
+     __le16  ImplDomainLength;
+     __le16  ImplNameLength;
+     __le16  ImplVersionLength;
+     __le16  HostNameLength;
+     __le16  OSNameLength;
+     __le16  OSVersionLength;
+     __le16  ArchLength;
+     __le16  Reserved2;
+     /* Followed by variable length UTF-16 strings:
+      * ImplDomain, ImplName, ImplVersion, HostName,
Quoted 9 lines

fs/smb/common/smb2pdu.h struct smb2_signing_capabilities { · line 633

Quoted 8 lines
fs/smb/common/smb2pdu.h +5 -0
+      * OSName, OSVersion, Arch
+      */
+     __u8    Data[];
+} __packed;
+
  #define POSIX_CTXT_DATA_LEN 16
  struct smb2_posix_neg_context {
      __le16  ContextType; /* 0x100 */

--
Regards,
Shyam

Signature · 2 lines
Regards,
Shyam
#14 lore raw
Quoted 15 lines · Shyam Prasad N
Quoted 13 lines · Enzo Matsumiya
Quoted 11 lines · Shyam Prasad N
Quoted 7 lines · Ralph Boehme

Hi!

I wonder which servers are expected to be implementing this? I suppose this protocol extension is not proposed without a server vendor interested in actually implementing it, otherwise the whole metrics story doesn't make sense.

Hi Ralph,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This is supposed to give the server an idea of what version of cifs.ko the client is actually running.

I agree with others on this point -- cifs.ko version is useless to match to a particular behaviour or pinpoint a specific bug.

Acked. Can you suggest an alternative field that will make the matching easier?

Kernel version is useful (major/minor #) but I don't see a problem with using cifs.ko version as well as we do today since we had a few cases where it could be updated for 'full backports' but in any case either of these will help narrow client down a lot.

Signature · 3 lines
Thanks,

Steve