Skip to content

Commit

Permalink
mm/damon/sysfs-schemes: handle tried regions sysfs directory allocati…
Browse files Browse the repository at this point in the history
…on failure

DAMOS tried regions sysfs directory allocation function
(damon_sysfs_scheme_regions_alloc()) is not handling the memory allocation
failure.  In the case, the code will dereference NULL pointer.  Handle the
failure to avoid such invalid access.

Link: https://lkml.kernel.org/r/20231106233408.51159-3-sj@kernel.org
Fixes: 9277d03 ("mm/damon/sysfs-schemes: implement scheme region directory")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org>	[6.2+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
SeongJae Park authored and Andrew Morton committed Nov 15, 2023
1 parent b4936b5 commit 8405568
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mm/damon/sysfs-schemes.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ damon_sysfs_scheme_regions_alloc(void)
struct damon_sysfs_scheme_regions *regions = kmalloc(sizeof(*regions),
GFP_KERNEL);

if (!regions)
return NULL;

regions->kobj = (struct kobject){};
INIT_LIST_HEAD(&regions->regions_list);
regions->nr_regions = 0;
Expand Down

0 comments on commit 8405568

Please sign in to comment.