ANDROID: 16K: Fix show maps CFI failure

If the kernel is built CONFIG_CFI_CLANG=y, reading smaps
may cause a panic. This is due to a failed CFI check; which
is triggered becuase the signature of the function pointer for
printing smaps padding VMAs does not match exactly with that
for show_smap().

Fix this by casting the function pointer to the expected type
based on whether printing maps or smaps padding.

Bug: 330117029
Bug: 327600007
Bug: 330767927
Bug: 328266487
Bug: 329803029
Change-Id: I65564a547dacbc4131f8557344c8c96e51f90cd5
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
Kalesh Singh 2024-04-30 13:42:47 -07:00
parent ecba20dd59
commit f952d4f3c8
3 changed files with 12 additions and 8 deletions

View File

@ -426,7 +426,7 @@ static int show_map(struct seq_file *m, void *v)
if (vma_pages(vma)) if (vma_pages(vma))
show_map_vma(m, vma); show_map_vma(m, vma);
show_map_pad_vma(vma, pad_vma, m, show_map_vma); show_map_pad_vma(vma, pad_vma, m, show_map_vma, false);
m_cache_vma(m, v); m_cache_vma(m, v);
return 0; return 0;
@ -924,7 +924,7 @@ static int show_smap(struct seq_file *m, void *v)
if (vma_pages(vma)) if (vma_pages(vma))
show_smap_vma(m, vma); show_smap_vma(m, vma);
show_map_pad_vma(vma, pad_vma, m, (show_pad_vma_fn)show_smap_vma); show_map_pad_vma(vma, pad_vma, m, show_smap_vma, true);
m_cache_vma(m, v); m_cache_vma(m, v);
return 0; return 0;

View File

@ -43,8 +43,6 @@
#define VM_PAD_MASK (VM_TOTAL_PAD_PAGES << VM_PAD_SHIFT) #define VM_PAD_MASK (VM_TOTAL_PAD_PAGES << VM_PAD_SHIFT)
#define VMA_PAD_START(vma) (vma->vm_end - (vma_pad_pages(vma) << PAGE_SHIFT)) #define VMA_PAD_START(vma) (vma->vm_end - (vma_pad_pages(vma) << PAGE_SHIFT))
typedef void (*show_pad_vma_fn)(struct seq_file *m, struct vm_area_struct *vma);
#if PAGE_SIZE == SZ_4K && defined(CONFIG_64BIT) #if PAGE_SIZE == SZ_4K && defined(CONFIG_64BIT)
extern void vma_set_pad_pages(struct vm_area_struct *vma, extern void vma_set_pad_pages(struct vm_area_struct *vma,
unsigned long nr_pages); unsigned long nr_pages);
@ -60,7 +58,7 @@ extern struct vm_area_struct *get_data_vma(struct vm_area_struct *vma);
extern void show_map_pad_vma(struct vm_area_struct *vma, extern void show_map_pad_vma(struct vm_area_struct *vma,
struct vm_area_struct *pad, struct vm_area_struct *pad,
struct seq_file *m, show_pad_vma_fn func); struct seq_file *m, void *func, bool smaps);
extern void split_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *new, extern void split_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *new,
unsigned long addr, int new_below); unsigned long addr, int new_below);
@ -92,7 +90,7 @@ static inline struct vm_area_struct *get_data_vma(struct vm_area_struct *vma)
static inline void show_map_pad_vma(struct vm_area_struct *vma, static inline void show_map_pad_vma(struct vm_area_struct *vma,
struct vm_area_struct *pad, struct vm_area_struct *pad,
struct seq_file *m, show_pad_vma_fn func) struct seq_file *m, void *func, bool smaps)
{ {
} }

View File

@ -21,6 +21,9 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
typedef void (*show_pad_maps_fn) (struct seq_file *m, struct vm_area_struct *vma);
typedef void (*show_pad_smaps_fn) (struct seq_file *m, void *v);
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
#if PAGE_SIZE == SZ_4K #if PAGE_SIZE == SZ_4K
DEFINE_STATIC_KEY_TRUE(pgsize_migration_enabled); DEFINE_STATIC_KEY_TRUE(pgsize_migration_enabled);
@ -304,7 +307,7 @@ struct vm_area_struct *get_data_vma(struct vm_area_struct *vma)
* and @pad. * and @pad.
*/ */
void show_map_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *pad, void show_map_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *pad,
struct seq_file *m, show_pad_vma_fn func) struct seq_file *m, void *func, bool smaps)
{ {
if (!pad) if (!pad)
return; return;
@ -321,7 +324,10 @@ void show_map_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *pad,
*/ */
BUG_ON(!vma); BUG_ON(!vma);
func(m, pad); if (smaps)
((show_pad_smaps_fn)func)(m, pad);
else
((show_pad_maps_fn)func)(m, pad);
kfree(pad); kfree(pad);
kfree(vma); kfree(vma);