{"id":2229677,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229677/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428154604.222551-2-henrique.carvalho@suse.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260428154604.222551-2-henrique.carvalho@suse.com>","date":"2026-04-28T15:45:57","name":"[01/11] smb: client: refactor negotiate context assembly","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"ae326e05389f737f5f7d1c5ff624121357bca9ba","submitter":{"id":89563,"url":"http://patchwork.ozlabs.org/api/1.1/people/89563/?format=json","name":"Henrique Carvalho","email":"henrique.carvalho@suse.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428154604.222551-2-henrique.carvalho@suse.com/mbox/","series":[{"id":501882,"url":"http://patchwork.ozlabs.org/api/1.1/series/501882/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501882","date":"2026-04-28T15:45:56","name":"smb: implement SMB over QUIC","version":1,"mbox":"http://patchwork.ozlabs.org/series/501882/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229677/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229677/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11221-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256\n header.s=google header.b=ChL8VG9D;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11221-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com\n header.b=\"ChL8VG9D\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.221.53","smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=suse.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=suse.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4lDn3vw9z1yJH\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 01:47:21 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id BF1C13019C81\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 15:46:46 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id C62783C1400;\n\tTue, 28 Apr 2026 15:46:39 +0000 (UTC)","from mail-wr1-f53.google.com (mail-wr1-f53.google.com\n [209.85.221.53])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 305BB3FD123\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 15:46:36 +0000 (UTC)","by mail-wr1-f53.google.com with SMTP id\n ffacd0b85a97d-43cfbd17589so9109979f8f.0\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 08:46:36 -0700 (PDT)","from precision ([2a01:4b00:c007:bb00:be9d:a3c4:18b1:4a25])\n        by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-4463d4fa52bsm7725384f8f.15.2026.04.28.08.46.34\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 08:46:34 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777391199; cv=none;\n b=DCtHMOyOzeMZqQGpE7yl6CIncEGJPcDE0JwuchuSj7rHt+R4SxSepinr1XJoMweXpmtpH1PEncogfhOyYO5rOWSR7sFFAczvLSsXTkaipm6VKs/BTEhq8G/66PR4oPMmNgAlpb5g2IB19JobPnMclsP/U4++oFBWxLEbOXxB45o=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777391199; c=relaxed/simple;\n\tbh=lQ5DpuALbgTsXOKgwn74AyoacGYenQNBVH9tON40P7o=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=av2WgkmvVfcvUblamUndyIMCvDAF5ATDCohcT8lA8VLfy2pWRT7DtrjWFoVpl8VuV8seB1W08A6no1nft84mxT+V138FG+nw/qh2OdcpD+qzh6oQo9cXZHKJSghihFAXYGDZW6pdo5tADdTdhn6u4HuJzIu80uXVpNwDyZ1sMtQ=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=suse.com;\n spf=pass smtp.mailfrom=suse.com;\n dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com\n header.b=ChL8VG9D; arc=none smtp.client-ip=209.85.221.53","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=suse.com; s=google; t=1777391195; x=1777995995;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=ycsCVSVbXnO73EBGsa9NkUp/8I4UNQARemQ6U5oYXqA=;\n        b=ChL8VG9DQQGbqgwroLvZeihOJObAONP5INjfOpthcnq1gY4gojYUJKlUKoD45lWN9t\n         OjWHP7pljoupGUyLzOQtrMLpLYm1XUBqiTc9XwP/RMHST9YBNcrbBm1ddxOv17qk9712\n         L2Yvp+w+2yU5qRCtxE+gRuu3Rmvn2fbzOYE17XKP6r29SUGfbXC+GX1FfCk1z1kTLL2f\n         1M7eh/Bsck34aFJP8iQvdyt76qh5JL6WYdgWeXIHGCkV/uNmel9YgfzGscigFwHD+P0G\n         IrzihQeHR3ldsS0YBOd0n84ocKVdItUilI7mKaWeU4RyFq4potJ3CiHnsEicUq6I0Wyf\n         dfaw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777391195; x=1777995995;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=ycsCVSVbXnO73EBGsa9NkUp/8I4UNQARemQ6U5oYXqA=;\n        b=mVU7zmIzr+j6wjsTxB4o76D+z0ZoXmDZ3F4qQh2QoBFBlWE6xJg487q6FN8I7gfM1e\n         Q5J94u63iRAHZZ/ux6JXfg+dSPPqqtGqyvy9c0YWzZtALwU+BBsH03aSIJrSAZzGxFWp\n         axO7NdVhipMwigWEH0RxGOOhSmN3W91MmMKccjROP1Z7jCDir3DH5rDIEXvdj/oNHW7M\n         otvAYgZVq4HEaRur61X3WNrX8MpqCh7sV3LDZxvuW/lGlJTSW4o2sz02N3nbALKNLWGN\n         3Oxim9Itv1j1fHhLk/Kp8TYFToBZIOfr6FaiZKeW5S1JkX21a/oWWCGrOsUW121426Dd\n         CtaQ==","X-Gm-Message-State":"AOJu0YwblaIiupjWtUVe1vFsHvpXDZaTaTBbJcxXbRXUWmCsSNNh1UkG\n\t2bWLQ/0zh9qW3ORZTqvLm6/5itWYulgUqyWsnxacUMYa410omT3KWHTqoptTbzb80vaUFa5eP+U\n\t2LWTPqvlIcg==","X-Gm-Gg":"AeBDiesmMOcpzflGC8iiH5nJiUoipBRR4WKMTM3OX21+5hl7iabhCeOf5lwZJOnkkyn\n\tT3pRTEIt5uP9qro6zjS0K/0D0WbDjujCg3nrhzfnjgA9NIOHchs8bi81cXsEyaHl7uXNQiddVPy\n\t+KCkfeYYzwb0uM6Y13ugNBMSW4ZjYlO6Q3oyInuiPShZv9mT+qppI5KXr19zs/Umq55uu3LBOFC\n\tKB6TMLjEjP975TjhC38iDnKCMG6WcZjKJG6v52dpetuTC/Vt4Wz4TZ6SHDShIU3S1fAgV9hOt9p\n\tUySoYqjq2nNc3yF7chTSKBkclc1/LuL8JaKkQfPZfuxuisDpNpZiJpT6jja0G9mIgV5KMgmaD+p\n\t0SbfNdwtH5n31JWw4W1Qe3l6y3b+sSF4CXr8ftwst2DPaBwUOa+gQgSlKzm2H7CLApfArP+urwN\n\t9KNrvweOFd/5nbC4NJGGGLG0rqgZBv+wJdD4M704N2mi2r","X-Received":"by 2002:a05:6000:2212:b0:43c:fc5c:a9fe with SMTP id\n ffacd0b85a97d-4464839c55emr6532758f8f.20.1777391195066;\n        Tue, 28 Apr 2026 08:46:35 -0700 (PDT)","From":"Henrique Carvalho <henrique.carvalho@suse.com>","To":"linux-cifs@vger.kernel.org","Cc":"sfrench@samba.org,\n\tlinkinjeon@kernel.org,\n\tmetze@samba.org,\n\tpc@manguebit.com,\n\tronniesahlberg@gmail.com,\n\tsprasad@microsoft.com,\n\ttom@talpey.com,\n\tbharathsm@microsoft.com,\n\tematsumiya@suse.de,\n\tHenrique Carvalho <henrique.carvalho@suse.com>","Subject":"[PATCH 01/11] smb: client: refactor negotiate context assembly","Date":"Tue, 28 Apr 2026 12:45:57 -0300","Message-ID":"<20260428154604.222551-2-henrique.carvalho@suse.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260428154604.222551-1-henrique.carvalho@suse.com>","References":"<20260428154604.222551-1-henrique.carvalho@suse.com>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Introduce struct neg_ctx, smb2_neg_context_len() and add_context() to\nhandle alignment, pointer advancement, and counter increment in one\nplace, eliminating repetitive code.\n\nAlso fix missing ALIGN() for posix negotiate context.\n\nSigned-off-by: Henrique Carvalho <henrique.carvalho@suse.com>\n---\n fs/smb/client/smb2pdu.c | 106 +++++++++++++++++++++-------------------\n 1 file changed, 56 insertions(+), 50 deletions(-)","diff":"diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c\nindex cddb1ae04e83..bac88a612d5d 100644\n--- a/fs/smb/client/smb2pdu.c\n+++ b/fs/smb/client/smb2pdu.c\n@@ -618,7 +618,15 @@ static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon,\n \n /* For explanation of negotiate contexts see MS-SMB2 section 2.2.3.1 */\n \n-static void\n+static inline unsigned int\n+smb2_neg_context_len(const void *p)\n+{\n+\tconst struct smb2_neg_context *ctx = p;\n+\n+\treturn sizeof(*ctx) + le16_to_cpu(ctx->DataLength);\n+}\n+\n+static unsigned int\n build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt)\n {\n \tpneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES;\n@@ -627,9 +635,10 @@ build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt)\n \tpneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE);\n \tget_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE);\n \tpneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512;\n+\treturn smb2_neg_context_len(pneg_ctxt);\n }\n \n-static void\n+static unsigned int\n build_compression_ctxt(struct smb2_compression_capabilities_context *pneg_ctxt)\n {\n \tpneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES;\n@@ -640,13 +649,13 @@ build_compression_ctxt(struct smb2_compression_capabilities_context *pneg_ctxt)\n \tpneg_ctxt->CompressionAlgorithms[0] = SMB3_COMPRESS_LZ77;\n \tpneg_ctxt->CompressionAlgorithms[1] = SMB3_COMPRESS_LZ77_HUFF;\n \tpneg_ctxt->CompressionAlgorithms[2] = SMB3_COMPRESS_LZNT1;\n+\treturn smb2_neg_context_len(pneg_ctxt);\n }\n \n static unsigned int\n build_signing_ctxt(struct smb2_signing_capabilities *pneg_ctxt)\n {\n-\tunsigned int ctxt_len = sizeof(struct smb2_signing_capabilities);\n-\tunsigned short num_algs = 1; /* number of signing algorithms sent */\n+\tconst unsigned short num_algs = 1; /* number of signing algorithms sent */\n \n \tpneg_ctxt->ContextType = SMB2_SIGNING_CAPABILITIES;\n \t/*\n@@ -658,13 +667,11 @@ build_signing_ctxt(struct smb2_signing_capabilities *pneg_ctxt)\n \tpneg_ctxt->SigningAlgorithmCount = cpu_to_le16(num_algs);\n \tpneg_ctxt->SigningAlgorithms[0] = cpu_to_le16(SIGNING_ALG_AES_CMAC);\n \n-\tctxt_len += sizeof(__le16) * num_algs;\n-\tctxt_len = ALIGN(ctxt_len, 8);\n-\treturn ctxt_len;\n+\treturn smb2_neg_context_len(pneg_ctxt);\n \t/* TBD add SIGNING_ALG_AES_GMAC and/or SIGNING_ALG_HMAC_SHA256 */\n }\n \n-static void\n+static unsigned int\n build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)\n {\n \tpneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES;\n@@ -684,6 +691,7 @@ build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)\n \t\tpneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM;\n \t\tpneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM;\n \t}\n+\treturn smb2_neg_context_len(pneg_ctxt);\n }\n \n static unsigned int\n@@ -695,11 +703,11 @@ build_netname_ctxt(struct smb2_netname_neg_context *pneg_ctxt, char *hostname)\n \n \t/* copy up to max of first 100 bytes of server name to NetName field */\n \tpneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp));\n-\t/* context size is DataLength + minimal smb2_neg_context */\n-\treturn ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8);\n+\n+\treturn smb2_neg_context_len(pneg_ctxt);\n }\n \n-static void\n+static unsigned int\n build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)\n {\n \tpneg_ctxt->ContextType = SMB2_POSIX_EXTENSIONS_AVAILABLE;\n@@ -721,15 +729,31 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)\n \tpneg_ctxt->Name[13] = 0x8B;\n \tpneg_ctxt->Name[14] = 0xCD;\n \tpneg_ctxt->Name[15] = 0x7C;\n+\treturn smb2_neg_context_len(pneg_ctxt);\n+}\n+\n+struct neg_ctx {\n+\tchar *pos;\n+\tunsigned int len;\n+\tunsigned int cnt;\n+};\n+\n+static inline void\n+add_context(struct neg_ctx *nc, unsigned int ctx_len)\n+{\n+\tunsigned int aligned_len = ALIGN(ctx_len, 8);\n+\n+\tnc->pos += aligned_len;\n+\tnc->len += aligned_len;\n+\tnc->cnt++;\n }\n \n static void\n assemble_neg_contexts(struct smb2_negotiate_req *req,\n \t\t      struct TCP_Server_Info *server, unsigned int *total_len)\n {\n-\tunsigned int ctxt_len, neg_context_count;\n+\tstruct neg_ctx nc;\n \tstruct TCP_Server_Info *pserver;\n-\tchar *pneg_ctxt;\n \tchar *hostname;\n \n \tif (*total_len > 200) {\n@@ -744,18 +768,15 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,\n \t */\n \t*total_len = ALIGN(*total_len, 8);\n \n-\tpneg_ctxt = (*total_len) + (char *)req;\n \treq->NegotiateContextOffset = cpu_to_le32(*total_len);\n \n-\tbuild_preauth_ctxt((struct smb2_preauth_neg_context *)pneg_ctxt);\n-\tctxt_len = ALIGN(sizeof(struct smb2_preauth_neg_context), 8);\n-\t*total_len += ctxt_len;\n-\tpneg_ctxt += ctxt_len;\n+\tnc.pos = (*total_len) + (char *)req;\n+\tnc.len = *total_len;\n+\tnc.cnt = 0;\n+\n+\tadd_context(&nc, build_preauth_ctxt((struct smb2_preauth_neg_context *)nc.pos));\n \n-\tbuild_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt);\n-\tctxt_len = ALIGN(sizeof(struct smb2_encryption_neg_context), 8);\n-\t*total_len += ctxt_len;\n-\tpneg_ctxt += ctxt_len;\n+\tadd_context(&nc, build_encrypt_ctxt((struct smb2_encryption_neg_context *)nc.pos));\n \n \t/*\n \t * secondary channels don't have the hostname field populated\n@@ -764,41 +785,26 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,\n \tpserver = SERVER_IS_CHAN(server) ? server->primary_server : server;\n \tcifs_server_lock(pserver);\n \thostname = pserver->hostname;\n-\tif (hostname && (hostname[0] != 0)) {\n-\t\tctxt_len = build_netname_ctxt((struct smb2_netname_neg_context *)pneg_ctxt,\n-\t\t\t\t\t      hostname);\n-\t\t*total_len += ctxt_len;\n-\t\tpneg_ctxt += ctxt_len;\n-\t\tneg_context_count = 3;\n-\t} else\n-\t\tneg_context_count = 2;\n+\tif (hostname && (hostname[0] != 0))\n+\t\tadd_context(&nc,\n+\t\t\t    build_netname_ctxt((struct smb2_netname_neg_context *)nc.pos,\n+\t\t\t\t\t       hostname));\n \tcifs_server_unlock(pserver);\n \n-\tbuild_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt);\n-\t*total_len += sizeof(struct smb2_posix_neg_context);\n-\tpneg_ctxt += sizeof(struct smb2_posix_neg_context);\n-\tneg_context_count++;\n+\tadd_context(&nc, build_posix_ctxt((struct smb2_posix_neg_context *)nc.pos));\n \n-\tif (server->compression.requested) {\n-\t\tbuild_compression_ctxt((struct smb2_compression_capabilities_context *)\n-\t\t\t\tpneg_ctxt);\n-\t\tctxt_len = ALIGN(sizeof(struct smb2_compression_capabilities_context), 8);\n-\t\t*total_len += ctxt_len;\n-\t\tpneg_ctxt += ctxt_len;\n-\t\tneg_context_count++;\n-\t}\n+\tif (server->compression.requested)\n+\t\tadd_context(&nc,\n+\t\t\t    build_compression_ctxt(\n+\t\t\t\t    (struct smb2_compression_capabilities_context *)nc.pos));\n \n-\tif (enable_negotiate_signing) {\n-\t\tctxt_len = build_signing_ctxt((struct smb2_signing_capabilities *)\n-\t\t\t\tpneg_ctxt);\n-\t\t*total_len += ctxt_len;\n-\t\tpneg_ctxt += ctxt_len;\n-\t\tneg_context_count++;\n-\t}\n+\tif (enable_negotiate_signing)\n+\t\tadd_context(&nc, build_signing_ctxt((struct smb2_signing_capabilities *)nc.pos));\n \n \t/* check for and add transport_capabilities and signing capabilities */\n-\treq->NegotiateContextCount = cpu_to_le16(neg_context_count);\n+\treq->NegotiateContextCount = cpu_to_le16(nc.cnt);\n \n+\t*total_len = nc.len;\n }\n \n /* If invalid preauth context warn but use what we requested, SHA-512 */\n","prefixes":["01/11"]}