From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B6B73FF1A2; Fri, 15 May 2026 15:53:09 +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=1778860389; cv=none; b=pWuc3Quz2wYr2+au9B9m4OpRCsEdaZh+KC/DXbrfBbFL8z9qoP+76XOWgxROEqVznTmIgwr0zLybPcxxySyjS1GFJDbzWgJELfKbqSSsXJEvLsW5WwJTS3PEm9Z7ngsXF5fzq8uqbKKndtUNIrZ8eVROJa8L8i0p7eoNhgNlm34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778860389; c=relaxed/simple; bh=t50zsXeW7bnO7e77BPC1E5/Llzq8dKNTl08SR89xFyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MMrYH6ZbdHLbPg61LegRgugQZyVLoJNapme0v09cIAo0AP5zj6g+3TpN8HXlmHf8kO1zaa4DwOsm3l9vs1SR1YCBxl0cAM4us6R9JLZaX2rw+Tnr1WY0ZsySP4u+YeKhIhrwR/9fYmLelPdKJNo6Derq+oF2u2UqcW18FlEHCK0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MxpKXkVK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MxpKXkVK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21D8CC2BCB0; Fri, 15 May 2026 15:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778860389; bh=t50zsXeW7bnO7e77BPC1E5/Llzq8dKNTl08SR89xFyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MxpKXkVKsFOkHLfv4G9yI4mpMb5xiEf8n1qG3h4jk7h33U//jPnG0o0okVaR8aRMk s+oIzoxzzHZxag/+wVjUB2FuppLcHFDyjvGCAK2rCWFfoKMDOlLT5d1luOYX02P8O5 4jR8QLhLslRobffDAOvC/ly7CRzyRPSQjwFOYJto= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Harish Kasiviswanathan , Alysa Liu , Alex Deucher Subject: [PATCH 6.12 071/144] drm/amdkfd: Add upper bound check for num_of_nodes Date: Fri, 15 May 2026 17:48:17 +0200 Message-ID: <20260515154655.185175341@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260515154653.469907118@linuxfoundation.org> References: <20260515154653.469907118@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alysa Liu commit 74b73fa56a395d46745e4f245225963e9f8be7f1 upstream. drm/amdkfd: Add upper bound check for num_of_nodes in kfd_ioctl_get_process_apertures_new. Reviewed-by: Harish Kasiviswanathan Signed-off-by: Alysa Liu Signed-off-by: Alex Deucher (cherry picked from commit 98ff46a5ea090c14d2cdb4f5b993b05d74f3949f) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 11 +++++++++++ 3 files changed, 15 insertions(+) --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -768,6 +768,9 @@ static int kfd_ioctl_get_process_apertur goto out_unlock; } + if (args->num_of_nodes > kfd_topology_get_num_devices()) + return -EINVAL; + /* Fill in process-aperture information for all available * nodes, but not more than args->num_of_nodes as that is * the amount of memory allocated by user --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1168,6 +1168,7 @@ static inline struct kfd_node *kfd_node_ return NULL; } int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_node **kdev); +uint32_t kfd_topology_get_num_devices(void); int kfd_numa_node_to_apic_id(int numa_node_id); /* Interrupts */ --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c @@ -2291,6 +2291,17 @@ int kfd_topology_remove_device(struct kf return res; } +uint32_t kfd_topology_get_num_devices(void) +{ + uint32_t num_devices; + + down_read(&topology_lock); + num_devices = sys_props.num_devices; + up_read(&topology_lock); + + return num_devices; +} + /* kfd_topology_enum_kfd_devices - Enumerate through all devices in KFD * topology. If GPU device is found @idx, then valid kfd_dev pointer is * returned through @kdev