From nobody Tue May 21 18:48:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1607444957; cv=none; d=zohomail.com; s=zohoarc; b=ZlICwwZ7Q4aia3C8mFyOZWeD//6hc3ROZ+vmRAVZdZhUdorx84QeI86v17lquikkXdEgOHu4wCB6R8RysCxXO4dWX31l/t5XPEs2xaxOY/lxpOSIDc20jDFRvXdTVCaBckwI5XxZ3+vLoeBgBFMBM3/btO7l5tVCABr++UnIJ+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607444957; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9wB4LdjkZFQvWc9yfVMtpRpmWrloUVqvX3PfsRpBN+8=; b=m431twvbIcge1gZeof7y/yBfjgFCRXDveybpRi9OOzogKYWdJmKNG+xNFoGTKuwkn9IIBHga4G7Rf1ntDs0Of5UB8pNUU+/au3SW8HSbd7RO2VmagfM9KHaTHZPkFc3TyLb1WVjoDvbtqxmngPzyxhjTv2MPqRKSpEafq05RxKo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607444957707991.3498095956364; Tue, 8 Dec 2020 08:29:17 -0800 (PST) Received: from localhost ([::1]:60604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmeUp-0001v2-6o for importer@patchew.org; Tue, 08 Dec 2020 10:01:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmeRx-0000bZ-Or; Tue, 08 Dec 2020 09:58:45 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmeRh-0001Iz-Fb; Tue, 08 Dec 2020 09:58:45 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Cr3F714QwzkmjZ; Tue, 8 Dec 2020 22:57:31 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Tue, 8 Dec 2020 22:58:01 +0800 From: Alex Chen To: , , Subject: [PATCH] block/nvme: Fix possible array index out of bounds in nvme_process_completion() Date: Tue, 8 Dec 2020 14:44:52 +0000 Message-ID: <20201208144452.91172-1-alex.chen@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=alex.chen@huawei.com; helo=szxga04-in.huawei.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.chen@huawei.com, qemu-trivial@nongnu.org, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The range of 'cid' is [1, NVME_QUEUE_SIZE-1], so when 'cid' is equal to NVME_QUEUE_SIZE, it should be continued, otherwise it will lead to array index out of bounds when accessing 'q->reqs[cid-1]' Reported-by: Euler Robot Signed-off-by: Alex Chen --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index a06a188d53..3a2b3f5486 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -402,7 +402,7 @@ static bool nvme_process_completion(NVMeQueuePair *q) q->cq_phase =3D !q->cq_phase; } cid =3D le16_to_cpu(c->cid); - if (cid =3D=3D 0 || cid > NVME_QUEUE_SIZE) { + if (cid =3D=3D 0 || cid >=3D NVME_QUEUE_SIZE) { warn_report("NVMe: Unexpected CID in completion queue: %"PRIu3= 2", " "queue size: %u", cid, NVME_QUEUE_SIZE); continue; --=20 2.19.1