FAILED: patch "[PATCH] nvmet-auth: reject short AUTH_RECEIVE buffers" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x 779575bc35c687697ba69e904f2cd22e60112534
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072058-flattery-mammogram-5fea@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 779575bc35c687697ba69e904f2cd22e60112534 Mon Sep 17 00:00:00 2001
From: Michael Bommarito <[email protected]>
Date: Tue, 9 Jun 2026 14:24:31 -0400
Subject: [PATCH] nvmet-auth: reject short AUTH_RECEIVE buffers
nvmet_execute_auth_receive() trusts the AUTH_RECEIVE allocation length after checking only that it is nonzero and matches the transfer length. In the SUCCESS1 and FAILURE1/default states, that lets a remote NVMe-oF initiator reach the fixed-size DH-HMAC-CHAP response builders with a kmalloc() buffer shorter than the response, so nvmet_auth_success1() and nvmet_auth_failure1() write past the allocation; both only WARN_ON the short length and then format the message anyway.
Impact: A remote NVMe-oF initiator with access to an auth-enabled target can trigger a 16-byte heap out-of-bounds write via a one-byte AUTH_RECEIVE allocation length.
Compute the minimum response length for the current DH-HMAC-CHAP step in nvmet_auth_receive_data_len() and report a zero data length when the host-supplied allocation length is shorter, so the existing zero-length check in nvmet_execute_auth_receive() rejects the command before any builder runs. The SUCCESS1 minimum is sizeof(struct nvmf_auth_dhchap_success1_data) plus the HMAC hash length, because the response hash is written into the rval[] flexible-array tail, so the minimum is state dependent rather than a flat sizeof. CHALLENGE keeps its existing variable-length guard in nvmet_auth_challenge().
This is reachable only when in-band DH-HMAC-CHAP authentication is configured on the target.
drivers/nvme/target/fabrics-cmd-auth.c +25 -1
@@ -493,7 +493,31 @@ static void nvmet_auth_failure1(struct nvmet_req *req, void *d, int al)u32 nvmet_auth_receive_data_len (struct nvmet_req *req) { -return le32_to_cpu (req->cmd->auth_receive.al); +struct nvmet_ctrl *ctrl = req->sq->ctrl; +u32 al =le32_to_cpu (req->cmd->auth_receive.al); +u32 min_len; + +/* +* Reject too-short al before kmalloc(al), since the SUCCESS1 and +* FAILURE1/default builders write fixed response headers into it. +*/ +switch (req->sq->dhchap_step) { +case NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE : +return al; +case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 : + min_len =sizeof (struct nvmf_auth_dhchap_success1_data ); +if (req->sq->dhchap_c2) + min_len +=nvme_auth_hmac_hash_len (ctrl->shash_id); +break ; +default : + min_len =sizeof (struct nvmf_auth_dhchap_failure_data ); +break ; + } + +if (al < min_len) +return 0 ; + +return al; }void nvmet_execute_auth_receive (struct nvmet_req *req)
Sasha Levin
maintainerPATCH 1/2 nvmet: Introduce nvmet_req_transfer_len()
From: Damien Le Moal <[email protected]>
[ Upstream commit 43043c9b97258a008b3402cfbbf1c5d82151c77f ]
Add the new function nvmet_req_transfer_len() to parse a request command to extract the transfer length of the command. This function implementation relies on multiple helper functions for parsing I/O commands (nvmet_io_cmd_transfer_len()), admin commands (nvmet_admin_cmd_data_len()) and fabrics connect commands (nvmet_connect_cmd_data_len).
Stable-dep-of: 779575bc35c6 ("nvmet-auth: reject short AUTH_RECEIVE buffers")
--- drivers/nvme/target/admin-cmd.c | 21 +++++++++++++ drivers/nvme/target/core.c | 37 ++++++++++++++++++++++ drivers/nvme/target/discovery.c | 14 +++++++++ drivers/nvme/target/fabrics-cmd-auth.c | 14 +++++++-- drivers/nvme/target/fabrics-cmd.c | 43 ++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 8 +++++ 6 files changed, 135 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +21 -0
@@ -1008,6 +1008,27 @@ void nvmet_execute_keep_alive(struct nvmet_req *req)nvmet_req_complete (req, status); } +u32 nvmet_admin_cmd_data_len (struct nvmet_req *req) +{ +struct nvme_command *cmd = req->cmd; + +if (nvme_is_fabrics (cmd)) +return nvmet_fabrics_admin_cmd_data_len (req); +if (nvmet_is_disc_subsys (nvmet_req_subsys (req))) +return nvmet_discovery_cmd_data_len (req); + +switch (cmd->common.opcode) { +case nvme_admin_get_log_page: +return nvmet_get_log_page_len (cmd); +case nvme_admin_identify: +return NVME_IDENTIFY_DATA_SIZE ; +case nvme_admin_get_features: +return nvmet_feat_data_len (req,le32_to_cpu (cmd->common.cdw10)); +default : +return 0 ; + } +} +u16 nvmet_parse_admin_cmd (struct nvmet_req *req) {struct nvme_command *cmd = req->cmd;
drivers/nvme/target/core.c +37 -0
@@ -891,6 +891,33 @@ static inline u16 nvmet_io_cmd_check_access(struct nvmet_req *req)return 0 ; } +static u32 nvmet_io_cmd_transfer_len (struct nvmet_req *req) +{ +struct nvme_command *cmd = req->cmd; +u32 metadata_len =0 ; + +if (nvme_is_fabrics (cmd)) +return nvmet_fabrics_io_cmd_data_len (req); + +if (!req->ns) +return 0 ; + +switch (req->cmd->common.opcode) { +case nvme_cmd_read: +case nvme_cmd_write: +case nvme_cmd_zone_append: +if (req->sq->ctrl->pi_support &&nvmet_ns_has_pi (req->ns)) + metadata_len =nvmet_rw_metadata_len (req); +return nvmet_rw_data_len (req) + metadata_len; +case nvme_cmd_dsm: +return nvmet_dsm_len (req); +case nvme_cmd_zone_mgmt_recv: +return (le32_to_cpu (req->cmd->zmr.numd) +1 ) <<2 ; +default : +return 0 ; + } +} +static u16 nvmet_parse_io_cmd (struct nvmet_req *req) {struct nvme_command *cmd = req->cmd;
@@ -1015,6 +1042,16 @@ void nvmet_req_uninit(struct nvmet_req *req) }EXPORT_SYMBOL_GPL (nvmet_req_uninit); +size_t nvmet_req_transfer_len (struct nvmet_req *req) +{ +if (likely (req->sq->qid !=0 )) +return nvmet_io_cmd_transfer_len (req); +if (unlikely (!req->sq->ctrl)) +return nvmet_connect_cmd_data_len (req); +return nvmet_admin_cmd_data_len (req); +} +EXPORT_SYMBOL_GPL (nvmet_req_transfer_len); +bool nvmet_check_transfer_len (struct nvmet_req *req,size_t len) {if (unlikely (len != req->transfer_len)) {
drivers/nvme/target/discovery.c +14 -0
@@ -373,6 +373,20 @@ static void nvmet_execute_disc_get_features(struct nvmet_req *req)nvmet_req_complete (req, stat); } +u32 nvmet_discovery_cmd_data_len (struct nvmet_req *req) +{ +struct nvme_command *cmd = req->cmd; + +switch (cmd->common.opcode) { +case nvme_admin_get_log_page: +return nvmet_get_log_page_len (req->cmd); +case nvme_admin_identify: +return NVME_IDENTIFY_DATA_SIZE ; +default : +return 0 ; + } +} +u16 nvmet_parse_discovery_cmd (struct nvmet_req *req) {struct nvme_command *cmd = req->cmd;
drivers/nvme/target/fabrics-cmd-auth.c +12 -2
@@ -188,6 +188,11 @@ static u8 nvmet_auth_failure2(void *d)return data->rescode_exp; } +u32 nvmet_auth_send_data_len (struct nvmet_req *req) +{ +return le32_to_cpu (req->cmd->auth_send.tl); +} +void nvmet_execute_auth_send (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -215,7 +220,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) offsetof(struct nvmf_auth_send_command , spsp1); goto done; } - tl =le32_to_cpu (req->cmd->auth_send.tl); + tl =nvmet_auth_send_data_len (req);if (!tl) { status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc =
@@ -438,6 +443,11 @@ static void nvmet_auth_failure1(struct nvmet_req *req, void *d, int al) data->rescode_exp = req->sq->dhchap_status; } +u32 nvmet_auth_receive_data_len (struct nvmet_req *req) +{ +return le32_to_cpu (req->cmd->auth_receive.al); +} +void nvmet_execute_auth_receive (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -463,7 +473,7 @@ void nvmet_execute_auth_receive(struct nvmet_req *req) offsetof(struct nvmf_auth_receive_command , spsp1); goto done; } - al =le32_to_cpu (req->cmd->auth_receive.al); + al =nvmet_auth_receive_data_len (req);if (!al) { status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc =
drivers/nvme/target/fabrics-cmd.c +43 -0
61 lines not on this page · raw message
drivers/nvme/target/nvmet.h +8 -0
@@ -466,18 +466,24 @@ void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl);void nvmet_stop_keep_alive_timer (struct nvmet_ctrl *ctrl);u16 nvmet_parse_connect_cmd (struct nvmet_req *req); +u32 nvmet_connect_cmd_data_len (struct nvmet_req *req);void nvmet_bdev_set_limits (struct block_device *bdev,struct nvme_id_ns *id);u16 nvmet_bdev_parse_io_cmd (struct nvmet_req *req);u16 nvmet_file_parse_io_cmd (struct nvmet_req *req);u16 nvmet_bdev_zns_parse_io_cmd (struct nvmet_req *req); +u32 nvmet_admin_cmd_data_len (struct nvmet_req *req);u16 nvmet_parse_admin_cmd (struct nvmet_req *req); +u32 nvmet_discovery_cmd_data_len (struct nvmet_req *req);u16 nvmet_parse_discovery_cmd (struct nvmet_req *req);u16 nvmet_parse_fabrics_admin_cmd (struct nvmet_req *req); +u32 nvmet_fabrics_admin_cmd_data_len (struct nvmet_req *req);u16 nvmet_parse_fabrics_io_cmd (struct nvmet_req *req); +u32 nvmet_fabrics_io_cmd_data_len (struct nvmet_req *req);bool nvmet_req_init (struct nvmet_req *req,struct nvmet_cq *cq,struct nvmet_sq *sq,const struct nvmet_fabrics_ops *ops);void nvmet_req_uninit (struct nvmet_req *req); +size_t nvmet_req_transfer_len (struct nvmet_req *req);bool nvmet_check_transfer_len (struct nvmet_req *req,size_t len);bool nvmet_check_data_len_lte (struct nvmet_req *req,size_t data_len);void nvmet_req_complete (struct nvmet_req *req,u16 status);
@@ -720,7 +726,9 @@ static inline void nvmet_req_bio_put(struct nvmet_req *req, struct bio *bio) }#ifdef CONFIG_NVME_TARGET_AUTH +u32 nvmet_auth_send_data_len (struct nvmet_req *req);void nvmet_execute_auth_send (struct nvmet_req *req); +u32 nvmet_auth_receive_data_len (struct nvmet_req *req);void nvmet_execute_auth_receive (struct nvmet_req *req);int nvmet_auth_set_key (struct nvmet_host *host,const char *secret,bool set_ctrl);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 nvmet-auth: reject short AUTH_RECEIVE buffers
From: Michael Bommarito <[email protected]>
[ Upstream commit 779575bc35c687697ba69e904f2cd22e60112534 ]
nvmet_execute_auth_receive() trusts the AUTH_RECEIVE allocation length after checking only that it is nonzero and matches the transfer length. In the SUCCESS1 and FAILURE1/default states, that lets a remote NVMe-oF initiator reach the fixed-size DH-HMAC-CHAP response builders with a kmalloc() buffer shorter than the response, so nvmet_auth_success1() and nvmet_auth_failure1() write past the allocation; both only WARN_ON the short length and then format the message anyway.
Impact: A remote NVMe-oF initiator with access to an auth-enabled target can trigger a 16-byte heap out-of-bounds write via a one-byte AUTH_RECEIVE allocation length.
Compute the minimum response length for the current DH-HMAC-CHAP step in nvmet_auth_receive_data_len() and report a zero data length when the host-supplied allocation length is shorter, so the existing zero-length check in nvmet_execute_auth_receive() rejects the command before any builder runs. The SUCCESS1 minimum is sizeof(struct nvmf_auth_dhchap_success1_data) plus the HMAC hash length, because the response hash is written into the rval[] flexible-array tail, so the minimum is state dependent rather than a flat sizeof. CHALLENGE keeps its existing variable-length guard in nvmet_auth_challenge().
This is reachable only when in-band DH-HMAC-CHAP authentication is configured on the target.
--- drivers/nvme/target/fabrics-cmd-auth.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/nvme/target/fabrics-cmd-auth.c +25 -1
@@ -445,7 +445,31 @@ static void nvmet_auth_failure1(struct nvmet_req *req, void *d, int al)u32 nvmet_auth_receive_data_len (struct nvmet_req *req) { -return le32_to_cpu (req->cmd->auth_receive.al); +struct nvmet_ctrl *ctrl = req->sq->ctrl; +u32 al =le32_to_cpu (req->cmd->auth_receive.al); +u32 min_len; + +/* +* Reject too-short al before kmalloc(al), since the SUCCESS1 and +* FAILURE1/default builders write fixed response headers into it. +*/ +switch (req->sq->dhchap_step) { +case NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE : +return al; +case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 : + min_len =sizeof (struct nvmf_auth_dhchap_success1_data ); +if (req->sq->dhchap_c2) + min_len +=nvme_auth_hmac_hash_len (ctrl->shash_id); +break ; +default : + min_len =sizeof (struct nvmf_auth_dhchap_failure_data ); +break ; + } + +if (al < min_len) +return 0 ; + +return al; }void nvmet_execute_auth_receive (struct nvmet_req *req)
Signature · 1 line
2.53.0