Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2566636lqp; Mon, 25 Mar 2024 02:52:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtQP7b2vNV1Wd9AgUWiKWFYy17wmXQoqOjsnt0Ul9hssRWfcX+jvloY4PoYgO0xTn68AuWCnpBVSBvI+yhe7vDa5UPPx7uRofktmKcCQ== X-Google-Smtp-Source: AGHT+IH7zBrIODaOuHmmDoE80JR0tV245WNIbIBGEn3Q8E04nXnwrx9QvUwv+QwTTesYRicItcl+ X-Received: by 2002:a05:6808:1829:b0:3c3:d2ca:a4fe with SMTP id bh41-20020a056808182900b003c3d2caa4femr842378oib.7.1711360327949; Mon, 25 Mar 2024 02:52:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711360327; cv=pass; d=google.com; s=arc-20160816; b=vj65fyKWMSQPTHzECDvG2PsPtj2xY6EPviKwcsMPXiLYGoAGRBmb+hWNzUNlj/df1b wU9mmz+OjHkEeZOdW/fmgoJvmyNKZ07c79XQqDl/ednArNELAGVdLv9FLslUYv+zzgn9 btmBHGEWG53nStvGYnDvDApWybEAWbaVbkj1Dj8/UYkffOMs08G2opJaFoKJn1Nv0NUi zPAyO/IlAtWQOWW4V5oOFn00eLWltm1fg5Zx/fSybaFn+oR4r8oe441JobDn5/yetZM6 ozWOpqUuwM8DCcDRhdORXa62HFVtofXz7ZzPHebcRCA16772E9lvloQcVEHkc5nKN+Po rkXg== 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=AJphEAMlULfStVV4gDVOuoXtpOjOCAHijm7Es6SHUec=; fh=JKDBNYLYZnYMQhabiWmTr8pE/5ei5nkAkCLdPM6gGSQ=; b=RSIowraViL6U2V7aQVg7QSWWsMBsZvDoclbgQ1BxqyL4vj+NQf/rmYkjVIqqFMCbFp Q5lT+/Z2P1aPEaCBqvUeLxBYbLIgiu5fLkWeAjxbTsTUKKb3F9v2zGunZJF6iI0dyqZg 3WRn4keEsK3sjOsweGFFf6gw2+KkY7Y+Ujm0EDgIYxiDhopLAf3FCck2bcKodKpEXVPy KXSGBfAw789cywcrnQj2n8/WurHV6CWupLY3DlNP9eJL6S+0N9xlAJ99nQLTPBMaJuj+ cPScuMYM7J6Af2utKo83TFYSE0Y1lNRFM/0sJTop+8UbyxrhkEr7fe/lRGYIVGlCk6uw C95A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z+t3mM9d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115774-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115774-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c36-20020a634e24000000b005dc864bb6e6si7260779pgb.634.2024.03.25.02.52.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:52:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115774-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z+t3mM9d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115774-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115774-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A619B35CD8 for ; Mon, 25 Mar 2024 09:18:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8872836D86A; Mon, 25 Mar 2024 03:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z+t3mM9d" 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 76283145B05; Sun, 24 Mar 2024 23:13:13 +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=1711321993; cv=none; b=lQLKnQQD7mANMP/2U005YvBeJPrCSnh01T2cx3y8mhJnksB+tu2dnVeaUB416i0+VOVJBkH4EbZL4inI5y2oIeQgz5jLDRy3ZkQkRxva0P7OQO1Mv7XEsUut/6QLHULLrpfRGdkZWhiVQHITIU73jWbrO81BkR/sGJvyJ4ycm3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321993; c=relaxed/simple; bh=AvB2jOdPf2snJyGE9H3oF9PY1mJQo3Q/t+9yru2FeY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nOID53Fg6p1yxpCtzxFYAcCp+hvKjhenL1f7IH2yNL8UObQXwznzosRkpIFpTMMUfkeEr5dGIY5R5AY4qjlCzYFt5CTY/lMINx49OOcCYFVwmq0b69ovA+sKnzhJ8eEcXn4qECESHcrPLEKiohghKRf/bZz0k6HXv7cl2+1bZXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z+t3mM9d; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830ABC433B1; Sun, 24 Mar 2024 23:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321993; bh=AvB2jOdPf2snJyGE9H3oF9PY1mJQo3Q/t+9yru2FeY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z+t3mM9dkGE0HboF7J0m3cSE7mL+a4N1vZIN/+Z2g2KwLp4hib5wLzwFHOkqtOcp/ rHA3w1JFaRuiPS82ANkafzYH7wA1h35Ycp9s871MQFX1i/cHCHSpZavgkyf3vjLwQd a2NjYC4t5QwZrjG+0Yzl5bc13JYepE3N59CBhadbEnng0s7pWLNaOn674TazVykW4G 829Q3ujQo1mkKkwLiq/6XS8cMsS7oTzTn9vUH+VJ6TUEa9QdmEo7eNiNxLifzGXVtz 8ftWRqI6ZexyHTTN24RB1WSS5MBEX7/68C3dXPgWpIbxgC61gw1f7h3wbLvLU306Tu 51ELuG/pESSkg== 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.1 065/451] nbd: null check for nla_nest_start Date: Sun, 24 Mar 2024 19:05:41 -0400 Message-ID: <20240324231207.1351418-66-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-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 9a53165de4cef..5c4be8dda253c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2408,6 +2408,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