Skip to content

Commit f67c2da

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/mm,fault: use get_kernel_nofault() to dereference in dump_pagetable()
The page table dumper uses get_kernel_nofault() to test if dereferencing page table entries is possible. Use the result, which is the required page table entry, instead of throwing it away and dereferencing a second time without any safe guard. Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 5be05c3 commit f67c2da

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

arch/s390/mm/fault.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,59 +112,52 @@ static __always_inline bool fault_is_write(struct pt_regs *regs)
112112
return false;
113113
}
114114

115-
static int bad_address(void *p)
116-
{
117-
unsigned long dummy;
118-
119-
return get_kernel_nofault(dummy, (unsigned long *)p);
120-
}
121-
122115
static void dump_pagetable(unsigned long asce, unsigned long address)
123116
{
124-
unsigned long *table = __va(asce & _ASCE_ORIGIN);
117+
unsigned long entry, *table = __va(asce & _ASCE_ORIGIN);
125118

126119
pr_alert("AS:%016lx ", asce);
127120
switch (asce & _ASCE_TYPE_MASK) {
128121
case _ASCE_TYPE_REGION1:
129122
table += (address & _REGION1_INDEX) >> _REGION1_SHIFT;
130-
if (bad_address(table))
123+
if (get_kernel_nofault(entry, table))
131124
goto bad;
132-
pr_cont("R1:%016lx ", *table);
133-
if (*table & _REGION_ENTRY_INVALID)
125+
pr_cont("R1:%016lx ", entry);
126+
if (entry & _REGION_ENTRY_INVALID)
134127
goto out;
135-
table = __va(*table & _REGION_ENTRY_ORIGIN);
128+
table = __va(entry & _REGION_ENTRY_ORIGIN);
136129
fallthrough;
137130
case _ASCE_TYPE_REGION2:
138131
table += (address & _REGION2_INDEX) >> _REGION2_SHIFT;
139-
if (bad_address(table))
132+
if (get_kernel_nofault(entry, table))
140133
goto bad;
141-
pr_cont("R2:%016lx ", *table);
142-
if (*table & _REGION_ENTRY_INVALID)
134+
pr_cont("R2:%016lx ", entry);
135+
if (entry & _REGION_ENTRY_INVALID)
143136
goto out;
144-
table = __va(*table & _REGION_ENTRY_ORIGIN);
137+
table = __va(entry & _REGION_ENTRY_ORIGIN);
145138
fallthrough;
146139
case _ASCE_TYPE_REGION3:
147140
table += (address & _REGION3_INDEX) >> _REGION3_SHIFT;
148-
if (bad_address(table))
141+
if (get_kernel_nofault(entry, table))
149142
goto bad;
150-
pr_cont("R3:%016lx ", *table);
151-
if (*table & (_REGION_ENTRY_INVALID | _REGION3_ENTRY_LARGE))
143+
pr_cont("R3:%016lx ", entry);
144+
if (entry & (_REGION_ENTRY_INVALID | _REGION3_ENTRY_LARGE))
152145
goto out;
153-
table = __va(*table & _REGION_ENTRY_ORIGIN);
146+
table = __va(entry & _REGION_ENTRY_ORIGIN);
154147
fallthrough;
155148
case _ASCE_TYPE_SEGMENT:
156149
table += (address & _SEGMENT_INDEX) >> _SEGMENT_SHIFT;
157-
if (bad_address(table))
150+
if (get_kernel_nofault(entry, table))
158151
goto bad;
159-
pr_cont("S:%016lx ", *table);
160-
if (*table & (_SEGMENT_ENTRY_INVALID | _SEGMENT_ENTRY_LARGE))
152+
pr_cont("S:%016lx ", entry);
153+
if (entry & (_SEGMENT_ENTRY_INVALID | _SEGMENT_ENTRY_LARGE))
161154
goto out;
162-
table = __va(*table & _SEGMENT_ENTRY_ORIGIN);
155+
table = __va(entry & _SEGMENT_ENTRY_ORIGIN);
163156
}
164157
table += (address & _PAGE_INDEX) >> _PAGE_SHIFT;
165-
if (bad_address(table))
158+
if (get_kernel_nofault(entry, table))
166159
goto bad;
167-
pr_cont("P:%016lx ", *table);
160+
pr_cont("P:%016lx ", entry);
168161
out:
169162
pr_cont("\n");
170163
return;

0 commit comments

Comments
 (0)