{"id":2220132,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2220132/?format=json","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.0/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":"<2026040647-reset-uninstall-1145@gregkh>","date":"2026-04-06T13:46:48","name":"[3/3] ksmbd: fix mechToken leak when SPNEGO decode fails after token alloc","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5487e4700b13cb5409913143b30c361f4296fddf","submitter":{"id":11800,"url":"http://patchwork.ozlabs.org/api/1.0/people/11800/?format=json","name":"Greg Kroah-Hartman","email":"gregkh@linuxfoundation.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/2026040647-reset-uninstall-1145@gregkh/mbox/","series":[{"id":498855,"url":"http://patchwork.ozlabs.org/api/1.0/series/498855/?format=json","date":"2026-04-06T13:46:46","name":"ksmbd: some potential bugfixes","version":1,"mbox":"http://patchwork.ozlabs.org/series/498855/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220132/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-10678-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 (1024-bit key;\n unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org\n header.a=rsa-sha256 header.s=korg header.b=1eJ/mcVd;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10678-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=linuxfoundation.org\n header.i=@linuxfoundation.org header.b=\"1eJ/mcVd\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::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 4fq9dX3nn4z1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 06 Apr 2026 23:48:16 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 18F81302C5F1\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  6 Apr 2026 13:47:10 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 9223C221275;\n\tMon,  6 Apr 2026 13:47:09 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B9ED14BF92;\n\tMon,  6 Apr 2026 13:47:09 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 86E06C2BC9E;\n\tMon,  6 Apr 2026 13:47:08 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775483229; cv=none;\n b=mOxEGU5O1B54MmWrGI8fLXwohQGAs7p2FeD45yydhKk8A4pefflqvyu8NvJg2DAkzgehpn2419ZAOz3bTV5Ao4WlRWFuWHLL+feYvbLCfo/xONm4iKHae4D4+s6KQyhBXmYVKnkXl4pwNE2+ASUKl7SMpUeGcJ+IujPZdQ/uWgg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775483229; c=relaxed/simple;\n\tbh=4ZQRFVzdUCijd8idg1rAWi6+HbzaURjFDDhmzLTKBPU=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=KXWKjz2ByVf4OCk0sKMPFK96xtRYLfsKpGt+POLtnshXpXs+E64biiz/SfxV9EAwwWpOMb/NrB0lvvUbgDt1IPZ7hG+u6RM+jwAAw6N/9w19l6dioPptXHGUFJoL+IQ9cdRLFjFHAU2c8xTDA0kq07jaOunF0YBNFQ6NLxcZkko=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (1024-bit key) header.d=linuxfoundation.org\n header.i=@linuxfoundation.org header.b=1eJ/mcVd;\n arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org;\n\ts=korg; t=1775483229;\n\tbh=4ZQRFVzdUCijd8idg1rAWi6+HbzaURjFDDhmzLTKBPU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=1eJ/mcVd3fMZ6m3/BWlT1UZwgIiCtE2SPxk9SaIE1naduA0M3HGVf0yJnWxVW4vr6\n\t yorsihbLnZ8BPbK66ozekiC6J9gZzfwrFYcypmgpm5JcKo/9fjnrsbrODv8Spsszpt\n\t 8ziLXJLKo7bWfuwDEzitK92lufx+A8xvOX87e/e4=","From":"Greg Kroah-Hartman <gregkh@linuxfoundation.org>","To":"linux-cifs@vger.kernel.org","Cc":"linux-kernel@vger.kernel.org,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tNamjae Jeon <linkinjeon@kernel.org>,\n\tSteve French <smfrench@gmail.com>,\n\tSergey Senozhatsky <senozhatsky@chromium.org>,\n\tTom Talpey <tom@talpey.com>,\n\tstable <stable@kernel.org>","Subject":"[PATCH 3/3] ksmbd: fix mechToken leak when SPNEGO decode fails after\n token alloc","Date":"Mon,  6 Apr 2026 15:46:48 +0200","Message-ID":"<2026040647-reset-uninstall-1145@gregkh>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<2026040644-brussels-dab-6f99@gregkh>","References":"<2026040644-brussels-dab-6f99@gregkh>","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","Lines":"68","X-Developer-Signature":"v=1; a=openpgp-sha256; l=2611;\n i=gregkh@linuxfoundation.org; h=from:subject:message-id;\n bh=4ZQRFVzdUCijd8idg1rAWi6+HbzaURjFDDhmzLTKBPU=;\n b=owGbwMvMwCRo6H6F97bub03G02pJDJmXd7r/q+V5ZHeAwbvDvqp/SfnK1mPVKXOYVNkEjO9sM\n GLf1LCyI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACby/inDggW+lQWPis6FrDjd\n 9qXZy/aMh1uLN8P8qJq4zVP3X2FRvaw0p+9s3ovlekfcAA==","X-Developer-Key":"i=gregkh@linuxfoundation.org; a=openpgp;\n fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29","Content-Transfer-Encoding":"8bit"},"content":"The kernel ASN.1 BER decoder calls action callbacks incrementally as it\nwalks the input.  When ksmbd_decode_negTokenInit() reaches the mechToken\n[2] OCTET STRING element, ksmbd_neg_token_alloc() allocates\nconn->mechToken immediately via kmemdup_nul().  If a later element in\nthe same blob is malformed, then the decoder will return nonzero after\nthe allocation is already live.  This could happen if mechListMIC [3]\noverrunse the enclosing SEQUENCE.\n\ndecode_negotiation_token() then sets conn->use_spnego = false because\nboth the negTokenInit and negTokenTarg grammars failed.  The cleanup at\nthe bottom of smb2_sess_setup() is gated on use_spnego:\n\n\tif (conn->use_spnego && conn->mechToken) {\n\t\tkfree(conn->mechToken);\n\t\tconn->mechToken = NULL;\n\t}\n\nso the kfree is skipped, causing the mechToken to never be freed.\n\nThis codepath is reachable pre-authentication, so untrusted clients can\ncause slow memory leaks on a server without even being properly\nauthenticated.\n\nFix this up by not checking check for use_spnego, as it's not required,\nso the memory will always be properly freed.  At the same time, always\nfree the memory in ksmbd_conn_free() incase some other failure path\nforgot to free it.\n\nCc: Namjae Jeon <linkinjeon@kernel.org>\nCc: Steve French <smfrench@gmail.com>\nCc: Sergey Senozhatsky <senozhatsky@chromium.org>\nCc: Tom Talpey <tom@talpey.com>\nCc: linux-cifs@vger.kernel.org\nCc: stable <stable@kernel.org>\nAssisted-by: gregkh_clanker_t1000\nSigned-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\n---\n fs/smb/server/connection.c | 1 +\n fs/smb/server/smb2pdu.c    | 2 +-\n 2 files changed, 2 insertions(+), 1 deletion(-)","diff":"diff --git a/fs/smb/server/connection.c b/fs/smb/server/connection.c\nindex 1bb2081c492c..26cfce344861 100644\n--- a/fs/smb/server/connection.c\n+++ b/fs/smb/server/connection.c\n@@ -96,6 +96,7 @@ void ksmbd_conn_free(struct ksmbd_conn *conn)\n \txa_destroy(&conn->sessions);\n \tkvfree(conn->request_buf);\n \tkfree(conn->preauth_info);\n+\tkfree(conn->mechToken);\n \tif (atomic_dec_and_test(&conn->refcnt)) {\n \t\tconn->transport->ops->free_transport(conn->transport);\n \t\tkfree(conn);\ndiff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c\nindex 6f658dc20758..a344937595f4 100644\n--- a/fs/smb/server/smb2pdu.c\n+++ b/fs/smb/server/smb2pdu.c\n@@ -1915,7 +1915,7 @@ int smb2_sess_setup(struct ksmbd_work *work)\n \telse if (rc)\n \t\trsp->hdr.Status = STATUS_LOGON_FAILURE;\n \n-\tif (conn->use_spnego && conn->mechToken) {\n+\tif (conn->mechToken) {\n \t\tkfree(conn->mechToken);\n \t\tconn->mechToken = NULL;\n \t}\n","prefixes":["3/3"]}