[PATCH 1/2] nvmet-tcp: propagate nvmet_tcp_build_pdu_iovec() errors to its callers
Keith Busch
kbusch at kernel.org
Wed Mar 11 13:20:31 PDT 2026
On Wed, Mar 11, 2026 at 05:09:19PM +0100, Maurizio Lombardi wrote:
> Currently, when nvmet_tcp_build_pdu_iovec() detects an out-of-bounds
> PDU length or offset, it triggers nvmet_tcp_fatal_error(cmd->queue)
> and returns early. However, because the function returns void, the
> callers are entirely unaware that a fatal error has occurred and
> that the cmd->recv_msg.msg_iter was left uninitialized.
>
> Callers such as nvmet_tcp_handle_h2c_data_pdu() proceed to blindly
> overwrite the queue state with queue->rcv_state = NVMET_TCP_RECV_DATA
> Consequently, the socket receiving loop may attempt to read incoming
> network data into the uninitialized iterator.
>
> Fix this by shifting the error handling responsibility to the callers.
This looks good to me. Just some minor comments below.
> + ret = nvmet_tcp_build_pdu_iovec(cmd);
> + if (unlikely(ret)) {
> + pr_err("queue %d: failed to build PDU iovec", queue->idx);
Missing the '\n' in this print.
> @@ -1092,7 +1098,12 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue)
> if (nvmet_tcp_need_data_in(queue->cmd)) {
> if (nvmet_tcp_has_inline_data(queue->cmd)) {
> queue->rcv_state = NVMET_TCP_RECV_DATA;
> - nvmet_tcp_build_pdu_iovec(queue->cmd);
> + ret = nvmet_tcp_build_pdu_iovec(queue->cmd);
> + if (unlikely(ret)) {
> + pr_err("queue %d: failed to build PDU iovec\n",
> + queue->idx);
> + return ret;
> + }
> return 0;
Minor nit here, you can squash the two rets into a single 'return ret;'.
More information about the Linux-nvme
mailing list