Skip to content

Fix race condition in the memory management system

Hubert Mazur linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1mm: fix race condition in the memory managementmm/execmem.c+17 -192 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH v1 0/1] Fix race condition in the memory management system

When 'ARCH_HAS_EXECMEM_ROX' is being enabled the memory management system will use caching techniques to optimize the allocations. The logic tries to find the appropriate memory block based on requested size. This can fail if current allocations is not sufficient hence kernel allocates a new block large enough in regards to the request. After the allocation is done, the new block is being added to the free_areas tree and then - traverses the tree with hope to find the matching piecie of memory. The operations of allocating new memory and traversing the tree are not protected by mutex and thus there is a chance that some other process will "steal" this shiny new block. It's a classic race condition for resources. Fix this accordingly by moving a new block of memory to busy fragments instead of free and return the pointer to memory. This simplifies the allocation logic since we don't firstly extend the free areas just to take it a bit later. In case the new memory allocation is required - do it and return to the caller.

Hubert Mazur (1):
mm: fix race condition in the memory management

 mm/execmem.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog