Skip to content

Commit

Permalink
iommu: apple-dart: fix potential null pointer deref
Browse files Browse the repository at this point in the history
If kzalloc() fails, accessing cfg->supports_bypass causes a null pointer dereference.

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

Fixes: 3bc0102 ("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>
  • Loading branch information
Qasim Ijaz authored and Joerg Roedel committed Mar 20, 2025
1 parent 3bc0102 commit b874149
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/iommu/apple-dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b874149

Please sign in to comment.