From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49AB6C433ED for ; Wed, 7 Apr 2021 06:06:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9932A61074 for ; Wed, 7 Apr 2021 06:06:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9932A61074 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=irrelevant.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lU1KT-00042x-NB for qemu-devel@archiver.kernel.org; Wed, 07 Apr 2021 02:06:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU11k-0002GN-Af; Wed, 07 Apr 2021 01:46:56 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:47971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU11i-00058U-Px; Wed, 07 Apr 2021 01:46:56 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 101295C00EC; Wed, 7 Apr 2021 01:46:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 07 Apr 2021 01:46:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=wP0e4oiBcmbpZ 2/CJUbzOJTfvUrQHGu1I7DHqbyh2sQ=; b=Kf+6ftevwQJaggnGgebt/KNyv7tfF 0Mi+dViLhy3cVev6wnEUsLuQXupVICA6CAeexeQd9hwHxEZLH3+LVONxMDvO8f+a rDdD9zK1MDTO/V6XuMByBdrC3iXOnb3krxwtPxPvtb1wY5uCNEiFOYFlon/ZHDyb UQkq+f3c6dt17yJs5U00burzqN87WPtWse8BNqXx446ombeFc3CG4qPAS0D1+hJF 9i3dmlStKiiSbKoX9AhzbMYOaXDHIvh9YAuEBsZWpLKnI9N0UWiSuU7q6a7z3v+3 oPo5MzfYsUly24pZL1qSjqAq7x61/M0xtK8vgp6aVgsL6vtbhdQV597UQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=wP0e4oiBcmbpZ2/CJUbzOJTfvUrQHGu1I7DHqbyh2sQ=; b=OHhCQvME Hryu9OzIIY+SAG+RDoFgx7UTW7EMDT9U5mQ+qDl4lWzfLDXcve30XcF+L+xTf4AR qbo8ocJuYgTf4fm78UbIgDF/T5iAYaAcnCpEQ51s3992+NW6JgCpjWXp3JeAWU4s 1bemaiEonZVhq6YkRYVG1MOELNQN9F0fD7O7iHbpi8bEfwq7xU6BkPtwLWQp7CqA /rCURL4gkzJ47ba3me18S+ImigknPfUjN++T3L/amN0twZ0TpvjVyXsUpvPGX4je WjJgdS0Xoo4BdsvL9kfyysvNvFnqb3i75NoXeIUYapHAoIvE9ncf4IqW4BKC5WYl XiIffbU8243xpQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepueelteegieeuhffgkeefgfevjeeigfetkeeitdfgtdeifefhtdfhfeeuffev gfeknecukfhppeektddrudeijedrleekrdduledtnecuvehluhhsthgvrhfuihiivgepud enucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id 9F5BE1080063; Wed, 7 Apr 2021 01:46:52 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PULL for-6.0 v2 10/10] hw/block/nvme: fix out-of-bounds read in nvme_subsys_ctrl Date: Wed, 7 Apr 2021 07:46:35 +0200 Message-Id: <20210407054635.189440-11-its@irrelevant.dk> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210407054635.189440-1-its@irrelevant.dk> References: <20210407054635.189440-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=66.111.4.29; envelope-from=its@irrelevant.dk; helo=out5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Stefan Hajnoczi , Keith Busch Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen nvme_subsys_ctrl() is used in contexts where the given controller identifier is from an untrusted source. Like its friends nvme_ns() and nvme_subsys_ns(), nvme_subsys_ctrl() should just return NULL if an invalid identifier is given. Fixes: 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command") Cc: Minwoo Im Signed-off-by: Klaus Jensen Reviewed-by: Minwoo Im --- hw/block/nvme-subsys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 1cbcad9be23e..7d7ef5f7f12b 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -36,7 +36,7 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys, uint32_t cntlid) { - if (!subsys) { + if (!subsys || cntlid >= NVME_SUBSYS_MAX_CTRLS) { return NULL; } -- 2.31.1