[PATCH] nvme: nvme_identify_ns_descs: prevent oob

Eugene Korenevsky ekorenevsky at aliyun.com
Wed Nov 26 13:45:08 PST 2025


On Wed, Nov 26, 2025 at 01:52:08PM -0700, Keith Busch wrote:

> Is this simpler check not sufficient?

> @@ -1566,7 +1566,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl,
>         for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {

Alas size of ns id header+data may be 4+1=5 if .nidt == NVME_NIDT_CSI.
`pos` may be not aligned to 4 (size of `struct nvme_ns_id_desc` header).
It can be NVME_IDENTIFY_DATA_SIZE-1 here.

And when cur->nidl (i.e. pos+1) is referenced later, we'll get a problem.

>                 struct nvme_ns_id_desc *cur = data + pos;
> 
> -               if (cur->nidl == 0)
> +               if (cur->nidl == 0 || cur->nidl + pos > NVME_IDENTIFY_DATA_SIZE)
>                         break;
> 
>                 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen);
> --



More information about the Linux-nvme mailing list