History

page_pool: Fix PP_MAGIC_MASK to avoid crashing on some 32-bit arches

Helge reported that the introduction of PP_MAGIC_MASK let to crashes on boot on his 32-bit parisc machine. The cause of this is the mask is set too wide, so the page_pool_page_is_pp() incurs false positives which crashes the machine. Just disabling the check in page_pool_is_pp() will lead to the page_pool code itself malfunctioning; so instead of doing this, this patch changes the define for PP_DMA_INDEX_BITS to avoid mistaking arbitrary kernel pointers for page_pool-tagged pages. The fix relies on the kernel pointers that alias with the pp_magic field always being above PAGE_OFFSET. With this assumption, we can use the lowest bit of the value of PAGE_OFFSET as the upper bound of the PP_DMA_INDEX_MASK, which should avoid the false positives. Because we cannot rely on PAGE_OFFSET always being a compile-time constant, nor on it always being >0, we fall back to disabling the dma_index storage when there are not enough bits available. This leaves us in the situation we were in before the patch in the Fixes tag, but only on a subset of architecture configurations. This seems to be the best we can do until the transition to page types in complete for page_pool pages. v2: - Make sure there's at least 8 bits available and that the PAGE_OFFSET bit calculation doesn't wrap

Toke Høiland-Jørgensen committed 1 year ago

Commit 95920c21 parent 521405c2 files · +66 −32Browse files

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

Unified · Split

include/linux/mm.h+13−9
@@ -4159,14 +4159,13 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status); · 4158 unmodified lines
4159 * since this value becomes part of PP_SIGNATURE; meaning we can just use the4159 * since this value becomes part of PP_SIGNATURE; meaning we can just use the
4160 * space between the PP_SIGNATURE value (without POISON_POINTER_DELTA), and the4160 * space between the PP_SIGNATURE value (without POISON_POINTER_DELTA), and the
4161 * lowest bits of POISON_POINTER_DELTA. On arches where POISON_POINTER_DELTA is4161 * lowest bits of POISON_POINTER_DELTA. On arches where POISON_POINTER_DELTA is
4162 * 0, we make sure that we leave the two topmost bits empty, as that guarantees4162 * 0, we use the lowest bit of PAGE_OFFSET as the boundary if that value is
4163 * we won't mistake a valid kernel pointer for a value we set, regardless of the4163 * known at compile-time.
4164 * VMSPLIT setting.
4165 *4164 *
4166 * Altogether, this means that the number of bits available is constrained by4165 * If the value of PAGE_OFFSET is not known at compile time, or if it is too
4167 * the size of an unsigned long (at the upper end, subtracting two bits per the4166 * small to leave at least 8 bits available above PP_SIGNATURE, we define the
4168 * above), and the definition of PP_SIGNATURE (with or without4167 * number of bits to be 0, which turns off the DMA index tracking altogether
4169 * POISON_POINTER_DELTA).4168 * (see page_pool_register_dma_index()).
4170 */4169 */
4171#define PP_DMA_INDEX_SHIFT (1 + __fls(PP_SIGNATURE - POISON_POINTER_DELTA))4170#define PP_DMA_INDEX_SHIFT (1 + __fls(PP_SIGNATURE - POISON_POINTER_DELTA))
4172#if POISON_POINTER_DELTA > 04171#if POISON_POINTER_DELTA > 0
@@ -4175,8 +4174,13 @@ int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status); · 2 unmodified lines
4175 */4174 */
4176#define PP_DMA_INDEX_BITS MIN(32, __ffs(POISON_POINTER_DELTA) - PP_DMA_INDEX_SHIFT)4175#define PP_DMA_INDEX_BITS MIN(32, __ffs(POISON_POINTER_DELTA) - PP_DMA_INDEX_SHIFT)
4177#else4176#else
4178/* Always leave out the topmost two; see above. */4177/* Use the lowest bit of PAGE_OFFSET if there's at least 8 bits available; see above */
4179#define PP_DMA_INDEX_BITS MIN(32, BITS_PER_LONG - PP_DMA_INDEX_SHIFT - 2)4178#define PP_DMA_INDEX_MIN_OFFSET (1 << (PP_DMA_INDEX_SHIFT + 8))
4179#define PP_DMA_INDEX_BITS ((__builtin_constant_p(PAGE_OFFSET) && \
4180 PAGE_OFFSET >= PP_DMA_INDEX_MIN_OFFSET && \
4181 !(PAGE_OFFSET & (PP_DMA_INDEX_MIN_OFFSET - 1))) ? \
4182 MIN(32, __ffs(PAGE_OFFSET) - PP_DMA_INDEX_SHIFT) : 0)
4183
4180#endif4184#endif
4181 4185
4182#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \4186#define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \

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