Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2360230lqp; Sun, 24 Mar 2024 15:40:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZj2e0HpLNI2yHjt7i1PLtptfIPRMUVQVT+ehJbypi9YQA/ZHl89cMsjK2uYzMNEWlQyx5bI/ZJ90neNcovvv9/BooBp8NSfI5iJf8eA== X-Google-Smtp-Source: AGHT+IHGQ2yl3fBpsWCLCy+ErZVYk1Q6y4y9wE9kmz0InNNKe9E0zogyqkJxpSyacEV5zGLNATT5 X-Received: by 2002:a05:620a:4108:b0:78a:5a0a:50e8 with SMTP id j8-20020a05620a410800b0078a5a0a50e8mr174325qko.35.1711320051629; Sun, 24 Mar 2024 15:40:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320051; cv=pass; d=google.com; s=arc-20160816; b=vtiR558dgwc8TpchIdTSDoZkqmw0I9UdTptp9hLfiCntWHRoYs4KIKIj4WwoHUCWrE opBaaORc63Aun1V8nP+HFEStBkeF5OBOuN1dWjNBMIkMjKSPDrKinNTWrYDUueKMuetv KS53ooZRegsH8v/sBVGNgFI41xP4wZZ1Fv/LSQyuWRIeHqUkvBF0UcNl5TUM5yE8bibv HOHN8v3NK01O+0BltviEYd0174B8udh6hTXyFOISZzYKyDi9JMNNKOy4hkLWijqTAjJK ysj9407kgt6Wwbpwsb073vQkDdt8y6wJgtGGuqZRSIxuJasHbu4G2TU+a1F0+z5Hc0qd SRGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6saWln+oXV/Xi01bn8RUPsUeSLkmuQOKWqHSdTqxA0w=; fh=JKDBNYLYZnYMQhabiWmTr8pE/5ei5nkAkCLdPM6gGSQ=; b=LEBIG/zmYnapNTOZ5Ns/DQOSWlqlQglBWJm9ubTokOo/kIX4EhhJJhGyCZyzv94LJs e3cCsvWjBvrl5qeimjHArikmjNmGwYyL3My9s5WllBjxWhJ48YBp4WO60SskC2iBrHkM UcSt2OunoS2wbWGCdmV/WFv5Rm9sZeSr4RYCmg+JE4YlyI88nnudJnHLShqvj/qb6RK6 tWvfUvbbNESSQe9AkIcmeGpfEL3qkpxzggRWCLADhysj4nweXIdL0A7RKeZpsmzbSeZV EANwFiDAb1tGWw3Si864lZ9Bs+2WHEKyJMQxLVDPZHViahQ5TUZPHQNdyLXtWMI+tmFa 1JMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tjAYMapN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112909-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id cm24-20020a05622a251800b00430df37ffa5si4632897qtb.279.2024.03.24.15.40.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:40:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tjAYMapN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112909-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 58BA11C21118 for ; Sun, 24 Mar 2024 22:40:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E04BD5FB92; Sun, 24 Mar 2024 22:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tjAYMapN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AFCE5D8E1; Sun, 24 Mar 2024 22:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319720; cv=none; b=KZhSmkUAGsVFgr5pKcyoLdct5SBQr8FZUv7d+c8mSH5vVj0xwVjNrCeRVT4antIyo1ub+NlaThSHNz01Wpc4rpk5ym7hOccIQJO1vi7CzS7Bb89AXmdXLtXpZ/Ha1mnYY+1ro2Cg8jb5474PsG9z6suQ+5ve8lQ4PTtUcLPL3L8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319720; c=relaxed/simple; bh=6alEoGO6nr4EhRoVtIgT4k+syFQEq+PbxvG/g+gpRtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=px8M99ssIk4x6dEkY3LJAxNc7Dzdy8GPQ8jm/nopuifZUDg1WWRN5v2RIlUYkVteGnIhEbYG6FAVK/QuEXM3U7KG7FRn1qZNgwSUYDKOwkzA/ifmgCvlcvgLSvCtftuLnXRdEjZ5vTfduOg58jseW/xdLuUpcLb4Y0USDeoTMeI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tjAYMapN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E182C43330; Sun, 24 Mar 2024 22:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319719; bh=6alEoGO6nr4EhRoVtIgT4k+syFQEq+PbxvG/g+gpRtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tjAYMapNswU1PIExmjPGLhRuvWkh/HjxqDqyTIVbpOQcA3A7kTZ1Qid/Hya8YyFAg 2wZcNUElFH3UFvESexGK2AfW81fygh1dcZ/lLY46inAHuejE55Fo2+e/ZsxrcEXNrZ 9xzMFcdU8KrwgB0EBXjzHrKBxEKrwVmqsWniGaJNL1popSE1wGUm39I6pfl2Jc1dr0 cSl1Jg4sGoBpYxHjStcBWtdw2gARPAtchwJGJR3vfnR34Ph0tnyrP8Cwo8gfieuCrV VG7r4Zw6JKsK8eRQJEWMb13GM5ZPD3CzeyRRYLDzu4k8Bt8qWd9gjblddm/hFxxanf HploNJDTj7mVw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Navid Emamdoost , Michal Kubecek , Kees Cook , Jens Axboe , Sasha Levin Subject: [PATCH 6.8 022/715] nbd: null check for nla_nest_start Date: Sun, 24 Mar 2024 18:23:21 -0400 Message-ID: <20240324223455.1342824-23-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Navid Emamdoost [ Upstream commit 31edf4bbe0ba27fd03ac7d87eb2ee3d2a231af6d ] nla_nest_start() may fail and return NULL. Insert a check and set errno based on other call sites within the same source code. Signed-off-by: Navid Emamdoost Reviewed-by: Michal Kubecek Fixes: 47d902b90a32 ("nbd: add a status netlink command") Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20240218042534.it.206-kees@kernel.org Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 33a8f37bb6a1f..b7c332528ed7a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2433,6 +2433,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) } dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST); + if (!dev_list) { + nlmsg_free(reply); + ret = -EMSGSIZE; + goto out; + } + if (index == -1) { ret = idr_for_each(&nbd_index_idr, &status_cb, reply); if (ret) { -- 2.43.0