History

mm: take into account mm_cid size for mm_struct static definitions

Both init_mm and efi_mm static definitions need to make room for the 2 mm_cid cpumasks. This fixes possible out-of-bounds accesses to init_mm and efi_mm. Add a space between # and define for the mm_alloc_cid() definition to make it consistent with the coding style used in the rest of this header file.

Mathieu Desnoyers committed 10 months ago

Commit be313401 parent 6ac433f1 file · +5 −2Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/mm_types.h+5−2
@@ -1368,7 +1368,7 @@ extern struct mm_struct init_mm; · 1367 unmodified lines
13681368
13691369 #define MM_STRUCT_FLEXIBLE_ARRAY_INIT \
13701370 { \
1371− [0 ... sizeof(cpumask_t)-1] = 0 \
1371+ [0 ... sizeof(cpumask_t) + MM_CID_STATIC_SIZE - 1] = 0 \
13721372 }
13731373
13741374 /* Pointer magic because the dynamic array size confuses some compilers. */
@@ -1500,7 +1500,7 @@ static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct * · 125 unmodified lines
15001500 mm_init_cid(mm, p);
15011501 return 0;
15021502 }
1503−#define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
1503+# define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
15041504
15051505 static inline void mm_destroy_cid(struct mm_struct *mm)
15061506 {
@@ -1514,6 +1514,8 @@ static inline unsigned int mm_cid_size(void) · 7 unmodified lines
15141514 return cpumask_size() + bitmap_size(num_possible_cpus());
15151515 }
15161516
1517+/* Use 2 * NR_CPUS as worse case for static allocation. */
1518+# define MM_CID_STATIC_SIZE (2 * sizeof(cpumask_t))
15171519 #else /* CONFIG_SCHED_MM_CID */
15181520 static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }
15191521 static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p) { return 0; }
@@ -1522,6 +1524,7 @@ static inline unsigned int mm_cid_size(void) · 2 unmodified lines
15221524 {
15231525 return 0;
15241526 }
1527+# define MM_CID_STATIC_SIZE 0
15251528 #endif /* CONFIG_SCHED_MM_CID */
15261529
15271530 struct mmu_gather;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t