]> git.dujemihanovic.xyz Git - linux.git/commitdiff
drm/xe: prevent potential UAF in pf_provision_vf_ggtt()
authorMatthew Auld <matthew.auld@intel.com>
Wed, 28 Aug 2024 10:43:42 +0000 (11:43 +0100)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 12 Sep 2024 17:29:30 +0000 (12:29 -0500)
The node ptr can point to an already freed ptr, if we hit the path with
an already allocated node. We later dereference that pointer with:

xe_gt_assert(gt, !xe_ggtt_node_allocated(node));

which is a potential UAF. Fix this by not stashing the ptr for node.
Also since it is likely a bad idea to leave config->ggtt_region pointing
to a stale ptr, also set that to NULL by calling
pf_release_vf_config_ggtt() instead of pf_release_ggtt().

Fixes: 34e804220f69 ("drm/xe: Make xe_ggtt_node struct independent")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240828104341.180111-2-matthew.auld@intel.com
(cherry picked from commit 89076b5a8b4e0a01040585e156a0b014cd472fd3)
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

index a95e546b77446c8acd109e9a04d40de1cce4a88b..8250ef71e68521d6d2bbdd65759c8407de6f59af 100644 (file)
@@ -399,7 +399,7 @@ static void pf_release_vf_config_ggtt(struct xe_gt *gt, struct xe_gt_sriov_confi
 static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
 {
        struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
-       struct xe_ggtt_node *node = config->ggtt_region;
+       struct xe_ggtt_node *node;
        struct xe_tile *tile = gt_to_tile(gt);
        struct xe_ggtt *ggtt = tile->mem.ggtt;
        u64 alignment = pf_get_ggtt_alignment(gt);
@@ -411,14 +411,14 @@ static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
 
        size = round_up(size, alignment);
 
-       if (xe_ggtt_node_allocated(node)) {
+       if (xe_ggtt_node_allocated(config->ggtt_region)) {
                err = pf_distribute_config_ggtt(tile, vfid, 0, 0);
                if (unlikely(err))
                        return err;
 
-               pf_release_ggtt(tile, node);
+               pf_release_vf_config_ggtt(gt, config);
        }
-       xe_gt_assert(gt, !xe_ggtt_node_allocated(node));
+       xe_gt_assert(gt, !xe_ggtt_node_allocated(config->ggtt_region));
 
        if (!size)
                return 0;