[PATCH v3] nvme: nvme_identify_ns_descs: prevent oob

Eugene Korenevsky ekorenevsky at aliyun.com
Tue Dec 2 12:30:04 PST 2025


> > -	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
> > -		struct nvme_ns_id_desc *cur = data + pos;

> > +	pos = 0;
> > +	do {

> > +	} while (pos < NVME_IDENTIFY_DATA_SIZE - sizeof(*cur));

> I don't want bikeshed this, but I thought this looked better as a
> for-loop. You can just modify the continuing condition instead of
> changing the loop type to do-while.

OK, tried to make the patch as close as possible to previous code.
See v4.

Also, adding 'pos += len' to modified `for` makes the line longer
than 80 symbols. However, checkpatch.pl says it is OK. Let me know
if it should be fixed somehow (e.g. by moving 'pos += len' to the
end of loop compound statement).



More information about the Linux-nvme mailing list