]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
xfrm: enforce validity of offload input flags
authorLeon Romanovsky <leonro@nvidia.com>
Tue, 8 Feb 2022 14:14:32 +0000 (16:14 +0200)
committerPaolo Pisati <paolo.pisati@canonical.com>
Wed, 9 Mar 2022 14:17:52 +0000 (15:17 +0100)
BugLink: https://bugs.launchpad.net/bugs/1964361
commit 7c76ecd9c99b6e9a771d813ab1aa7fa428b3ade1 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: d77e38e612a0 ("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>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
include/uapi/linux/xfrm.h
net/xfrm/xfrm_device.c

index 4e29d785189020fb8bf311bd5d09d6c1c5825f97..65e13a099b1a0efa455bc81beabed3f98b5b1541 100644 (file)
@@ -511,6 +511,12 @@ struct xfrm_user_offload {
        int                             ifindex;
        __u8                            flags;
 };
+/* This flag was exposed without any kernel code that supporting it.
+ * Unfortunately, strongswan has the code that uses sets this flag,
+ * which makes impossible to reuse this bit.
+ *
+ * So leave it here to make sure that it won't be reused by mistake.
+ */
 #define XFRM_OFFLOAD_IPV6      1
 #define XFRM_OFFLOAD_INBOUND   2
 
index e843b0d9e2a61c16551be51f69bc441ccad4f921..c255aac6b816b4911b435ae76cd3377b88f2d9dd 100644 (file)
@@ -223,6 +223,9 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
        if (x->encap || x->tfcpad)
                return -EINVAL;
 
+       if (xuo->flags & ~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND))
+               return -EINVAL;
+
        dev = dev_get_by_index(net, xuo->ifindex);
        if (!dev) {
                if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) {
@@ -261,7 +264,8 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
        xso->dev = dev;
        xso->real_dev = dev;
        xso->num_exthdrs = 1;
-       xso->flags = xuo->flags;
+       /* Don't forward bit that is not implemented */
+       xso->flags = xuo->flags & ~XFRM_OFFLOAD_IPV6;
 
        err = dev->xfrmdev_ops->xdo_dev_state_add(x);
        if (err) {