Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796102885; b=JjPSqcOwvBbCNQJ10ikD3Hyugg8DklWqeGf9n6/UHqE60SNzRQPHTqihyzj6f+ZE3kBi jJSl8HxpQVSuH7LbAFkWJqEGBGAKpoCanvGlxYgzat2472L43KVK9aUekEVpY1B0koA15 v7/x6l3v5nnRGK/TIfFwjxPzSTTMdSNWLo8ovhcqAeSqrWseOqwn0yCEMWdtyg90thJBR Zv8tVJrtVzGrTVkalClEOuLUv1UD2SAfMMKNxWRn6jjCWrgcv47vpG3zjUpJi2zAVHgqv vXdfoU/Q1Dhnn+ewI9CKsbxNWqpseUC0YahejW9/w0neXprtxVh0FeTcjk74JtsNfyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796102885; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=92/sIjXzDZ3H315UKdP5unuU6foNr8e8lr/ygZli0L0=; b=xCz3xmxgrwc7yUY882NacYwQ5PemDgEn2/lkJsExLYeJxPekTfV288CfcRIeofEObTK2 anZytiyBMhmjSpwLNWDYFXi6sv1l5091jk8h5QAzdCwfDnHue5wCXM4nU9QiSfGCEl9d6 dUguehXYZMA3barQ5rRhyc7rxhRHGLX/bDowzXG2g+ItEJ7kxv5BSUwfeot2ZQjXEhN4+ 9VFuG3g3zNq40ww29bAt0QhXFLohsuqSwZotXN4nrHOBQzSFYmufR5P3+FblX/9Xkabjf i0qSlOSrVpuN36xag4GL+tadfqFTQGDvu6QM3LUuZRdaV3KRlgdiHh7p7nn1ALmTCEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d9xd1Wuf; arc=none smtp.remote-ip=74.125.229.9 Received: from mail-dy2-f9.google.com (mail-dy2-f9.google.com [74.125.229.9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D20F606A325 for ; Tue, 1 Dec 2026 05:28:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D20F606A325 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.a=rsa-sha256 header.s=20260707 header.b=d9xd1Wuf Received: by mail-dy2-f9.google.com with SMTP id 5a478bee46e88-384d0550c71so5497003eec.0 for ; Mon, 30 Nov 2026 21:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796102884; x=1796707684; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=92/sIjXzDZ3H315UKdP5unuU6foNr8e8lr/ygZli0L0=; b=d9xd1Wufzrutz44LE7/Ys4OcQYoh6sDbqhvpjt1hpy42AL22bNsR+EuEMRdpivlzsD AqzBnnXER4byeR6Ur0wo5VrRjuHL40x5lVrDw0DCDWPWRZhLBopIWHtnvTlujAEA8Ln+ wvrEL4mCgKeWpEzIN/A/WVkdlzkq61EQpBIeHTy8CN+k9m0vhW8mrWJAhzsWhPrqBZrl 3mHiDcP0HD3tfPQLf65gTfWSVkPDhq/I1ee/RIm8fn8XiqMRVe7GB9d6I+d9pTEGHBso RUc40Sv3nJWKhypPp9C1KoJ4ku0lfd43l2JJd/mGnHMTem04poz1CfB8c1C7t3/MFCvS u03Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796102884; x=1796707684; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=92/sIjXzDZ3H315UKdP5unuU6foNr8e8lr/ygZli0L0=; b=f/JjLPgLMYfWtMpNd+AEJvr0RfljAU0mvNfVKlLOnlEZmgBWbH8IFhjqaBrysz7XaI Hed/XmWnTrUsrKXsP60GIhaCwzctvrJfWM7lqm1jF4HVQJB3bjLd/XNv69ixoHMFpAmv 7LKAlAkKxs1PoFqQ+H6cqKMHPcBDQPdZGiUWMHoyoOwjTfCg7+ynwMxbkyrMOvrBIClz 9nOC09zO4f/S1wY9qL1jwjEZPi5ZSd0kxLascUMG+U2hBEALqnDaDnfxRmZnvxvRLqR+ b8sN//uHBhaVUNMnphRDa2YxGU/D/4zSFcag+0vr7wtVtLh5pH5hN0qYxBqFBCDyfwP9 5WEw== X-Forwarded-Encrypted: i=1; AL+hErEt9yTMZ1ULdFhyBNBc4wWqe5GbQaukrV6Wq1qtXTZbElJ501BHf58jUg40bAVQaP/+t+i8ibkTW4xt@vger.kernel.org X-Gm-Message-State: APuU4Z+Zi/0wFXBl5t2Eyb5Theu+CvC5v/LT7Ehers59o8ap8rDrijKL LFhzsyCVnC5dCb5hPRJdIt0992oq2x2SFcE3XqZZbZVLiXWJtCazd8yA X-Gm-Gg: AZFdTZd49Elhh03WtLQuvi5EHVwVNae4J+sS8Qg3bSnvD1PiwFpR/PPimT0AuAc/GfD shJXDESkOK+atn9espBfsXz+rHDy98szqoB5n7+USIz6INgBXhWRjwmvELKPjYBGmASjrbGcFnv IHzjgIoPz3klQiM6qfBBiuMNHFdRoAyU9OpCItU5bOHFMNiHNfNONJSeg3ZHrUaQHuK3tju5Gi9 ljE8Duk6pILEOunivlITr6KLelcpmHSs2wGnB/Re+hRFI8gIVMAfsmmWoM47C8SWELeKZ02SyTL 5orj8Dv10aAaGvLsMLH1s2rm8eVMg+SC3qcaN2ahcNhanAsQZ8E1CDvcc3u+pKO5ugxQHcXvydW QUxN+gaw3e01ggPsKIEm+fZK7FjRp46228FHPUtPOZBtLxqkSRcpWSpYAjpBt3oWcU7yoQGhJM7 Y6oqv5TLlQ8x6zLH16CCT40PSuQl4TBF8wE0MJ8PJy51ysvrDE0Uc+3ZvNmlsofGDe7khERfXD2 EF9l6nI/2vhG6gx1EYEfKpGadLcE+CdQXinZRFYMgexZQoXuzWHVBtMmqtQxSlBAl0fYyVIskwf ApxOSy1s5xKcJ6BL16EpdXYJ3yS0AYGmBXVPfv39 X-Received: by 2002:a05:7301:4718:b0:380:9c6f:ad0a with SMTP id 5a478bee46e88-3856e63b224mr34763261eec.10.1796102884113; Mon, 30 Nov 2026 21:28:04 -0800 (PST) Received: from localhost.localdomain ([111.55.8.72]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c371esm104691970eec.23.2026.11.30.21.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 21:28:03 -0800 (PST) From: Hang Nan To: Ian Bridges Cc: Namjae Jeon , Steve French , Tom Talpey , Sergey Senozhatsky , ChenXiaoSong , linux-cifs@vger.kernel.org, Hang Nan Subject: [PATCH v3] ksmbd: reject a short NTLMv2 key instead of truncating it Date: Tue, 1 Dec 2026 13:26:47 +0800 Message-ID: <20261201052647.10672-1-nanx95726@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201033612.2177557-1-icb@fastmail.org> References: <20261201033612.2177557-1-icb@fastmail.org> X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit calc_ntlmv2_hash() feeds CIFS_ENCPWD_SIZE bytes to hmac_md5_init_usingrawkey() whatever length the daemon sent in LOGIN_RESPONSE.hash_sz. A hash shorter than 16 bytes makes the ksmbd-io worker read past the passkey allocation, and hash_sz 0 allocates ZERO_SIZE_PTR, so the copy reads from 0x10: BUG: KASAN: slab-out-of-bounds in __hmac_md5_preparekey Read of size 16 at addr ffff888007cdf8c0 Workqueue: ksmbd-io handle_ksmbd_work __hmac_md5_preparekey hmac_md5_init_usingrawkey calc_ntlmv2_hash ksmbd_auth_ntlmv2 smb2_sess_setup Padding the key down to hash_sz is not a fix: HMAC-MD5 zero pads a key, so an empty key is the same key as the all-zero 16 byte NT hash, and any client can log in with it. Ian Bridges reproduced that on ksmbd-for-next 4543a3349127 with such a truncation applied: with a ksmbd-tools entry whose password field decodes to no bytes ("alice:A"), an NTLMv2 login using the all-zero NT hash succeeded for a normal, non-guest user. Guest accounts never reach calc_ntlmv2_hash(), so there is nothing to preserve for them: refuse the short key and let the login fail. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Reviewed-by: Ian Bridges Tested-by: Ian Bridges Signed-off-by: Hang Nan --- v3: only reword the paragraph about Ian's reproduction, which happened with the truncation applied rather than on ksmbd-for-next alone; add his Reviewed-by and Tested-by. Truncating the key to hash_sz does not make the login fail: HMAC-MD5 zero pads its key, so an empty key is the same key as the all-zero 16 byte NT hash and any client can log in with it. Guest sessions never reach calc_ntlmv2_hash(), so there is nothing to preserve for them. fs/smb/server/auth.c | 4 ++++ fs/smb/server/mgmt/user_config.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/fs/smb/server/auth.c b/fs/smb/server/auth.c index 0c51ca0cb14d..eafca0038378 100644 --- a/fs/smb/server/auth.c +++ b/fs/smb/server/auth.c @@ -79,6 +79,10 @@ static int calc_ntlmv2_hash(struct ksmbd_conn *conn, struct ksmbd_session *sess, __le16 *uniname = NULL; struct hmac_md5_ctx ctx; + /* a short key would be zero padded by HMAC into a guessable one */ + if (user_passkey_sz(sess->user) < CIFS_ENCPWD_SIZE) + return -EINVAL; + hmac_md5_init_usingrawkey(&ctx, user_passkey(sess->user), CIFS_ENCPWD_SIZE); diff --git a/fs/smb/server/mgmt/user_config.h b/fs/smb/server/mgmt/user_config.h index e116b2ee9917..4011bf3b6d65 100644 --- a/fs/smb/server/mgmt/user_config.h +++ b/fs/smb/server/mgmt/user_config.h @@ -46,6 +46,11 @@ static inline char *user_passkey(struct ksmbd_user *user) return user->passkey; } +static inline size_t user_passkey_sz(struct ksmbd_user *user) +{ + return user->passkey_sz; +} + static inline char *user_name(struct ksmbd_user *user) { return user->name; -- 2.56.1