From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0276453482 for ; Thu, 7 May 2026 16:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778172752; cv=none; b=fjM3VF87G9zrAfsUsaq+wMHgJ2x5dbJFtl8RxZqOidaqZpHSFOuVknsYrA96rQ1MZSJHeT7+KhUjiOpdjEdUSjahRaXKfc20DOdjn0HE/yJVtcXEeHiZKDmm0SH6TIx5CNvaWcrc6yAO+LzHvVw7HSKh8Cj5ToQPCfdJCrBr05o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778172752; c=relaxed/simple; bh=aHoBqTbdr56DO71Zlzzaandq5SHQ8sCJYyYln2KmSW0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t6Te4ldjqWQ4kTnyKbpC77fYq0S5ip13Cti3hVznUL5zswLUf5J7B3BgDoMbaoTTgpBXoB6cKJB4X0fKGnBsrGv+G5fDSiakjFFrqi0jWYAtHVDLTZ+nG0ZQsKa9IWc7memvB+Q8B7sZqo92d75lIJD97xTg/USbWR9Hud9a/AM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hLOKaJ2P; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hLOKaJ2P" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2b9ea536877so8108725ad.1 for ; Thu, 07 May 2026 09:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778172749; x=1778777549; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yv2fHWPI4GY7ycdmc2I4lTP92YQsllQ8O6sfU4iOItg=; b=hLOKaJ2PpTO1yTKqpMknJRZzPhXHNq7xaXp8V5BnrxFTCvd0QcDK0DZAgm9VzK5bTT Bux/AzMC2D7MJSLwhzTFDYnZc/PcFfAPrt8RjuB79Xlff9UFigczDKCeflfeCkGTz2G7 HABg0Kz931SdXv4whao41c0gDBwe/KKq6Y93up4S8hhGD6St0cVinpDlhAcwwesiCqFs Z31FaqJ6koWowukjj/sUlfYD1qGPef56yjJbpvWTC/ZDLJf7Or6GBkk1inCS5dXXNvHH TEnPVgXz9V6ixzjwa7SYJTbCt+ZIiVAH4LzRzP2VOMF76lXLsF0xCUxlnpIInpu0Rg1C y0zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778172749; x=1778777549; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=yv2fHWPI4GY7ycdmc2I4lTP92YQsllQ8O6sfU4iOItg=; b=NZxJdH6LfCfQLx4VrrZckn9YHEu2C9Xk41wc6+kmgahU9lG4EDr/Kg5dOKhU44gTok 3rXcq48EApeCgA8jLeW8dtJyepuescTdvPlsCB6YGsZqsqIrtZVKuzsOFJAq1lZwwugv hCnOpsWvW4+kWPdvXNu5k79wl69kvMVcES48mZQhGkChtCR9bANmW6WCqcZeuvjdZoSU 8Rt+tAOCkwh5jBwqHl7BqoJ6yGyqSEqGsoJBvKMHlru+c3l1DpKHGOiD1J/jcce9EWrx mrbbWqp4CnWDJXmmN+N3ODIf2m74SRrRPQbp4dxhyyxoKNoWjvaV909dYNOOM2ttsfD9 q08g== X-Forwarded-Encrypted: i=1; AFNElJ9ldVg+/1MFhC4GCqb7NyFVt8OijcFDeRkvoeqUnLw99ma/w699kTxpQSq/0JcvKs7JzdC7cubLKFdhN1g=@vger.kernel.org X-Gm-Message-State: AOJu0Yy40oNqmz8mSarVE1dnKwatxoyQ+O/6CNgVrXAmXzTwPiZBMggv dM0e0QNO1bdKXt6Z1k6g1M9HDaE7m5uZnG5V9ubJAaU/HCE0YYwFPsZY X-Gm-Gg: Acq92OFmhErMdF9RM9pv8bz8PQ56HkqU/LY2PxPh7wentKOhWIdOT8SvqhRPfN5VuzV LGCRkkG8KpCZIEMI1e0ewwf8lRKT2wEiymKzP7IebD3JXDrwUHvil6z1WMgS4exxaM5Oyxgp62b d5LaxLSck49d+nlSm621EMCnPOlw/86avc5P/nn2Bcq9cQKMImGllpVfMloe83YhK9TjnfCzlvQ EFXAYijPfUqJvrBkV/O6khsKKqlCs8IUbS0pTSzFyHrYvB4K7bVAaBnNfB9fqCxgEHr4STu3vgJ Oklkq9OaJo6X0GWmq3iG/nY+xAlG0Fe/Pim0VOFlu9QmwIEo9ApiZ0o8WZs0VEg+WBU7353Q6AI loAmYVvv6B6zUOh3lqSNGCcyuzvOwBriNYHN5VtfaJoKlGl/biNhj9sCqXcTgx4R+azwWV3EJLB NzBMsbQpnVc0/Zi18Q1ZXXGo1ErEF2Tff7j2QxGmo= X-Received: by 2002:a17:903:4b03:b0:2ba:21c2:d6cb with SMTP id d9443c01a7336-2babd4bdb6dmr31502595ad.16.1778172749225; Thu, 07 May 2026 09:52:29 -0700 (PDT) Received: from localhost ([49.207.150.30]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bae783dc50sm2551575ad.43.2026.05.07.09.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 09:52:28 -0700 (PDT) From: Piyush Sachdeva X-Google-Original-From: Piyush Sachdeva Date: Thu, 07 May 2026 22:22:14 +0530 Subject: [PATCH v3 2/2] smb: client: Zero-pad short GSS session keys per MS-SMB2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260507-kerbmi-v3-2-397ebbb53eff@microsoft.com> References: <20260507-kerbmi-v3-0-397ebbb53eff@microsoft.com> In-Reply-To: <20260507-kerbmi-v3-0-397ebbb53eff@microsoft.com> To: Steve French , linux-cifs@vger.kernel.org, Shyam Prasad N , Bharath SM , Paulo Alcantara , Ronnie Sahlberg , Tom Talpey Cc: samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, vaibsharma@microsoft.com X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3414; i=psachdeva@microsoft.com; h=from:subject:message-id; bh=aHoBqTbdr56DO71Zlzzaandq5SHQ8sCJYyYln2KmSW0=; b=owGbwMvMwCV29FJ3ncRHDT/G02pJDJl/Djv5n01fPnF6wi83E+7DM3gmtQm4HoiepBY1uZTl8 JPUFofrHRNZGMS4GCzFFFk2nLgjyxu/S3LepydGMHNYmUCGSIs0MAABCwNfbmJeqZGOkZ6ptqGe oZGOgY4xAxenAEz1rmhGhl3Z+fqduVN3PKrUWPizViSXMyR50q3G2+V9rS87JQqKuRkZDv53CLH Zq7rpwDS+S/4HPjx+HeCpof6Laa5EUNHBg5X5TAA= X-Developer-Key: i=psachdeva@microsoft.com; a=openpgp; fpr=80350F71F916134953C3EB979E19C6F9839C3CFC Per MS-SMB2 section 3.2.5.3, Session.SessionKey is the first 16 bytes of the GSS cryptographic key, right-padded with zero bytes if the key is shorter than 16 bytes. SMB2_auth_kerberos() copies the GSS session key from the cifs.upcall response using kmemdup(msg->data, msg->sesskey_len, ...) and stores the GSS-reported length verbatim in ses->auth_key.len. generate_key() reads SMB2_NTLMV2_SESSKEY_SIZE bytes from this buffer when feeding the HMAC-SHA256 KDF for signing key derivation. If a GSS mechanism returns a session key shorter than 16 bytes (e.g. a deprecated single-DES Kerberos enctype with an 8-byte session key), the KDF call performs an out-of-bounds slab read and derives keys that do not match the server, which pads per the spec. Modern KDCs disable short-key enctypes by default, so this is latent rather than reachable in production, but it is still a kernel heap over-read. Allocate auth_key.response with kzalloc() at a length of max(msg->sesskey_len, SMB2_NTLMV2_SESSKEY_SIZE), copy the GSS key in, and rely on kzalloc()'s zero initialization for the spec-mandated padding. Set ses->auth_key.len to the padded length. Larger GSS keys (e.g. the 32-byte aes256-cts-hmac-sha1-96 session key) continue to be stored at their natural length, preserving the FullSessionKey path. Emit a cifs_dbg(VFS, ...) message when a short key is encountered to surface deprecated-enctype usage. NTLMv2 and NTLMSSP code paths produce a 16-byte session key by construction and are unaffected. Signed-off-by: Piyush Sachdeva Signed-off-by: Piyush Sachdeva --- fs/smb/client/smb2pdu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index cb61051f9af3..995fcdd30681 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -1713,17 +1713,30 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) is_binding = (ses->ses_status == SES_GOOD); spin_unlock(&ses->ses_lock); + /* + * Per MS-SMB2 3.2.5.3, Session.SessionKey is the first 16 bytes of the + * GSS cryptographic key, right-padded with zero bytes if shorter. + * Allocate at least SMB2_NTLMV2_SESSKEY_SIZE bytes (zeroed) so the KDF + * input buffer is always valid for HMAC-SHA256 even with deprecated + * Kerberos enctypes that return a short session key. + */ + if (unlikely(msg->sesskey_len < SMB2_NTLMV2_SESSKEY_SIZE)) + cifs_dbg(VFS, + "short GSS session key (%u bytes); zero-padding per MS-SMB2 3.2.5.3\n", + msg->sesskey_len); + kfree_sensitive(ses->auth_key.response); - ses->auth_key.response = kmemdup(msg->data, - msg->sesskey_len, - GFP_KERNEL); + ses->auth_key.len = max_t(unsigned int, msg->sesskey_len, + SMB2_NTLMV2_SESSKEY_SIZE); + ses->auth_key.response = kzalloc(ses->auth_key.len, GFP_KERNEL); if (!ses->auth_key.response) { cifs_dbg(VFS, "%s: can't allocate (%u bytes) memory\n", - __func__, msg->sesskey_len); + __func__, ses->auth_key.len); + ses->auth_key.len = 0; rc = -ENOMEM; goto out_put_spnego_key; } - ses->auth_key.len = msg->sesskey_len; + memcpy(ses->auth_key.response, msg->data, msg->sesskey_len); sess_data->iov[1].iov_base = msg->data + msg->sesskey_len; sess_data->iov[1].iov_len = msg->secblob_len; -- 2.53.0