Skip to content

Commit 61f2598

Browse files
aegldledford
authored andcommitted
IB/core: Add mitigation for Spectre V1
Some processors may mispredict an array bounds check and speculatively access memory that they should not. With a user supplied array index we like to play things safe by masking the value with the array size before it is used as an index. Signed-off-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/r/20190731043957.GA1600@agluck-desk2.amr.corp.intel.com Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 708637e commit 61f2598

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/infiniband/core/user_mad.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/sched.h>
5050
#include <linux/semaphore.h>
5151
#include <linux/slab.h>
52+
#include <linux/nospec.h>
5253

5354
#include <linux/uaccess.h>
5455

@@ -884,11 +885,14 @@ static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg)
884885

885886
if (get_user(id, arg))
886887
return -EFAULT;
888+
if (id >= IB_UMAD_MAX_AGENTS)
889+
return -EINVAL;
887890

888891
mutex_lock(&file->port->file_mutex);
889892
mutex_lock(&file->mutex);
890893

891-
if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) {
894+
id = array_index_nospec(id, IB_UMAD_MAX_AGENTS);
895+
if (!__get_agent(file, id)) {
892896
ret = -EINVAL;
893897
goto out;
894898
}

0 commit comments

Comments
 (0)