Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp925807imj; Sat, 9 Feb 2019 10:57:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IY6O+bpDRH2sL7dtbdjaFKrcdXfvMXo+TuATFx9gR6GcX0GycAVIVPoUeoEc9dh+FEidhLD X-Received: by 2002:a62:9f92:: with SMTP id v18mr28918745pfk.154.1549738663074; Sat, 09 Feb 2019 10:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549738663; cv=none; d=google.com; s=arc-20160816; b=j1Q76MQQyZ1Ky4N0jWG9H6H01eL82KPSGjBlHBXxtdSTPqekEqa0L3p25HCyiU53Pq 8rchssZ1WEHg6ShSLOolQHc7bu04XToEfBbq6dPpIceVCORwzq3gcNVrrRlkLSQkL0wv SJBDDsVNiPAy4PkL9fDwl7bdCG/lG5T3OXmihon63q24fs6d+mDms3D3aP5G9enKpLuC keCFCt2ZKoQm5QQ50AQtRiesb7HM8cfSw2CiE1+jfQ0qmjzpj19UoCP1bSz94QX7EaOq 8EGxsq5yN1u0vHrdBcMqSy/PtPV/aabL7JRNb9r2bMLFqnJUBIXyHXeCOnAqHWQKSYY7 Ohgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L8HIPQWPtw6vUZ6y7Lf46SDLHzKfPk5OV9EBsPOT2jc=; b=dpL0sNjujeZoXpG+xINf3JwrFvFJu9xTyP88w41oZ9Ds3PNtGg3McGAcOJncXYZZwk /xQ/yxRYNbIzXc2k6uVifeb4PJL2KBSaNa74Sbuv41axkJOSVqpNRvcM/46sOdGLSxfU oQIqrTS3fqDbq/9O97N8XlDRP3i735k0sItCvZDwLhx7PlgAZH7971kMg+lgcSOIsz0v 9CQbxk1M7B7sxCEui4qEYFJjWPoMhZbcyGRJ+aK/hP7vegKUhl43qqhgc+SlinczBhqA IDhPeyH4pppBCRWjcfnyeAqyPAT8Kf/h9Bz3pTUI8y14C/UgtJQuzuK08+saeLKNPBMT xWPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OHudC1Zb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s87si6058641pfi.185.2019.02.09.10.57.27; Sat, 09 Feb 2019 10:57:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OHudC1Zb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728214AbfBIS4f (ORCPT + 99 others); Sat, 9 Feb 2019 13:56:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:60816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727497AbfBISr7 (ORCPT ); Sat, 9 Feb 2019 13:47:59 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7158221929; Sat, 9 Feb 2019 18:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549738079; bh=GfBgCGk4g92oHtW1P0dpWO7xchTgnj88YDOjmgz10r4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OHudC1Zbc5aAVhJXgu6TvHoIR0dYAQZZawfkCQ971DTAQnSjGiUSamV2Io4EOj2ld lTrg64J6fLmgXmXGr+WKvUHP8LTgsYfGeyWWI9uyMASdIIHSXj877FjVXF/il2/i/K GfJNoJAGpzKChkWhEK+fC1+0A5erVnWSvgKcjbCM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hongbo Yao , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 4.20 22/42] nvme-pci: fix out of bounds access in nvme_cqe_pending Date: Sat, 9 Feb 2019 13:47:14 -0500 Message-Id: <20190209184734.125935-22-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190209184734.125935-1-sashal@kernel.org> References: <20190209184734.125935-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hongbo Yao [ Upstream commit dcca1662727220d18fa351097ddff33f95f516c5 ] 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. nvmeq->cq_head is updated in nvme_update_cq_head(), if nvmeq->cq_head equals nvmeq->q_depth and before its value set to zero, nvme_cqe_pending() uses its value as an array index, the index will be out of bounds. Signed-off-by: Hongbo Yao [hch: slight coding style update] Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 0f45868e8af9..47597046c14f 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -913,9 +913,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++; } } -- 2.19.1