Skip to content

Commit b7577fe

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/diag: Add missing array_index_nospec() call to memtop_get_page_count()
'level' is user space controlled and used to read from an array. Add the missing array_index_nospec() call to prevent speculative execution. Cc: stable@vger.kernel.org Fixes: 0d30871 ("s390/diag: Add memory topology information via diag310") Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Reviewed-by: Mete Durlu <meted@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 8cdeaa5 commit b7577fe

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

arch/s390/kernel/diag/diag310.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,18 @@ static int memtop_get_stride_len(unsigned long *res)
190190
static int memtop_get_page_count(unsigned long *res, unsigned long level)
191191
{
192192
static unsigned long memtop_pages[DIAG310_LEVELMAX];
193-
unsigned long pages;
193+
unsigned long pages, idx;
194194
int rc;
195195

196196
if (level > DIAG310_LEVELMAX || level < DIAG310_LEVELMIN)
197197
return -EINVAL;
198-
pages = READ_ONCE(memtop_pages[level - 1]);
198+
idx = array_index_nospec(level - 1, ARRAY_SIZE(memtop_pages));
199+
pages = READ_ONCE(memtop_pages[idx]);
199200
if (!pages) {
200201
rc = diag310_get_memtop_size(&pages, level);
201202
if (rc)
202203
return rc;
203-
WRITE_ONCE(memtop_pages[level - 1], pages);
204+
WRITE_ONCE(memtop_pages[idx], pages);
204205
}
205206
*res = pages;
206207
return 0;

0 commit comments

Comments
 (0)