Skip to content

Commit 4e63702

Browse files
rleongregkh
authored andcommitted
xfrm: enforce validity of offload input flags
commit 7c76ecd upstream. struct xfrm_user_offload has flags variable that received user input, but kernel didn't check if valid bits were provided. It caused a situation where not sanitized input was forwarded directly to the drivers. For example, XFRM_OFFLOAD_IPV6 define that was exposed, was used by strongswan, but not implemented in the kernel at all. As a solution, check and sanitize input flags to forward XFRM_OFFLOAD_INBOUND to the drivers. Fixes: d77e38e ("xfrm: Add an IPsec hardware offloading API") Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 00fc3ad commit 4e63702

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎include/uapi/linux/xfrm.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ struct xfrm_user_offload {
511511
int ifindex;
512512
__u8 flags;
513513
};
514+
/* This flag was exposed without any kernel code that supporting it.
515+
* Unfortunately, strongswan has the code that uses sets this flag,
516+
* which makes impossible to reuse this bit.
517+
*
518+
* So leave it here to make sure that it won't be reused by mistake.
519+
*/
514520
#define XFRM_OFFLOAD_IPV6 1
515521
#define XFRM_OFFLOAD_INBOUND 2
516522

‎net/xfrm/xfrm_device.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
223223
if (x->encap || x->tfcpad)
224224
return -EINVAL;
225225

226+
if (xuo->flags & ~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND))
227+
return -EINVAL;
228+
226229
dev = dev_get_by_index(net, xuo->ifindex);
227230
if (!dev) {
228231
if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) {
@@ -261,7 +264,8 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
261264
xso->dev = dev;
262265
xso->real_dev = dev;
263266
xso->num_exthdrs = 1;
264-
xso->flags = xuo->flags;
267+
/* Don't forward bit that is not implemented */
268+
xso->flags = xuo->flags & ~XFRM_OFFLOAD_IPV6;
265269

266270
err = dev->xfrmdev_ops->xdo_dev_state_add(x);
267271
if (err) {

0 commit comments

Comments
 (0)