FAILED: patch "[PATCH] nvmet-tcp: bound SGL data length before allocating command" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 4a3f00262a044e8e15064b1a6860968bf0500bf4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026082515-mobilize-facelift-6d03@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4a3f00262a044e8e15064b1a6860968bf0500bf4 Mon Sep 17 00:00:00 2001
From: Ibrahim Hashimov <[email protected]>
Date: Thu, 9 Jul 2026 15:25:33 +0200
Subject: [PATCH] nvmet-tcp: bound SGL data length before allocating command
buffers
nvmet_tcp_map_data() reads the host-controlled 32-bit sgl->length and, for the in-capsule offset descriptor (type 0x01), checks it against port->inline_data_size before use. Any other SGL descriptor type -- including the non-inline transport SGL data-block descriptor (type (NVME_TRANSPORT_SGL_DATA_DESC << 4) | NVME_SGL_FMT_TRANSPORT_A, the type a real host uses for out-of-capsule writes) skips that check entirely and falls straight through to:
cmd->req.sg = sgl_alloc(len, GFP_KERNEL, &cmd->req.sg_cnt);
with len taken directly from the wire, unbounded up to 4 GiB.
nvmet_req_init() only parses the command and never inspects sgl->length, and nvmet_check_transfer_len() -- the only other place transfer_len is validated -- runs later, from req->execute(), after the allocation has already happened. For a write command the target responds with an R2T and parks the command waiting for the host to send the data; if the host (or an unauthenticated peer that simply never follows up) never does, the sgl_alloc() buffer stays resident for the life of the command. NVMe/TCP has no mandatory authentication in the default configuration, so any peer able to reach the target portal and complete a Fabrics connect can drive this with a single crafted command, repeatable across queues and connections for amplification. This is unbounded kernel memory allocation triggered by a remote, effectively unauthenticated peer.
Validate len against the same NVMET_TCP_MAXH2CDATA ceiling this file already uses to bound per-PDU H2C data, for every SGL descriptor type, before doing any allocation. This closes the gap for the non-inline descriptor while leaving the existing, tighter inline_data_size check in place for the in-capsule case.
Runtime-verified on a v6.19 KASAN stand: with this bound in place, a crafted write command carrying an oversized non-inline SGL length is rejected before sgl_alloc() runs, where the same request previously drove an unbounded ~256 MiB kernel allocation (up to 4 GiB) that stayed resident pending an R2T the host never satisfies.
drivers/nvme/target/tcp.c +13 -0
@@ -422,6 +422,19 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)if (!len)return 0 ; +/* +* inline_data_size only bounds the in-capsule (type 0x01) SGL +* descriptor below. A non-inline transport SGL data-block +* descriptor skips that check entirely and would otherwise reach +* sgl_alloc() with an attacker-controlled len of up to 4 GiB, +* pinning that much kernel memory for a command that may never +* complete. Bound every descriptor type here, before allocating +* anything, using the same ceiling this file already applies to +* per-PDU H2C data. +*/ +if (len >NVMET_TCP_MAXH2CDATA ) +return NVME_SC_SGL_INVALID_DATA |NVME_STATUS_DNR ; +if (sgl->type == ((NVME_SGL_FMT_DATA_DESC <<4 ) |NVME_SGL_FMT_OFFSET )) {if (!nvme_is_write (cmd->req.cmd))
Sasha Levin
maintainerPATCH 1/4 nvme: rename nvme_sc_to_pr_err to nvme_status_to_pr_err
From: Weiwen Hu <[email protected]>
[ Upstream commit 22f19a584d7045e0509f103dbc5c0acfd6415163 ]
This should better match its semantic. "sc" is used in the NVMe spec to specifically refer to the last 8 bits in the status field. We should not reuse "sc" here.
Stable-dep-of: 4a3f00262a04 ("nvmet-tcp: bound SGL data length before allocating command buffers")
--- drivers/nvme/host/pr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/nvme/host/pr.c +5 -5
@@ -72,12 +72,12 @@ static int nvme_send_ns_pr_command(struct nvme_ns *ns, struct nvme_command *c,return nvme_submit_sync_cmd (ns->queue, c, data, data_len); } -static int nvme_sc_to_pr_err (int nvme_sc) +static int nvme_status_to_pr_err (int status) { -if (nvme_is_path_error (nvme_sc)) +if (nvme_is_path_error (status))return PR_STS_PATH_FAILED ; -switch (nvme_sc &0x7ff ) { +switch (status &0x7ff ) {case NVME_SC_SUCCESS :return PR_STS_SUCCESS ;case NVME_SC_RESERVATION_CONFLICT :
@@ -122,7 +122,7 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,if (ret <0 )return ret; -return nvme_sc_to_pr_err (ret); +return nvme_status_to_pr_err (ret); } static int nvme_pr_register(struct block_device *bdev, u64 old,
@@ -197,7 +197,7 @@ static int nvme_pr_resv_report(struct block_device *bdev, void *data,if (ret <0 )return ret; -return nvme_sc_to_pr_err (ret); +return nvme_status_to_pr_err (ret); } static int nvme_pr_read_keys(struct block_device *bdev,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 nvme: fix status magic numbers
From: Weiwen Hu <[email protected]>
[ Upstream commit d89a5c6705998ddc42b104f8eabd3c4b9e8fde08 ]
Replaced some magic numbers about SC and SCT with enum and macro.
Stable-dep-of: 4a3f00262a04 ("nvmet-tcp: bound SGL data length before allocating command buffers")
--- drivers/nvme/host/constants.c | 2 +- drivers/nvme/host/core.c | 14 +++++++------- drivers/nvme/host/multipath.c | 2 +- drivers/nvme/host/nvme.h | 4 ++-- drivers/nvme/host/pr.c | 2 +- include/linux/nvme.h | 14 ++++++++++++-- 6 files changed, 24 insertions(+), 14 deletions(-)
drivers/nvme/host/constants.c +1 -1
@@ -173,7 +173,7 @@ static const char * const nvme_statuses[] = {const unsigned char *nvme_get_error_status_str (u16 status) { - status &=0x7ff ; + status &=NVME_SCT_SC_MASK ;if (status <ARRAY_SIZE (nvme_statuses) && nvme_statuses[status])return nvme_statuses[status &0x7ff ];return "Unknown" ;
drivers/nvme/host/core.c +7 -7
@@ -251,7 +251,7 @@ void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)static blk_status_t nvme_error_status (u16 status) { -switch (status &0x7ff ) { +switch (status &NVME_SCT_SC_MASK ) {case NVME_SC_SUCCESS :return BLK_STS_OK ;case NVME_SC_CAP_EXCEEDED :
@@ -319,8 +319,8 @@ static void nvme_log_error(struct request *req) (unsigned long long )nvme_sect_to_lba (ns,blk_rq_pos (req)), (unsigned long long )blk_rq_bytes (req) >> ns->lba_shift,nvme_get_error_status_str (nr->status), - nr->status >>8 &7 ,/* Status Code Type */ - nr->status &0xff ,/* Status Code */ +NVME_SCT (nr->status),/* Status Code Type */ + nr->status &NVME_SC_MASK ,/* Status Code */ nr->status &NVME_SC_MORE ?"MORE " :"" , nr->status & NVME_SC_DNR ? "DNR " : "");return ;
@@ -331,8 +331,8 @@ static void nvme_log_error(struct request *req)nvme_get_admin_opcode_str (nr->cmd->common.opcode), nr->cmd->common.opcode,nvme_get_error_status_str (nr->status), - nr->status >>8 &7 ,/* Status Code Type */ - nr->status &0xff ,/* Status Code */ +NVME_SCT (nr->status),/* Status Code Type */ + nr->status &NVME_SC_MASK ,/* Status Code */ nr->status &NVME_SC_MORE ?"MORE " :"" , nr->status & NVME_SC_DNR ? "DNR " : ""); }
@@ -349,7 +349,7 @@ static inline enum nvme_disposition nvme_decide_disposition(struct request *req)if (likely (nvme_req (req)->status ==0 ))return COMPLETE ; -if ((nvme_req (req)->status &0x7ff ) ==NVME_SC_AUTH_REQUIRED ) +if ((nvme_req (req)->status &NVME_SCT_SC_MASK ) ==NVME_SC_AUTH_REQUIRED )return AUTHENTICATE ; if (blk_noretry_request(req) ||
@@ -1155,7 +1155,7 @@ EXPORT_SYMBOL_NS_GPL(nvme_passthru_end, NVME_TARGET_PASSTHRU);/* * Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1: -* +* * The host should send Keep Alive commands at half of the Keep Alive Timeout * accounting for transport roundtrip times [..]. */
drivers/nvme/host/multipath.c +1 -1
@@ -86,7 +86,7 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)void nvme_failover_req (struct request *req) {struct nvme_ns *ns = req->q->queuedata; -u16 status =nvme_req (req)->status &0x7ff ; +u16 status =nvme_req (req)->status &NVME_SCT_SC_MASK ;unsigned long flags;struct bio *bio;
drivers/nvme/host/nvme.h +2 -2
@@ -692,7 +692,7 @@ static inline u32 nvme_bytes_to_numd(size_t len)static inline bool nvme_is_ana_error (u16 status) { -switch (status &0x7ff ) { +switch (status &NVME_SCT_SC_MASK ) {case NVME_SC_ANA_TRANSITION :case NVME_SC_ANA_INACCESSIBLE :case NVME_SC_ANA_PERSISTENT_LOSS :
@@ -705,7 +705,7 @@ static inline bool nvme_is_ana_error(u16 status)static inline bool nvme_is_path_error (u16 status) {/* check for a status code type of 'path related status' */ -return (status &0x700 ) ==0x300 ; +return (status &NVME_SCT_MASK ) ==NVME_SCT_PATH ; }/*
drivers/nvme/host/pr.c +1 -1
@@ -77,7 +77,7 @@ static int nvme_status_to_pr_err(int status)if (nvme_is_path_error (status))return PR_STS_PATH_FAILED ; -switch (status &0x7ff ) { +switch (status &NVME_SCT_SC_MASK ) {case NVME_SC_SUCCESS :return PR_STS_SUCCESS ;case NVME_SC_RESERVATION_CONFLICT :
include/linux/nvme.h +12 -2
@@ -1847,6 +1847,7 @@ enum {/* * Generic Command Status: */ +NVME_SCT_GENERIC =0x0 ,NVME_SC_SUCCESS =0x0 ,NVME_SC_INVALID_OPCODE =0x1 , NVME_SC_INVALID_FIELD = 0x2,
@@ -1894,6 +1895,7 @@ enum {/* * Command Specific Status: */ +NVME_SCT_COMMAND_SPECIFIC =0x100 ,NVME_SC_CQ_INVALID =0x100 ,NVME_SC_QID_INVALID =0x101 , NVME_SC_QUEUE_SIZE = 0x102,
@@ -1967,6 +1969,7 @@ enum {/* * Media and Data Integrity Errors: */ +NVME_SCT_MEDIA_ERROR =0x200 ,NVME_SC_WRITE_FAULT =0x280 ,NVME_SC_READ_ERROR =0x281 , NVME_SC_GUARD_CHECK = 0x282,
@@ -1979,6 +1982,7 @@ enum {/* * Path-related Errors: */ +NVME_SCT_PATH =0x300 ,NVME_SC_INTERNAL_PATH_ERROR =0x300 ,NVME_SC_ANA_PERSISTENT_LOSS =0x301 , NVME_SC_ANA_INACCESSIBLE = 0x302,
@@ -1987,11 +1991,17 @@ enum {NVME_SC_HOST_PATH_ERROR =0x370 ,NVME_SC_HOST_ABORTED_CMD =0x371 , -NVME_SC_CRD =0x1800 , +NVME_SC_MASK =0x00ff ,/* Status Code */ +NVME_SCT_MASK =0x0700 ,/* Status Code Type */ +NVME_SCT_SC_MASK =NVME_SCT_MASK |NVME_SC_MASK , + +NVME_SC_CRD =0x1800 ,/* Command Retry Delayed */ NVME_SC_MORE =0x2000 , - NVME_SC_DNR = 0x4000, + NVME_SC_DNR = 0x4000, /* Do Not Retry */ }; +#define NVME_SCT (status) ((status) >> 8 & 7) + struct nvme_completion {/* * Used by Admin and Fabrics commands to return data:
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 nvme: rename CDR/MORE/DNR to NVME_STATUS_*
In reply to Sasha LevinFrom: Weiwen Hu <[email protected]>
[ Upstream commit dd0b0a4a2c5d7209457dc172997d1243ad269cfa ]
CDR/MORE/DNR fields are not belonging to SC in the NVMe spec, rename them to NVME_STATUS_* to avoid confusion.
Stable-dep-of: 4a3f00262a04 ("nvmet-tcp: bound SGL data length before allocating command buffers")
--- drivers/nvme/host/core.c | 18 +++++----- drivers/nvme/host/fabrics.c | 8 ++--- drivers/nvme/host/fault_inject.c | 2 +- drivers/nvme/host/fc.c | 8 ++--- drivers/nvme/target/admin-cmd.c | 24 +++++++------- drivers/nvme/target/core.c | 46 +++++++++++++------------- drivers/nvme/target/discovery.c | 14 ++++---- drivers/nvme/target/fabrics-cmd-auth.c | 16 ++++----- drivers/nvme/target/fabrics-cmd.c | 36 ++++++++++---------- drivers/nvme/target/io-cmd-bdev.c | 12 +++---- drivers/nvme/target/passthru.c | 10 +++--- drivers/nvme/target/rdma.c | 10 +++--- drivers/nvme/target/tcp.c | 4 +-- drivers/nvme/target/zns.c | 30 ++++++++--------- include/linux/nvme.h | 6 ++-- 15 files changed, 122 insertions(+), 122 deletions(-)
drivers/nvme/host/core.c +9 -9
@@ -297,7 +297,7 @@ static void nvme_retry_req(struct request *req)u16 crd;/* The mask and shift result must be <= 3 */ - crd = (nvme_req (req)->status &NVME_SC_CRD ) >>11 ; + crd = (nvme_req (req)->status &NVME_STATUS_CRD ) >>11 ;if (crd) delay =nvme_req (req)->ctrl->crdt[crd -1 ] *100 ;
@@ -321,8 +321,8 @@ static void nvme_log_error(struct request *req)nvme_get_error_status_str (nr->status),NVME_SCT (nr->status),/* Status Code Type */ nr->status &NVME_SC_MASK ,/* Status Code */ - nr->status &NVME_SC_MORE ?"MORE " :"" , - nr->status & NVME_SC_DNR ? "DNR " : ""); + nr->status &NVME_STATUS_MORE ?"MORE " :"" , + nr->status & NVME_STATUS_DNR ? "DNR " : "");return ; }
@@ -333,8 +333,8 @@ static void nvme_log_error(struct request *req)nvme_get_error_status_str (nr->status),NVME_SCT (nr->status),/* Status Code Type */ nr->status &NVME_SC_MASK ,/* Status Code */ - nr->status &NVME_SC_MORE ?"MORE " :"" , - nr->status & NVME_SC_DNR ? "DNR " : ""); + nr->status &NVME_STATUS_MORE ?"MORE " :"" , + nr->status & NVME_STATUS_DNR ? "DNR " : ""); }enum nvme_disposition {
@@ -353,7 +353,7 @@ static inline enum nvme_disposition nvme_decide_disposition(struct request *req)return AUTHENTICATE ;if (blk_noretry_request (req) || - (nvme_req (req)->status &NVME_SC_DNR ) || + (nvme_req (req)->status &NVME_STATUS_DNR ) ||nvme_req (req)->retries >= nvme_max_retries)return COMPLETE ;
@@ -3764,7 +3764,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_info *info) { -int ret =NVME_SC_INVALID_NS |NVME_SC_DNR ; +int ret =NVME_SC_INVALID_NS |NVME_STATUS_DNR ;if (!nvme_ns_ids_equal (&ns->head->ids, &info->ids)) { dev_err(ns->ctrl->device,
@@ -3780,7 +3780,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)* * TODO: we should probably schedule a delayed retry here. */ -if (ret >0 && (ret &NVME_SC_DNR )) +if (ret >0 && (ret &NVME_STATUS_DNR ))nvme_ns_remove (ns); }
@@ -3972,7 +3972,7 @@ static void nvme_scan_work(struct work_struct *work)* they report) but don't actually support it. */ ret =nvme_scan_ns_list (ctrl); -if (ret >0 && ret &NVME_SC_DNR ) +if (ret >0 && ret &NVME_STATUS_DNR )nvme_scan_ns_sequential (ctrl); }mutex_unlock (&ctrl->scan_lock);
drivers/nvme/host/fabrics.c +4 -4
@@ -186,7 +186,7 @@ int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val)if (unlikely (ret !=0 ))dev_err (ctrl->device,"Property Get error: %d, offset %#x\n" , - ret >0 ? ret & ~NVME_SC_DNR : ret, off); + ret >0 ? ret & ~NVME_STATUS_DNR : ret, off);return ret; }
@@ -232,7 +232,7 @@ int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)if (unlikely (ret !=0 ))dev_err (ctrl->device,"Property Get error: %d, offset %#x\n" , - ret >0 ? ret & ~NVME_SC_DNR : ret, off); + ret >0 ? ret & ~NVME_STATUS_DNR : ret, off);return ret; }EXPORT_SYMBOL_GPL (nvmf_reg_read64);
@@ -274,7 +274,7 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)if (unlikely (ret))dev_err (ctrl->device,"Property Set error: %d, offset %#x\n" , - ret >0 ? ret & ~NVME_SC_DNR : ret, off); + ret >0 ? ret & ~NVME_STATUS_DNR : ret, off);return ret; }EXPORT_SYMBOL_GPL (nvmf_reg_write32);
@@ -309,7 +309,7 @@ static void nvmf_log_connect_error(struct nvme_ctrl *ctrl, int errval, int offset, struct nvme_command *cmd, struct nvmf_connect_data *data) { - int err_sctype = errval & ~NVME_SC_DNR; + int err_sctype = errval & ~NVME_STATUS_DNR;if (errval <0 ) { dev_err(ctrl->device,
drivers/nvme/host/fault_inject.c +1 -1
@@ -75,7 +75,7 @@ void nvme_should_fail(struct request *req)/* inject status code and DNR bit */ status = fault_inject->status;if (fault_inject->dont_retry) - status |=NVME_SC_DNR ; + status |=NVME_STATUS_DNR ;nvme_req (req)->status = status; } }
drivers/nvme/host/fc.c +4 -4
@@ -3091,7 +3091,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)if (ctrl->ctrl.icdoff) {dev_err (ctrl->ctrl.device,"icdoff %d is not supported!\n" , ctrl->ctrl.icdoff); - ret =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + ret =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out_disconnect_admin_queue; }
@@ -3099,7 +3099,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)if (!nvme_ctrl_sgl_supported (&ctrl->ctrl)) {dev_err (ctrl->ctrl.device,"Mandatory sgls are not supported!\n" ); - ret =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + ret =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out_disconnect_admin_queue; }
@@ -3275,7 +3275,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)dev_info (ctrl->ctrl.device,"NVME-FC{%d}: reset: Reconnect attempt failed (%d)\n" , ctrl->cnum, status); -if (status >0 && (status &NVME_SC_DNR )) +if (status >0 && (status &NVME_STATUS_DNR )) recon = false; }else if (time_after_eq (jiffies, rport->dev_loss_end)) recon = false;
@@ -3292,7 +3292,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)queue_delayed_work (nvme_wq, &ctrl->connect_work, recon_delay); }else {if (portptr->port_state ==FC_OBJSTATE_ONLINE ) { -if (status >0 && (status &NVME_SC_DNR )) +if (status >0 && (status &NVME_STATUS_DNR ))dev_warn (ctrl->ctrl.device,"NVME-FC{%d}: reconnect failure\n" , ctrl->cnum);
drivers/nvme/target/admin-cmd.c +12 -12
@@ -344,7 +344,7 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)pr_debug ("unhandled lid %d on qid %d\n" , req->cmd->get_log_page.lid, req->sq->qid); req->error_loc = offsetof(struct nvme_get_log_page_command , lid); -nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); +nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ); }static void nvmet_execute_identify_ctrl (struct nvmet_req *req)
@@ -496,7 +496,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)if (le32_to_cpu (req->cmd->identify.nsid) ==NVME_NSID_ALL ) { req->error_loc = offsetof(struct nvme_identify , nsid); - status =NVME_SC_INVALID_NS |NVME_SC_DNR ; + status =NVME_SC_INVALID_NS |NVME_STATUS_DNR ; goto out; }
@@ -662,7 +662,7 @@ static void nvmet_execute_identify_desclist(struct nvmet_req *req)if (sg_zero_buffer (req->sg, req->sg_cnt,NVME_IDENTIFY_DATA_SIZE - off, off) !=NVME_IDENTIFY_DATA_SIZE - off) - status =NVME_SC_INTERNAL |NVME_SC_DNR ; + status =NVME_SC_INTERNAL |NVME_STATUS_DNR ; out:nvmet_req_complete (req, status);
@@ -724,7 +724,7 @@ static void nvmet_execute_identify(struct nvmet_req *req)pr_debug ("unhandled identify cns %d on qid %d\n" , req->cmd->identify.cns, req->sq->qid); req->error_loc = offsetof(struct nvme_identify , cns); -nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); +nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ); }/*
@@ -807,7 +807,7 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask)if (val32 & ~mask) { req->error_loc = offsetof(struct nvme_common_command , cdw11); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }WRITE_ONCE (req->sq->ctrl->aen_enabled, val32);
@@ -833,7 +833,7 @@ void nvmet_execute_set_features(struct nvmet_req *req) ncqr = (cdw11 >>16 ) &0xffff ; nsqr = cdw11 &0xffff ;if (ncqr ==0xffff || nsqr ==0xffff ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; } nvmet_set_result(req,
@@ -846,14 +846,14 @@ void nvmet_execute_set_features(struct nvmet_req *req) status =nvmet_set_feat_async_event (req,NVMET_AEN_CFG_ALL );break ;case NVME_FEAT_HOST_ID : - status =NVME_SC_CMD_SEQ_ERROR |NVME_SC_DNR ; + status =NVME_SC_CMD_SEQ_ERROR |NVME_STATUS_DNR ;break ;case NVME_FEAT_WRITE_PROTECT : status =nvmet_set_feat_write_protect (req);break ;default : req->error_loc = offsetof(struct nvme_common_command , cdw10); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; }
@@ -939,7 +939,7 @@ void nvmet_execute_get_features(struct nvmet_req *req)if (!(req->cmd->common.cdw11 &cpu_to_le32 (1 <<0 ))) { req->error_loc = offsetof(struct nvme_common_command , cdw11); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; }
@@ -952,7 +952,7 @@ void nvmet_execute_get_features(struct nvmet_req *req)default : req->error_loc = offsetof(struct nvme_common_command , cdw10); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; }
@@ -969,7 +969,7 @@ void nvmet_execute_async_event(struct nvmet_req *req)mutex_lock (&ctrl->lock);if (ctrl->nr_async_event_cmds >=NVMET_ASYNC_EVENTS ) {mutex_unlock (&ctrl->lock); -nvmet_req_complete (req,NVME_SC_ASYNC_LIMIT |NVME_SC_DNR ); +nvmet_req_complete (req,NVME_SC_ASYNC_LIMIT |NVME_STATUS_DNR );return ; } ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req;
@@ -1006,7 +1006,7 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)if (nvme_is_fabrics (cmd))return nvmet_parse_fabrics_admin_cmd (req);if (unlikely (!nvmet_check_auth_status (req))) -return NVME_SC_AUTH_REQUIRED |NVME_SC_DNR ; +return NVME_SC_AUTH_REQUIRED |NVME_STATUS_DNR ;if (nvmet_is_disc_subsys (nvmet_req_subsys (req)))return nvmet_parse_discovery_cmd (req);
drivers/nvme/target/core.c +23 -23
171 lines not on this page · raw message
drivers/nvme/target/discovery.c +7 -7
@@ -179,7 +179,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)if (req->cmd->get_log_page.lid !=NVME_LOG_DISC ) { req->error_loc = offsetof(struct nvme_get_log_page_command , lid); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -187,7 +187,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)if (offset &0x3 ) { req->error_loc = offsetof(struct nvme_get_log_page_command , lpo); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -256,7 +256,7 @@ static void nvmet_execute_disc_identify(struct nvmet_req *req)if (req->cmd->identify.cns !=NVME_ID_CNS_CTRL ) { req->error_loc = offsetof(struct nvme_identify , cns); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -320,7 +320,7 @@ static void nvmet_execute_disc_set_features(struct nvmet_req *req)default : req->error_loc = offsetof(struct nvme_common_command , cdw10); - stat =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + stat =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; }
@@ -345,7 +345,7 @@ static void nvmet_execute_disc_get_features(struct nvmet_req *req)default : req->error_loc = offsetof(struct nvme_common_command , cdw10); - stat =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + stat =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; }
@@ -361,7 +361,7 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req) cmd->common.opcode); req->error_loc = offsetof(struct nvme_common_command , opcode); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }switch (cmd->common.opcode) {
@@ -386,7 +386,7 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)default :pr_debug ("unhandled cmd %d\n" , cmd->common.opcode); req->error_loc = offsetof(struct nvme_common_command , opcode); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; } }
drivers/nvme/target/fabrics-cmd-auth.c +8 -8
@@ -198,26 +198,26 @@ void nvmet_execute_auth_send(struct nvmet_req *req)u8 dhchap_status;if (req->cmd->auth_send.secp !=NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_send_command , secp); goto done; }if (req->cmd->auth_send.spsp0 !=0x01 ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_send_command , spsp0); goto done; }if (req->cmd->auth_send.spsp1 !=0x01 ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_send_command , spsp1); goto done; } tl =le32_to_cpu (req->cmd->auth_send.tl);if (!tl) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_send_command , tl); goto done;
@@ -446,26 +446,26 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)u16 status =0 ;if (req->cmd->auth_receive.secp !=NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_receive_command , secp); goto done; }if (req->cmd->auth_receive.spsp0 !=0x01 ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_receive_command , spsp0); goto done; }if (req->cmd->auth_receive.spsp1 !=0x01 ) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_receive_command , spsp1); goto done; } al =le32_to_cpu (req->cmd->auth_receive.al);if (!al) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvmf_auth_receive_command , al); goto done;
drivers/nvme/target/fabrics-cmd.c +18 -18
@@ -18,7 +18,7 @@ static void nvmet_execute_prop_set(struct nvmet_req *req)if (req->cmd->prop_set.attrib &1 ) { req->error_loc = offsetof(struct nvmf_property_set_command , attrib); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -29,7 +29,7 @@ static void nvmet_execute_prop_set(struct nvmet_req *req)default : req->error_loc = offsetof(struct nvmf_property_set_command , offset); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; } out:nvmet_req_complete (req, status);
@@ -50,7 +50,7 @@ static void nvmet_execute_prop_get(struct nvmet_req *req) val = ctrl->cap;break ;default : - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; } }else {
@@ -65,7 +65,7 @@ static void nvmet_execute_prop_get(struct nvmet_req *req) val = ctrl->csts;break ;default : - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ; } }
@@ -105,7 +105,7 @@ u16 nvmet_parse_fabrics_admin_cmd(struct nvmet_req *req)pr_debug ("received unknown capsule type 0x%x\n" , cmd->fabrics.fctype); req->error_loc = offsetof(struct nvmf_common_command , fctype); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }return 0 ;
@@ -128,7 +128,7 @@ u16 nvmet_parse_fabrics_io_cmd(struct nvmet_req *req)pr_debug ("received unknown capsule type 0x%x\n" , cmd->fabrics.fctype); req->error_loc = offsetof(struct nvmf_common_command , fctype); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }return 0 ;
@@ -147,14 +147,14 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)pr_warn ("queue size zero!\n" ); req->error_loc = offsetof(struct nvmf_connect_command , sqsize); req->cqe->result.u32 =IPO_IATTR_CONNECT_SQE (sqsize); - ret =NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; + ret =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; goto err; }if (ctrl->sqs[qid] !=NULL ) {pr_warn ("qid %u has already been created\n" , qid); req->error_loc = offsetof(struct nvmf_connect_command , qid); -return NVME_SC_CMD_SEQ_ERROR |NVME_SC_DNR ; +return NVME_SC_CMD_SEQ_ERROR |NVME_STATUS_DNR ; }if (sqsize > mqes) {
@@ -162,14 +162,14 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req) sqsize, mqes, ctrl->cntlid); req->error_loc = offsetof(struct nvmf_connect_command , sqsize); req->cqe->result.u32 =IPO_IATTR_CONNECT_SQE (sqsize); -return NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; +return NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; } old =cmpxchg (&req->sq->ctrl,NULL , ctrl);if (old) {pr_warn ("queue already connected!\n" ); req->error_loc = offsetof(struct nvmf_connect_command , opcode); -return NVME_SC_CONNECT_CTRL_BUSY |NVME_SC_DNR ; +return NVME_SC_CONNECT_CTRL_BUSY |NVME_STATUS_DNR ; }/* note: convert queue size from 0's-based value to 1's-based value */
@@ -229,14 +229,14 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)pr_warn ("invalid connect version (%d).\n" ,le16_to_cpu (c->recfmt)); req->error_loc = offsetof(struct nvmf_connect_command , recfmt); - status =NVME_SC_CONNECT_FORMAT |NVME_SC_DNR ; + status =NVME_SC_CONNECT_FORMAT |NVME_STATUS_DNR ; goto out; }if (unlikely (d->cntlid !=cpu_to_le16 (0xffff ))) {pr_warn ("connect attempt for invalid controller ID %#x\n" , d->cntlid); - status =NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; req->cqe->result.u32 =IPO_IATTR_CONNECT_DATA (cntlid); goto out; }
@@ -258,7 +258,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req) dhchap_status);nvmet_ctrl_put (ctrl);if (dhchap_status ==NVME_AUTH_DHCHAP_FAILURE_FAILED ) - status = (NVME_SC_CONNECT_INVALID_HOST |NVME_SC_DNR ); + status = (NVME_SC_CONNECT_INVALID_HOST |NVME_STATUS_DNR );else status =NVME_SC_INTERNAL ; goto out;
@@ -306,7 +306,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)if (c->recfmt !=0 ) {pr_warn ("invalid connect version (%d).\n" ,le16_to_cpu (c->recfmt)); - status =NVME_SC_CONNECT_FORMAT |NVME_SC_DNR ; + status =NVME_SC_CONNECT_FORMAT |NVME_STATUS_DNR ; goto out; }
@@ -315,13 +315,13 @@ static void nvmet_execute_io_connect(struct nvmet_req *req) ctrl =nvmet_ctrl_find_get (d->subsysnqn, d->hostnqn,le16_to_cpu (d->cntlid), req);if (!ctrl) { - status =NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; goto out; }if (unlikely (qid > ctrl->subsys->max_qid)) {pr_warn ("invalid queue id (%d)\n" , qid); - status =NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; req->cqe->result.u32 =IPO_IATTR_CONNECT_SQE (qid); goto out_ctrl_put; }
@@ -351,13 +351,13 @@ u16 nvmet_parse_connect_cmd(struct nvmet_req *req)pr_debug ("invalid command 0x%x on unconnected queue.\n" , cmd->fabrics.opcode); req->error_loc = offsetof(struct nvme_common_command , opcode); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }if (cmd->fabrics.fctype != nvme_fabrics_type_connect) {pr_debug ("invalid capsule type 0x%x on unconnected queue.\n" , cmd->fabrics.fctype); req->error_loc = offsetof(struct nvmf_common_command , fctype); -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }if (cmd->connect.qid ==0 )
drivers/nvme/target/io-cmd-bdev.c +6 -6
@@ -133,11 +133,11 @@ u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)*/ switch (blk_sts) {case BLK_STS_NOSPC : - status =NVME_SC_CAP_EXCEEDED |NVME_SC_DNR ; + status =NVME_SC_CAP_EXCEEDED |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvme_rw_command , length);break ;case BLK_STS_TARGET : - status =NVME_SC_LBA_RANGE |NVME_SC_DNR ; + status =NVME_SC_LBA_RANGE |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvme_rw_command , slba);break ;case BLK_STS_NOTSUPP :
@@ -145,10 +145,10 @@ u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)switch (req->cmd->common.opcode) {case nvme_cmd_dsm:case nvme_cmd_write_zeroes: - status =NVME_SC_ONCS_NOT_SUPPORTED |NVME_SC_DNR ; + status =NVME_SC_ONCS_NOT_SUPPORTED |NVME_STATUS_DNR ;break ;default : - status =NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; + status =NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }break ;case BLK_STS_MEDIUM :
@@ -157,7 +157,7 @@ u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)break ;case BLK_STS_IOERR :default : - status =NVME_SC_INTERNAL |NVME_SC_DNR ; + status =NVME_SC_INTERNAL |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvme_common_command , opcode); }
@@ -354,7 +354,7 @@ u16 nvmet_bdev_flush(struct nvmet_req *req)return 0 ;if (blkdev_issue_flush (req->ns->bdev)) -return NVME_SC_INTERNAL |NVME_SC_DNR ; +return NVME_SC_INTERNAL |NVME_STATUS_DNR ;return 0 ; }
drivers/nvme/target/passthru.c +5 -5
@@ -306,7 +306,7 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req) ns =nvme_find_get_ns (ctrl, nsid);if (unlikely (!ns)) {pr_err ("failed to get passthru ns nsid:%u\n" , nsid); - status =NVME_SC_INVALID_NS |NVME_SC_DNR ; + status =NVME_SC_INVALID_NS |NVME_STATUS_DNR ; goto out; }
@@ -426,7 +426,7 @@ u16 nvmet_parse_passthru_io_cmd(struct nvmet_req *req)* emulated in the future if regular targets grow support for * this feature. */ -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; }return nvmet_setup_passthru_command (req);
@@ -478,7 +478,7 @@ static u16 nvmet_passthru_get_set_features(struct nvmet_req *req)case NVME_FEAT_RESV_PERSIST :/* No reservations, see nvmet_parse_passthru_io_cmd() */ default : -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ; } }
@@ -546,7 +546,7 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req) req->p.use_workqueue = true;return NVME_SC_SUCCESS ; } -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ;case NVME_ID_CNS_NS : req->execute = nvmet_passthru_execute_cmd; req->p.use_workqueue = true;
@@ -558,7 +558,7 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req) req->p.use_workqueue = true;return NVME_SC_SUCCESS ; } -return NVME_SC_INVALID_OPCODE |NVME_SC_DNR ; +return NVME_SC_INVALID_OPCODE |NVME_STATUS_DNR ;default :return nvmet_setup_passthru_command (req); }
drivers/nvme/target/rdma.c +5 -5
@@ -853,12 +853,12 @@ static u16 nvmet_rdma_map_sgl_inline(struct nvmet_rdma_rsp *rsp)if (!nvme_is_write (rsp->req.cmd)) { rsp->req.error_loc = offsetof(struct nvme_common_command , opcode); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }if (off + len > rsp->queue->dev->inline_data_size) {pr_err ("invalid inline data offset!\n" ); -return NVME_SC_SGL_INVALID_OFFSET |NVME_SC_DNR ; +return NVME_SC_SGL_INVALID_OFFSET |NVME_STATUS_DNR ; }/* no data command? */
@@ -922,7 +922,7 @@ static u16 nvmet_rdma_map_sgl(struct nvmet_rdma_rsp *rsp)pr_err ("invalid SGL subtype: %#x\n" , sgl->type); rsp->req.error_loc = offsetof(struct nvme_common_command , dptr); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }case NVME_KEY_SGL_FMT_DATA_DESC :switch (sgl->type &0xf ) {
@@ -934,12 +934,12 @@ static u16 nvmet_rdma_map_sgl(struct nvmet_rdma_rsp *rsp)pr_err ("invalid SGL subtype: %#x\n" , sgl->type); rsp->req.error_loc = offsetof(struct nvme_common_command , dptr); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }default :pr_err ("invalid SGL type: %#x\n" , sgl->type); rsp->req.error_loc = offsetof(struct nvme_common_command , dptr); -return NVME_SC_SGL_INVALID_TYPE |NVME_SC_DNR ; +return NVME_SC_SGL_INVALID_TYPE |NVME_STATUS_DNR ; } }
drivers/nvme/target/tcp.c +2 -2
@@ -420,10 +420,10 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)if (sgl->type == ((NVME_SGL_FMT_DATA_DESC <<4 ) |NVME_SGL_FMT_OFFSET )) {if (!nvme_is_write (cmd->req.cmd)) -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;if (len > cmd->req.port->inline_data_size) -return NVME_SC_SGL_INVALID_OFFSET |NVME_SC_DNR ; +return NVME_SC_SGL_INVALID_OFFSET |NVME_STATUS_DNR ; cmd->pdu_len = len; } cmd->req.transfer_len += len;
drivers/nvme/target/zns.c +15 -15
@@ -104,7 +104,7 @@ void nvmet_execute_identify_ns_zns(struct nvmet_req *req)if (le32_to_cpu (req->cmd->identify.nsid) ==NVME_NSID_ALL ) { req->error_loc = offsetof(struct nvme_identify , nsid); - status =NVME_SC_INVALID_NS |NVME_SC_DNR ; + status =NVME_SC_INVALID_NS |NVME_STATUS_DNR ; goto out; }
@@ -125,7 +125,7 @@ void nvmet_execute_identify_ns_zns(struct nvmet_req *req) }if (!bdev_is_zoned (req->ns->bdev)) { - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc = offsetof(struct nvme_identify , nsid); goto out; }
@@ -162,17 +162,17 @@ static u16 nvmet_bdev_validate_zone_mgmt_recv(struct nvmet_req *req)if (sect >=get_capacity (req->ns->bdev->bd_disk)) { req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , slba); -return NVME_SC_LBA_RANGE |NVME_SC_DNR ; +return NVME_SC_LBA_RANGE |NVME_STATUS_DNR ; }if (out_bufsize <sizeof (struct nvme_zone_report )) { req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , numd); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }if (req->cmd->zmr.zra !=NVME_ZRA_ZONE_REPORT ) { req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , zra); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }switch (req->cmd->zmr.pr) {
@@ -181,7 +181,7 @@ static u16 nvmet_bdev_validate_zone_mgmt_recv(struct nvmet_req *req)break ;default : req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , pr); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }switch (req->cmd->zmr.zrasf) {
@@ -197,7 +197,7 @@ static u16 nvmet_bdev_validate_zone_mgmt_recv(struct nvmet_req *req)default : req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , zrasf); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }return NVME_SC_SUCCESS ;
@@ -345,7 +345,7 @@ static u16 blkdev_zone_mgmt_errno_to_nvme_status(int ret)return NVME_SC_SUCCESS ;case -EINVAL :case -EIO : -return NVME_SC_ZONE_INVALID_TRANSITION |NVME_SC_DNR ; +return NVME_SC_ZONE_INVALID_TRANSITION |NVME_STATUS_DNR ;default :return NVME_SC_INTERNAL ; }
@@ -468,7 +468,7 @@ static u16 nvmet_bdev_execute_zmgmt_send_all(struct nvmet_req *req)default :/* this is needed to quiet compiler warning */ req->error_loc = offsetof(struct nvme_zone_mgmt_send_cmd , zsa); -return NVME_SC_INVALID_FIELD |NVME_SC_DNR ; +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; }return NVME_SC_SUCCESS ;
@@ -486,7 +486,7 @@ static void nvmet_bdev_zmgmt_send_work(struct work_struct *w)if (op ==REQ_OP_LAST ) { req->error_loc = offsetof(struct nvme_zone_mgmt_send_cmd , zsa); - status =NVME_SC_ZONE_INVALID_TRANSITION |NVME_SC_DNR ; + status =NVME_SC_ZONE_INVALID_TRANSITION |NVME_STATUS_DNR ; goto out; }
@@ -498,13 +498,13 @@ static void nvmet_bdev_zmgmt_send_work(struct work_struct *w)if (sect >=get_capacity (bdev->bd_disk)) { req->error_loc = offsetof(struct nvme_zone_mgmt_send_cmd , slba); - status =NVME_SC_LBA_RANGE |NVME_SC_DNR ; + status =NVME_SC_LBA_RANGE |NVME_STATUS_DNR ; goto out; }if (sect & (zone_sectors -1 )) { req->error_loc = offsetof(struct nvme_zone_mgmt_send_cmd , slba); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -556,13 +556,13 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req)if (sect >=get_capacity (req->ns->bdev->bd_disk)) { req->error_loc = offsetof(struct nvme_rw_command , slba); - status =NVME_SC_LBA_RANGE |NVME_SC_DNR ; + status =NVME_SC_LBA_RANGE |NVME_STATUS_DNR ; goto out; }if (sect & (bdev_zone_sectors (req->ns->bdev) -1 )) { req->error_loc = offsetof(struct nvme_rw_command , slba); - status =NVME_SC_INVALID_FIELD |NVME_SC_DNR ; + status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; goto out; }
@@ -595,7 +595,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) }if (total_len !=nvmet_rw_data_len (req)) { - status =NVME_SC_INTERNAL |NVME_SC_DNR ; + status =NVME_SC_INTERNAL |NVME_STATUS_DNR ; goto out_put_bio; }
include/linux/nvme.h +3 -3
@@ -1995,9 +1995,9 @@ enum {NVME_SCT_MASK =0x0700 ,/* Status Code Type */ NVME_SCT_SC_MASK =NVME_SCT_MASK |NVME_SC_MASK , -NVME_SC_CRD =0x1800 ,/* Command Retry Delayed */ -NVME_SC_MORE =0x2000 , - NVME_SC_DNR = 0x4000, /* Do Not Retry */ +NVME_STATUS_CRD =0x1800 ,/* Command Retry Delayed */ +NVME_STATUS_MORE =0x2000 , + NVME_STATUS_DNR = 0x4000, /* Do Not Retry */ };#define NVME_SCT (status) ((status) >> 8 & 7)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 nvmet-tcp: bound SGL data length before allocating command buffers
In reply to Sasha LevinFrom: Ibrahim Hashimov <[email protected]>
[ Upstream commit 4a3f00262a044e8e15064b1a6860968bf0500bf4 ]
nvmet_tcp_map_data() reads the host-controlled 32-bit sgl->length and, for the in-capsule offset descriptor (type 0x01), checks it against port->inline_data_size before use. Any other SGL descriptor type -- including the non-inline transport SGL data-block descriptor (type (NVME_TRANSPORT_SGL_DATA_DESC << 4) | NVME_SGL_FMT_TRANSPORT_A, the type a real host uses for out-of-capsule writes) skips that check entirely and falls straight through to:
cmd->req.sg = sgl_alloc(len, GFP_KERNEL, &cmd->req.sg_cnt);
with len taken directly from the wire, unbounded up to 4 GiB.
nvmet_req_init() only parses the command and never inspects sgl->length, and nvmet_check_transfer_len() -- the only other place transfer_len is validated -- runs later, from req->execute(), after the allocation has already happened. For a write command the target responds with an R2T and parks the command waiting for the host to send the data; if the host (or an unauthenticated peer that simply never follows up) never does, the sgl_alloc() buffer stays resident for the life of the command. NVMe/TCP has no mandatory authentication in the default configuration, so any peer able to reach the target portal and complete a Fabrics connect can drive this with a single crafted command, repeatable across queues and connections for amplification. This is unbounded kernel memory allocation triggered by a remote, effectively unauthenticated peer.
Validate len against the same NVMET_TCP_MAXH2CDATA ceiling this file already uses to bound per-PDU H2C data, for every SGL descriptor type, before doing any allocation. This closes the gap for the non-inline descriptor while leaving the existing, tighter inline_data_size check in place for the in-capsule case.
Runtime-verified on a v6.19 KASAN stand: with this bound in place, a crafted write command carrying an oversized non-inline SGL length is rejected before sgl_alloc() runs, where the same request previously drove an unbounded ~256 MiB kernel allocation (up to 4 GiB) that stayed resident pending an R2T the host never satisfies.
--- drivers/nvme/target/tcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/nvme/target/tcp.c +13 -0
@@ -417,6 +417,19 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)if (!len)return 0 ; +/* +* inline_data_size only bounds the in-capsule (type 0x01) SGL +* descriptor below. A non-inline transport SGL data-block +* descriptor skips that check entirely and would otherwise reach +* sgl_alloc() with an attacker-controlled len of up to 4 GiB, +* pinning that much kernel memory for a command that may never +* complete. Bound every descriptor type here, before allocating +* anything, using the same ceiling this file already applies to +* per-PDU H2C data. +*/ +if (len >NVMET_TCP_MAXH2CDATA ) +return NVME_SC_SGL_INVALID_DATA |NVME_STATUS_DNR ; +if (sgl->type == ((NVME_SGL_FMT_DATA_DESC <<4 ) |NVME_SGL_FMT_OFFSET )) {if (!nvme_is_write (cmd->req.cmd))
Signature · 1 line
2.53.0