FAILED: patch "[PATCH] nvmet-auth: validate reply message payload bounds against" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 3a413ece2504c70aa34a20be4dafec04e8c741f9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071506-uncounted-retaliate-5437@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 3a413ece2504c70aa34a20be4dafec04e8c741f9 Mon Sep 17 00:00:00 2001
From: Tianchu Chen <[email protected]>
Date: Fri, 29 May 2026 14:18:39 +0000
Subject: [PATCH] nvmet-auth: validate reply message payload bounds against
transfer length
nvmet_auth_reply() accesses the variable-length rval[] array using attacker-controlled hl (hash length) and dhvlen (DH value length) fields without verifying they fit within the allocated buffer of tl bytes.
A malicious NVMe-oF initiator can craft a DHCHAP_REPLY message with a small transfer length but large hl/dhvlen values, causing out-of-bounds heap reads when the target processes the DH public key (rval + 2*hl) or performs the host response memcmp.
With DH authentication configured, the OOB pointer is passed directly to sg_init_one() and read by crypto_kpp_compute_shared_secret(), reaching up to 526 bytes past the buffer. This is exploitable pre-authentication.
Add bounds validation ensuring sizeof(*data) + 2*hl + dhvlen <= tl before any access to the variable-length fields.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
drivers/nvme/target/fabrics-cmd-auth.c +12 -3
@@ -132,13 +132,22 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d)return 0 ; } -static u8 nvmet_auth_reply (struct nvmet_req *req,void *d) +static u8 nvmet_auth_reply (struct nvmet_req *req,void *d,u32 tl) {struct nvmet_ctrl *ctrl = req->sq->ctrl;struct nvmf_auth_dhchap_reply_data *data = d; -u16 dhvlen =le16_to_cpu (data->dhvlen); +u16 dhvlen;u8 *response; +if (tl <sizeof (*data)) +return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD ; + + dhvlen =le16_to_cpu (data->dhvlen); + +/* Validate that hl and dhvlen fit within the transfer length */ +if (sizeof (*data) +2 * (size_t )data->hl + dhvlen > tl) +return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD ; +pr_debug ("%s: ctrl %d qid %d: data hl %d cvalid %d dhvlen %u\n" , __func__, ctrl->cntlid, req->sq->qid, data->hl, data->cvalid, dhvlen);
@@ -338,7 +347,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req)switch (data->auth_id) {case NVME_AUTH_DHCHAP_MESSAGE_REPLY : - dhchap_status =nvmet_auth_reply (req, d); + dhchap_status =nvmet_auth_reply (req, d, tl);if (dhchap_status ==0 ) req->sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 ;
Sasha Levin
maintainerPATCH 1/3 nvmet: remove superfluous initialization
From: Chaitanya Kulkarni <[email protected]>
[ Upstream commit 8d30528a170905ede9ab6ab81f229e441808590b ]
Remove superfluous initialization of status variable in nvmet_execute_admin_connect() and nvmet_execute_io_connect(), since it will get overwritten by nvmet_copy_from_sgl().
Stable-dep-of: 3a413ece2504 ("nvmet-auth: validate reply message payload bounds against transfer length")
--- drivers/nvme/target/fabrics-cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/fabrics-cmd.c +2 -2
@@ -209,7 +209,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)struct nvmf_connect_command *c = &req->cmd->connect;struct nvmf_connect_data *d;struct nvmet_ctrl *ctrl =NULL ; -u16 status =0 ; +u16 status;int ret;if (!nvmet_check_transfer_len (req,sizeof (struct nvmf_connect_data )))
@@ -287,7 +287,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)struct nvmf_connect_data *d;struct nvmet_ctrl *ctrl;u16 qid =le16_to_cpu (c->qid); -u16 status =0 ; +u16 status;if (!nvmet_check_transfer_len (req,sizeof (struct nvmf_connect_data )))return ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 nvmet: return DHCHAP status codes from nvmet_setup_auth()
From: Hannes Reinecke <[email protected]>
[ Upstream commit 44e3c25efae8575e06f1c5d1dc40058a991e3cb2 ]
A failure in nvmet_setup_auth() does not mean that the NVMe authentication command failed, so we should rather return a protocol error with a 'failure1' response than an NVMe status.
Also update the type used for dhchap_step and dhchap_status to u8 to avoid confusions with nvme status. Furthermore, split dhchap_status and nvme status so we don't accidentally mix these return values.
[dwagner: - use u8 as type for dhchap_{step|status}
- separate nvme status from dhcap_status]
Stable-dep-of: 3a413ece2504 ("nvmet-auth: validate reply message payload bounds against transfer length")
--- drivers/nvme/target/auth.c | 20 +++++------ drivers/nvme/target/fabrics-cmd-auth.c | 49 +++++++++++++------------- drivers/nvme/target/fabrics-cmd.c | 11 +++--- drivers/nvme/target/nvmet.h | 8 ++--- 4 files changed, 43 insertions(+), 45 deletions(-)
drivers/nvme/target/auth.c +8 -12
@@ -125,12 +125,11 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)return ret; } -int nvmet_setup_auth (struct nvmet_ctrl *ctrl) +u8 nvmet_setup_auth (struct nvmet_ctrl *ctrl) {int ret =0 ;struct nvmet_host_link *p;struct nvmet_host *host =NULL ; -const char *hash_name;down_read (&nvmet_config_sem);if (nvmet_is_disc_subsys (ctrl->subsys))
@@ -148,13 +147,16 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) }if (!host) {pr_debug ("host %s not found\n" , ctrl->hostnqn); - ret = -EPERM ; + ret =NVME_AUTH_DHCHAP_FAILURE_FAILED ; goto out_unlock; } ret =nvmet_setup_dhgroup (ctrl, host->dhchap_dhgroup_id); -if (ret <0 ) +if (ret <0 ) {pr_warn ("Failed to setup DH group" ); + ret =NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE ; + goto out_unlock; + }if (!host->dhchap_secret) {pr_debug ("No authentication provided\n" );
@@ -165,12 +167,6 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl)pr_debug ("Re-use existing hash ID %d\n" , ctrl->shash_id); }else { - hash_name =nvme_auth_hmac_name (host->dhchap_hash_id); -if (!hash_name) { -pr_warn ("Hash ID %d invalid\n" , host->dhchap_hash_id); - ret = -EINVAL ; - goto out_unlock; - } ctrl->shash_id = host->dhchap_hash_id; }
@@ -179,7 +175,7 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) ctrl->host_key =nvme_auth_extract_key (host->dhchap_secret +10 , host->dhchap_key_hash);if (IS_ERR (ctrl->host_key)) { - ret =PTR_ERR (ctrl->host_key); + ret =NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE ; ctrl->host_key =NULL ; goto out_free_hash; }
@@ -197,7 +193,7 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) ctrl->ctrl_key =nvme_auth_extract_key (host->dhchap_ctrl_secret +10 , host->dhchap_ctrl_key_hash);if (IS_ERR (ctrl->ctrl_key)) { - ret =PTR_ERR (ctrl->ctrl_key); + ret =NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE ; ctrl->ctrl_key =NULL ; goto out_free_hash; }
drivers/nvme/target/fabrics-cmd-auth.c +25 -24
110 lines not on this page · raw message
drivers/nvme/target/fabrics-cmd.c +6 -5
@@ -210,7 +210,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)struct nvmf_connect_data *d;struct nvmet_ctrl *ctrl =NULL ;u16 status; -int ret; +u8 dhchap_status;if (!nvmet_check_transfer_len (req,sizeof (struct nvmf_connect_data )))return ;
@@ -252,11 +252,12 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)uuid_copy (&ctrl->hostid, &d->hostid); - ret =nvmet_setup_auth (ctrl); -if (ret <0 ) { -pr_err ("Failed to setup authentication, error %d\n" , ret); + dhchap_status =nvmet_setup_auth (ctrl); +if (dhchap_status) { +pr_err ("Failed to setup authentication, dhchap status %u\n" , + dhchap_status);nvmet_ctrl_put (ctrl); -if (ret == -EPERM ) +if (dhchap_status ==NVME_AUTH_DHCHAP_FAILURE_FAILED ) status = (NVME_SC_CONNECT_INVALID_HOST |NVME_SC_DNR );else status =NVME_SC_INTERNAL ;
drivers/nvme/target/nvmet.h +4 -4
@@ -111,8 +111,8 @@ struct nvmet_sq {struct delayed_work auth_expired_work;bool authenticated;u16 dhchap_tid; -u16 dhchap_status; -int dhchap_step; +u8 dhchap_status; +u8 dhchap_step;u8 *dhchap_c1;u8 *dhchap_c2;u32 dhchap_s1;
@@ -705,7 +705,7 @@ void nvmet_execute_auth_receive(struct nvmet_req *req);int nvmet_auth_set_key (struct nvmet_host *host,const char *secret,bool set_ctrl);int nvmet_auth_set_host_hash (struct nvmet_host *host,const char *hash); -int nvmet_setup_auth (struct nvmet_ctrl *ctrl); +u8 nvmet_setup_auth (struct nvmet_ctrl *ctrl);void nvmet_auth_sq_init (struct nvmet_sq *sq);void nvmet_destroy_auth (struct nvmet_ctrl *ctrl);void nvmet_auth_sq_free (struct nvmet_sq *sq);
@@ -724,7 +724,7 @@ int nvmet_auth_ctrl_exponential(struct nvmet_req *req,int nvmet_auth_ctrl_sesskey (struct nvmet_req *req,u8 *buf,int buf_size);#else -static inline int nvmet_setup_auth (struct nvmet_ctrl *ctrl) +static inline u8 nvmet_setup_auth (struct nvmet_ctrl *ctrl) {return 0 ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 nvmet-auth: validate reply message payload bounds against transfer length
In reply to Sasha LevinFrom: Tianchu Chen <[email protected]>
[ Upstream commit 3a413ece2504c70aa34a20be4dafec04e8c741f9 ]
nvmet_auth_reply() accesses the variable-length rval[] array using attacker-controlled hl (hash length) and dhvlen (DH value length) fields without verifying they fit within the allocated buffer of tl bytes.
A malicious NVMe-oF initiator can craft a DHCHAP_REPLY message with a small transfer length but large hl/dhvlen values, causing out-of-bounds heap reads when the target processes the DH public key (rval + 2*hl) or performs the host response memcmp.
With DH authentication configured, the OOB pointer is passed directly to sg_init_one() and read by crypto_kpp_compute_shared_secret(), reaching up to 526 bytes past the buffer. This is exploitable pre-authentication.
Add bounds validation ensuring sizeof(*data) + 2*hl + dhvlen <= tl before any access to the variable-length fields.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/nvme/target/fabrics-cmd-auth.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/nvme/target/fabrics-cmd-auth.c +12 -3
@@ -109,13 +109,22 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d)return 0 ; } -static u8 nvmet_auth_reply (struct nvmet_req *req,void *d) +static u8 nvmet_auth_reply (struct nvmet_req *req,void *d,u32 tl) {struct nvmet_ctrl *ctrl = req->sq->ctrl;struct nvmf_auth_dhchap_reply_data *data = d; -u16 dhvlen =le16_to_cpu (data->dhvlen); +u16 dhvlen;u8 *response; +if (tl <sizeof (*data)) +return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD ; + + dhvlen =le16_to_cpu (data->dhvlen); + +/* Validate that hl and dhvlen fit within the transfer length */ +if (sizeof (*data) +2 * (size_t )data->hl + dhvlen > tl) +return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD ; +pr_debug ("%s: ctrl %d qid %d: data hl %d cvalid %d dhvlen %u\n" , __func__, ctrl->cntlid, req->sq->qid, data->hl, data->cvalid, dhvlen);
@@ -287,7 +296,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req)switch (data->auth_id) {case NVME_AUTH_DHCHAP_MESSAGE_REPLY : - dhchap_status =nvmet_auth_reply (req, d); + dhchap_status =nvmet_auth_reply (req, d, tl);if (dhchap_status ==0 ) req->sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 ;
Signature · 1 line
2.53.0