Skip to content

Commit 5648451

Browse files
GustavoARSilvadavem330
authored andcommitted
ipv4: Fix potential Spectre v1 vulnerability
vr.vifi is indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: net/ipv4/ipmr.c:1616 ipmr_ioctl() warn: potential spectre issue 'mrt->vif_table' [r] (local cap) net/ipv4/ipmr.c:1690 ipmr_compat_ioctl() warn: potential spectre issue 'mrt->vif_table' [r] (local cap) Fix this by sanitizing vr.vifi before using it to index mrt->vif_table' Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4a2eb0c commit 5648451

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/ipv4/ipmr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#include <net/nexthop.h>
7070
#include <net/switchdev.h>
7171

72+
#include <linux/nospec.h>
73+
7274
struct ipmr_rule {
7375
struct fib_rule common;
7476
};
@@ -1612,6 +1614,7 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
16121614
return -EFAULT;
16131615
if (vr.vifi >= mrt->maxvif)
16141616
return -EINVAL;
1617+
vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif);
16151618
read_lock(&mrt_lock);
16161619
vif = &mrt->vif_table[vr.vifi];
16171620
if (VIF_EXISTS(mrt, vr.vifi)) {
@@ -1686,6 +1689,7 @@ int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
16861689
return -EFAULT;
16871690
if (vr.vifi >= mrt->maxvif)
16881691
return -EINVAL;
1692+
vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif);
16891693
read_lock(&mrt_lock);
16901694
vif = &mrt->vif_table[vr.vifi];
16911695
if (VIF_EXISTS(mrt, vr.vifi)) {

0 commit comments

Comments
 (0)