xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr()
authorEric Dumazet <edumazet@google.com>
Fri, 20 Jan 2023 13:02:49 +0000 (13:02 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Feb 2023 18:17:58 +0000 (19:17 +0100)
commit5dc688fae6b7be9dbbf5304a3d2520d038e06db5
tree3e11a11e870adcb2db89d520b3b29ba6e7b699ee
parent9bae58d58b6bb73b572356b31a62d2afc7378d12
xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr()

[ Upstream commit b6ee896385380aa621102e8ea402ba12db1cabff ]

  int type = nla_type(nla);

  if (type > XFRMA_MAX) {
            return -EOPNOTSUPP;
  }

@type is then used as an array index and can be used
as a Spectre v1 gadget.

  if (nla_len(nla) < compat_policy[type].len) {

array_index_nospec() can be used to prevent leaking
content of kernel memory to malicious users.

Fixes: 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Dmitry Safonov <dima@arista.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Reviewed-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/xfrm/xfrm_compat.c