Skip to content

Commit b3f78e7

Browse files
ryanhrobakpm00
authored andcommitted
mm: vmalloc must set pte via arch code
Patch series "Fixes for pte encapsulation bypasses", v3. A series to improve the encapsulation of pte entries by disallowing non-arch code from directly dereferencing pte_t pointers. This patch (of 4): It is bad practice to directly set pte entries within a pte table. Instead all modifications must go through arch-provided helpers such as set_pte_at() to give the arch code visibility and allow it to check (and potentially modify) the operation. Link: https://lkml.kernel.org/r/20230602092949.545577-1-ryan.roberts@arm.com Link: https://lkml.kernel.org/r/20230602092949.545577-2-ryan.roberts@arm.com Fixes: 3e9a9e2 ("mm: add a vmap_pfn function") Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Acked-by: Lorenzo Stoakes <lstoakes@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: SeongJae Park <sj@kernel.org> Cc: Yu Zhao <yuzhao@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 501b265 commit b3f78e7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mm/vmalloc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,10 +2944,16 @@ struct vmap_pfn_data {
29442944
static int vmap_pfn_apply(pte_t *pte, unsigned long addr, void *private)
29452945
{
29462946
struct vmap_pfn_data *data = private;
2947+
unsigned long pfn = data->pfns[data->idx];
2948+
pte_t ptent;
29472949

2948-
if (WARN_ON_ONCE(pfn_valid(data->pfns[data->idx])))
2950+
if (WARN_ON_ONCE(pfn_valid(pfn)))
29492951
return -EINVAL;
2950-
*pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot));
2952+
2953+
ptent = pte_mkspecial(pfn_pte(pfn, data->prot));
2954+
set_pte_at(&init_mm, addr, pte, ptent);
2955+
2956+
data->idx++;
29512957
return 0;
29522958
}
29532959

0 commit comments

Comments
 (0)