]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu: apple-dart: fix potential null pointer deref
authorQasim Ijaz <qasdev00@gmail.com>
Fri, 14 Mar 2025 23:01:02 +0000 (23:01 +0000)
committerJoerg Roedel <jroedel@suse.de>
Thu, 20 Mar 2025 07:59:15 +0000 (08:59 +0100)
If kzalloc() fails, accessing cfg->supports_bypass causes a null pointer dereference.

Fix by checking for NULL immediately after allocation and returning -ENOMEM.

Fixes: 3bc0102835f6 ("iommu: apple-dart: Allow mismatched bypass support")
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Link: https://lore.kernel.org/r/20250314230102.11008-1-qasdev00@gmail.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/apple-dart.c

index 13ccb801f52a4d34f6653f78e92787af7dfed1bc..e13501541fdd9dd23cc24d6424ab8dbc34f5841a 100644 (file)
@@ -797,12 +797,11 @@ static int apple_dart_of_xlate(struct device *dev,
 
        if (!cfg) {
                cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
-
+               if (!cfg)
+                       return -ENOMEM;
                /* Will be ANDed with DART capabilities */
                cfg->supports_bypass = true;
        }
-       if (!cfg)
-               return -ENOMEM;
        dev_iommu_priv_set(dev, cfg);
 
        cfg_dart = cfg->stream_maps[0].dart;