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

Unified · Split

include/linux/mm_types.h+5−2
@@ -1368,7 +1368,7 @@ extern struct mm_struct init_mm; · 1367 unmodified lines
1368 1368
1369#define MM_STRUCT_FLEXIBLE_ARRAY_INIT \1369#define MM_STRUCT_FLEXIBLE_ARRAY_INIT \
1370{ \1370{ \
1371 [0 ... sizeof(cpumask_t)-1] = 0 \1371 [0 ... sizeof(cpumask_t) + MM_CID_STATIC_SIZE - 1] = 0 \
1372}1372}
1373 1373
1374/* Pointer magic because the dynamic array size confuses some compilers. */1374/* 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
1500 mm_init_cid(mm, p);1500 mm_init_cid(mm, p);
1501 return 0;1501 return 0;
1502}1502}
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__))
1504 1504
1505static inline void mm_destroy_cid(struct mm_struct *mm)1505static inline void mm_destroy_cid(struct mm_struct *mm)
1506{1506{
@@ -1514,6 +1514,8 @@ static inline unsigned int mm_cid_size(void) · 7 unmodified lines
1514 return cpumask_size() + bitmap_size(num_possible_cpus());1514 return cpumask_size() + bitmap_size(num_possible_cpus());
1515}1515}
1516 1516
1517/* Use 2 * NR_CPUS as worse case for static allocation. */
1518# define MM_CID_STATIC_SIZE (2 * sizeof(cpumask_t))
1517#else /* CONFIG_SCHED_MM_CID */1519#else /* CONFIG_SCHED_MM_CID */
1518static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }1520static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }
1519static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p) { return 0; }1521static 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
1522{1524{
1523 return 0;1525 return 0;
1524}1526}
1527# define MM_CID_STATIC_SIZE 0
1525#endif /* CONFIG_SCHED_MM_CID */1528#endif /* CONFIG_SCHED_MM_CID */
1526 1529
1527struct mmu_gather;1530struct 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