linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Hongbo Yao <yaohongbo@huawei.com>
Cc: wangxiongfeng2@huawei.com, guohanjun@huawei.com,
	huawei.libin@huawei.com, thunder.leizhen@huawei.com,
	tanxiaojun@huawei.com, xiexiuqi@huawei.com,
	yangyingliang@huawei.com, cj.chengjian@huawei.com,
	wxf.wang@hisilicon.com, keith.busch@intel.com, axboe@fb.com,
	hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvme: fix out of bounds access in nvme_cqe_pending
Date: Wed, 9 Jan 2019 19:39:20 +0100	[thread overview]
Message-ID: <20190109183920.GA22070@lst.de> (raw)
In-Reply-To: <1546827727-49635-1-git-send-email-yaohongbo@huawei.com>

On Mon, Jan 07, 2019 at 10:22:07AM +0800, Hongbo Yao wrote:
> There is an out of bounds array access in nvme_cqe_peding().
> 
> When enable irq_thread for nvme interrupt, there is racing between the
> nvmeq->cq_head updating and reading.

Just curious: why did you enable this option?  Do you have a workload
where it matters?

> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index d668682..68375d4 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -908,9 +908,11 @@ static void nvme_complete_cqes(struct nvme_queue *nvmeq, u16 start, u16 end)
>  
>  static inline void nvme_update_cq_head(struct nvme_queue *nvmeq)
>  {
> -	if (++nvmeq->cq_head == nvmeq->q_depth) {
> +	if (nvmeq->cq_head == (nvmeq->q_depth - 1)) {
>  		nvmeq->cq_head = 0;
>  		nvmeq->cq_phase = !nvmeq->cq_phase;
> +	} else {
> +		++nvmeq->cq_head;

No need for the braces above, but otherwise this looks fine.  I'll apply
it to nvme-4.21.

  reply	other threads:[~2019-01-09 18:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07  2:22 [PATCH] nvme: fix out of bounds access in nvme_cqe_pending Hongbo Yao
2019-01-09 18:39 ` Christoph Hellwig [this message]
2019-01-10  1:54   ` Yao HongBo
2019-01-10 14:50     ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190109183920.GA22070@lst.de \
    --to=hch@lst.de \
    --cc=axboe@fb.com \
    --cc=cj.chengjian@huawei.com \
    --cc=guohanjun@huawei.com \
    --cc=huawei.libin@huawei.com \
    --cc=keith.busch@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=tanxiaojun@huawei.com \
    --cc=thunder.leizhen@huawei.com \
    --cc=wangxiongfeng2@huawei.com \
    --cc=wxf.wang@hisilicon.com \
    --cc=xiexiuqi@huawei.com \
    --cc=yangyingliang@huawei.com \
    --cc=yaohongbo@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).