Commit Graph

395 Commits

Author SHA1 Message Date
Rado Vrbovsky 57f771037a Merge: CVE-2024-50142: xfrm: validate new SA's prefixlen using SA family when sel.family is unset
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5768

JIRA: https://issues.redhat.com/browse/RHEL-66461
CVE: CVE-2024-50142

backport of upstream commit:
commit 3f0ab59e6537c6a8f9e1b355b48f9c05a76e8563
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Oct 1 18:48:14 2024 +0200

    xfrm: validate new SA's prefixlen using SA family when sel.family is unset

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>

Approved-by: Florian Westphal <fwestpha@redhat.com>
Approved-by: Hangbin Liu <haliu@redhat.com>
Approved-by: Chris von Recklinghausen <crecklin@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-11-22 09:27:15 +00:00
Rado Vrbovsky 61d491d856 Merge: CVE-2024-50110: xfrm: fix one more kernel-infoleak in algo dumping
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5680

JIRA: https://issues.redhat.com/browse/RHEL-65959  
CVE: CVE-2024-50110

```
xfrm: fix one more kernel-infoleak in algo dumping

During fuzz testing, the following issue was discovered:

BUG: KMSAN: kernel-infoleak in _copy_to_iter+0x598/0x2a30
 _copy_to_iter+0x598/0x2a30
 __skb_datagram_iter+0x168/0x1060
 skb_copy_datagram_iter+0x5b/0x220
 netlink_recvmsg+0x362/0x1700
 sock_recvmsg+0x2dc/0x390
 __sys_recvfrom+0x381/0x6d0
 __x64_sys_recvfrom+0x130/0x200
 x64_sys_call+0x32c8/0x3cc0
 do_syscall_64+0xd8/0x1c0
 entry_SYSCALL_64_after_hwframe+0x79/0x81

Uninit was stored to memory at:
 copy_to_user_state_extra+0xcc1/0x1e00
 dump_one_state+0x28c/0x5f0
 xfrm_state_walk+0x548/0x11e0
 xfrm_dump_sa+0x1e0/0x840
 netlink_dump+0x943/0x1c40
 __netlink_dump_start+0x746/0xdb0
 xfrm_user_rcv_msg+0x429/0xc00
 netlink_rcv_skb+0x613/0x780
 xfrm_netlink_rcv+0x77/0xc0
 netlink_unicast+0xe90/0x1280
 netlink_sendmsg+0x126d/0x1490
 __sock_sendmsg+0x332/0x3d0
 ____sys_sendmsg+0x863/0xc30
 ___sys_sendmsg+0x285/0x3e0
 __x64_sys_sendmsg+0x2d6/0x560
 x64_sys_call+0x1316/0x3cc0
 do_syscall_64+0xd8/0x1c0
 entry_SYSCALL_64_after_hwframe+0x79/0x81

Uninit was created at:
 __kmalloc+0x571/0xd30
 attach_auth+0x106/0x3e0
 xfrm_add_sa+0x2aa0/0x4230
 xfrm_user_rcv_msg+0x832/0xc00
 netlink_rcv_skb+0x613/0x780
 xfrm_netlink_rcv+0x77/0xc0
 netlink_unicast+0xe90/0x1280
 netlink_sendmsg+0x126d/0x1490
 __sock_sendmsg+0x332/0x3d0
 ____sys_sendmsg+0x863/0xc30
 ___sys_sendmsg+0x285/0x3e0
 __x64_sys_sendmsg+0x2d6/0x560
 x64_sys_call+0x1316/0x3cc0
 do_syscall_64+0xd8/0x1c0
 entry_SYSCALL_64_after_hwframe+0x79/0x81

Bytes 328-379 of 732 are uninitialized
Memory access of size 732 starts at ffff88800e18e000
Data copied to user address 00007ff30f48aff0

CPU: 2 PID: 18167 Comm: syz-executor.0 Not tainted 6.8.11 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014

Fixes copying of xfrm algorithms where some random
data of the structure fields can end up in userspace.
Padding in structures may be filled with random (possibly sensitve)
data and should never be given directly to user-space.

A similar issue was resolved in the commit
8222d5910dae ("xfrm: Zero padding when dumping algos and encap")

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: c7a5899eb2 ("xfrm: redact SA secret with lockdown confidentiality")
Cc: stable@vger.kernel.org
Co-developed-by: Boris Tonofa <b.tonofa@ideco.ru>
Signed-off-by: Boris Tonofa <b.tonofa@ideco.ru>
Signed-off-by: Petr Vaganov <p.vaganov@ideco.ru>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
(cherry picked from commit 6889cd2a93e1e3606b3f6e958aa0924e836de4d2)
```

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>

---

<small>Created 2024-11-05 21:25 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://gitlab.com/cki-project/kernel-workflow/-/issues/new?issue%5Btitle%5D=backporter%20webhook%20issue)</small>

Approved-by: Sabrina Dubroca <sdubroca@redhat.com>
Approved-by: Florian Westphal <fwestpha@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-11-22 09:23:20 +00:00
Sabrina Dubroca 73770f507b xfrm: validate new SA's prefixlen using SA family when sel.family is unset
JIRA: https://issues.redhat.com/browse/RHEL-66461
CVE: CVE-2024-50142

Conflict: no sa_dir in verify_newsa_info, added upstream in
    a4a87fa4e96c ("xfrm: Add Direction to the SA in or out")

commit 3f0ab59e6537c6a8f9e1b355b48f9c05a76e8563
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Oct 1 18:48:14 2024 +0200

    xfrm: validate new SA's prefixlen using SA family when sel.family is unset

    This expands the validation introduced in commit 07bf790895 ("xfrm:
    Validate address prefix lengths in the xfrm selector.")

    syzbot created an SA with
        usersa.sel.family = AF_UNSPEC
        usersa.sel.prefixlen_s = 128
        usersa.family = AF_INET

    Because of the AF_UNSPEC selector, verify_newsa_info doesn't put
    limits on prefixlen_{s,d}. But then copy_from_user_state sets
    x->sel.family to usersa.family (AF_INET). Do the same conversion in
    verify_newsa_info before validating prefixlen_{s,d}, since that's how
    prefixlen is going to be used later on.

    Reported-by: syzbot+cc39f136925517aed571@syzkaller.appspotmail.com
    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2024-11-12 16:21:03 +01:00
CKI Backport Bot a07eee1835 xfrm: fix one more kernel-infoleak in algo dumping
JIRA: https://issues.redhat.com/browse/RHEL-65959
CVE: CVE-2024-50110

commit 6889cd2a93e1e3606b3f6e958aa0924e836de4d2
Author: Petr Vaganov <p.vaganov@ideco.ru>
Date:   Tue Oct 8 14:02:58 2024 +0500

    xfrm: fix one more kernel-infoleak in algo dumping

    During fuzz testing, the following issue was discovered:

    BUG: KMSAN: kernel-infoleak in _copy_to_iter+0x598/0x2a30
     _copy_to_iter+0x598/0x2a30
     __skb_datagram_iter+0x168/0x1060
     skb_copy_datagram_iter+0x5b/0x220
     netlink_recvmsg+0x362/0x1700
     sock_recvmsg+0x2dc/0x390
     __sys_recvfrom+0x381/0x6d0
     __x64_sys_recvfrom+0x130/0x200
     x64_sys_call+0x32c8/0x3cc0
     do_syscall_64+0xd8/0x1c0
     entry_SYSCALL_64_after_hwframe+0x79/0x81

    Uninit was stored to memory at:
     copy_to_user_state_extra+0xcc1/0x1e00
     dump_one_state+0x28c/0x5f0
     xfrm_state_walk+0x548/0x11e0
     xfrm_dump_sa+0x1e0/0x840
     netlink_dump+0x943/0x1c40
     __netlink_dump_start+0x746/0xdb0
     xfrm_user_rcv_msg+0x429/0xc00
     netlink_rcv_skb+0x613/0x780
     xfrm_netlink_rcv+0x77/0xc0
     netlink_unicast+0xe90/0x1280
     netlink_sendmsg+0x126d/0x1490
     __sock_sendmsg+0x332/0x3d0
     ____sys_sendmsg+0x863/0xc30
     ___sys_sendmsg+0x285/0x3e0
     __x64_sys_sendmsg+0x2d6/0x560
     x64_sys_call+0x1316/0x3cc0
     do_syscall_64+0xd8/0x1c0
     entry_SYSCALL_64_after_hwframe+0x79/0x81

    Uninit was created at:
     __kmalloc+0x571/0xd30
     attach_auth+0x106/0x3e0
     xfrm_add_sa+0x2aa0/0x4230
     xfrm_user_rcv_msg+0x832/0xc00
     netlink_rcv_skb+0x613/0x780
     xfrm_netlink_rcv+0x77/0xc0
     netlink_unicast+0xe90/0x1280
     netlink_sendmsg+0x126d/0x1490
     __sock_sendmsg+0x332/0x3d0
     ____sys_sendmsg+0x863/0xc30
     ___sys_sendmsg+0x285/0x3e0
     __x64_sys_sendmsg+0x2d6/0x560
     x64_sys_call+0x1316/0x3cc0
     do_syscall_64+0xd8/0x1c0
     entry_SYSCALL_64_after_hwframe+0x79/0x81

    Bytes 328-379 of 732 are uninitialized
    Memory access of size 732 starts at ffff88800e18e000
    Data copied to user address 00007ff30f48aff0

    CPU: 2 PID: 18167 Comm: syz-executor.0 Not tainted 6.8.11 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014

    Fixes copying of xfrm algorithms where some random
    data of the structure fields can end up in userspace.
    Padding in structures may be filled with random (possibly sensitve)
    data and should never be given directly to user-space.

    A similar issue was resolved in the commit
    8222d5910dae ("xfrm: Zero padding when dumping algos and encap")

    Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

    Fixes: c7a5899eb2 ("xfrm: redact SA secret with lockdown confidentiality")
    Cc: stable@vger.kernel.org
    Co-developed-by: Boris Tonofa <b.tonofa@ideco.ru>
    Signed-off-by: Boris Tonofa <b.tonofa@ideco.ru>
    Signed-off-by: Petr Vaganov <p.vaganov@ideco.ru>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-11-05 21:25:05 +00:00
Sabrina Dubroca b7a4643784 xfrm: call xfrm_dev_policy_delete when kill policy
JIRA: https://issues.redhat.com/browse/RHEL-63989

commit 89a2aefe4b084686c2ffc1ee939585111ea4fc0f
Author: Jianbo Liu <jianbol@nvidia.com>
Date:   Mon Jul 8 09:58:12 2024 +0300

    xfrm: call xfrm_dev_policy_delete when kill policy

    xfrm_policy_kill() is called at different places to delete xfrm
    policy. It will call xfrm_pol_put(). But xfrm_dev_policy_delete() is
    not called to free the policy offloaded to hardware.

    The three commits cited here are to handle this issue by calling
    xfrm_dev_policy_delete() outside xfrm_get_policy(). But they didn't
    cover all the cases. An example, which is not handled for now, is
    xfrm_policy_insert(). It is called when XFRM_MSG_UPDPOLICY request is
    received. Old policy is replaced by new one, but the offloaded policy
    is not deleted, so driver doesn't have the chance to release hardware
    resources.

    To resolve this issue for all cases, move xfrm_dev_policy_delete()
    into xfrm_policy_kill(), so the offloaded policy can be deleted from
    hardware when it is called, which avoids hardware resources leakage.

    Fixes: 919e43fad516 ("xfrm: add an interface to offload policy")
    Fixes: bf06fcf4be0f ("xfrm: add missed call to delete offloaded policies")
    Fixes: 982c3aca8bac ("xfrm: delete offloaded policy")
    Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
    Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2024-10-30 11:47:58 +01:00
CKI Backport Bot 9e368d2a60 xfrm: generalize xdo_dev_state_update_curlft to allow statistics update
JIRA: https://issues.redhat.com/browse/RHEL-59900

commit fd2bc4195d5107f88c1b90e1ec935888ccbfc5c0
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue Oct 3 20:57:20 2023 +0300

    xfrm: generalize xdo_dev_state_update_curlft to allow statistics update

    In order to allow drivers to fill all statistics, change the name
    of xdo_dev_state_update_curlft to be xdo_dev_state_update_stats.

    Acked-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-09-24 11:17:25 +00:00
Ivan Vecera e8c655e394 xfrm: copy_to_user_state fetch offloaded SA packets/bytes statistics
JIRA: https://issues.redhat.com/browse/RHEL-16982

commit c9fa320b00cff04980b8514d497068e59a8ee131
Author: Raed Salem <raeds@nvidia.com>
Date:   Tue Mar 14 10:58:40 2023 +0200

    xfrm: copy_to_user_state fetch offloaded SA packets/bytes statistics

    Both in RX and TX, the traffic that performs IPsec packet offload
    transformation is accounted by HW only. Consequently, the HW should
    be queried for packets/bytes statistics when user asks for such
    transformation data.

    Signed-off-by: Raed Salem <raeds@nvidia.com>
    Link: https://lore.kernel.org/r/d90ec74186452b1509ee94875d942cb777b7181e.1678714336.git.leon@kernel.org
    Acked-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Leon Romanovsky <leon@kernel.org>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-12-05 16:07:52 +01:00
Jan Stancek 036b42c7fb Merge: xfrm: backports from upstream
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3271

JIRA: https://issues.redhat.com/browse/RHEL-14517
Tested: basic ipsec tests

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>

Approved-by: Florian Westphal <fwestpha@redhat.com>
Approved-by: Xin Long <lxin@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-11-20 21:50:19 +01:00
Sabrina Dubroca dfe2244607 xfrm: delete offloaded policy
JIRA: https://issues.redhat.com/browse/RHEL-14517
Tested: basic ipsec tests

commit 982c3aca8bac8ae38acdc940e4f1ecec3bffc623
Author: Leon Romanovsky <leon@kernel.org>
Date:   Mon Jul 31 14:38:26 2023 +0300

    xfrm: delete offloaded policy

    The policy memory was released but not HW driver data. Add
    call to xfrm_dev_policy_delete(), so drivers will have a chance
    to release their resources.

    Fixes: 919e43fad516 ("xfrm: add an interface to offload policy")
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-10-25 22:53:55 +02:00
Sabrina Dubroca a4a56456a0 net: xfrm: Amend XFRMA_SEC_CTX nla_policy structure
JIRA: https://issues.redhat.com/browse/RHEL-14517
Tested: basic ipsec tests

commit d1e0e61d617ba17aa516db707aa871387566bbf7
Author: Lin Ma <linma@zju.edu.cn>
Date:   Fri Jun 30 16:19:11 2023 +0800

    net: xfrm: Amend XFRMA_SEC_CTX nla_policy structure

    According to all consumers code of attrs[XFRMA_SEC_CTX], like

    * verify_sec_ctx_len(), convert to xfrm_user_sec_ctx*
    * xfrm_state_construct(), call security_xfrm_state_alloc whose prototype
    is int security_xfrm_state_alloc(.., struct xfrm_user_sec_ctx *sec_ctx);
    * copy_from_user_sec_ctx(), convert to xfrm_user_sec_ctx *
    ...

    It seems that the expected parsing result for XFRMA_SEC_CTX should be
    structure xfrm_user_sec_ctx, and the current xfrm_sec_ctx is confusing
    and misleading (Luckily, they happen to have same size 8 bytes).

    This commit amend the policy structure to xfrm_user_sec_ctx to avoid
    ambiguity.

    Fixes: cf5cb79f69 ("[XFRM] netlink: Establish an attribute policy")
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-10-25 22:53:55 +02:00
Wander Lairson Costa c13ec76236
net: xfrm: Fix xfrm_address_filter OOB read
Bugzilla: https://bugzilla.redhat.com/2227305
CVE: CVE-2023-39194

commit dfa73c17d55b921e1d4e154976de35317e43a93a
Author: Lin Ma <linma@zju.edu.cn>
Date:   Tue Jun 27 11:31:38 2023 +0800

    net: xfrm: Fix xfrm_address_filter OOB read

    We found below OOB crash:

    [   44.211730] ==================================================================
    [   44.212045] BUG: KASAN: slab-out-of-bounds in memcmp+0x8b/0xb0
    [   44.212045] Read of size 8 at addr ffff88800870f320 by task poc.xfrm/97
    [   44.212045]
    [   44.212045] CPU: 0 PID: 97 Comm: poc.xfrm Not tainted 6.4.0-rc7-00072-gdad9774deaf1-dirty #4
    [   44.212045] Call Trace:
    [   44.212045]  <TASK>
    [   44.212045]  dump_stack_lvl+0x37/0x50
    [   44.212045]  print_report+0xcc/0x620
    [   44.212045]  ? __virt_addr_valid+0xf3/0x170
    [   44.212045]  ? memcmp+0x8b/0xb0
    [   44.212045]  kasan_report+0xb2/0xe0
    [   44.212045]  ? memcmp+0x8b/0xb0
    [   44.212045]  kasan_check_range+0x39/0x1c0
    [   44.212045]  memcmp+0x8b/0xb0
    [   44.212045]  xfrm_state_walk+0x21c/0x420
    [   44.212045]  ? __pfx_dump_one_state+0x10/0x10
    [   44.212045]  xfrm_dump_sa+0x1e2/0x290
    [   44.212045]  ? __pfx_xfrm_dump_sa+0x10/0x10
    [   44.212045]  ? __kernel_text_address+0xd/0x40
    [   44.212045]  ? kasan_unpoison+0x27/0x60
    [   44.212045]  ? mutex_lock+0x60/0xe0
    [   44.212045]  ? __pfx_mutex_lock+0x10/0x10
    [   44.212045]  ? kasan_save_stack+0x22/0x50
    [   44.212045]  netlink_dump+0x322/0x6c0
    [   44.212045]  ? __pfx_netlink_dump+0x10/0x10
    [   44.212045]  ? mutex_unlock+0x7f/0xd0
    [   44.212045]  ? __pfx_mutex_unlock+0x10/0x10
    [   44.212045]  __netlink_dump_start+0x353/0x430
    [   44.212045]  xfrm_user_rcv_msg+0x3a4/0x410
    [   44.212045]  ? __pfx__raw_spin_lock_irqsave+0x10/0x10
    [   44.212045]  ? __pfx_xfrm_user_rcv_msg+0x10/0x10
    [   44.212045]  ? __pfx_xfrm_dump_sa+0x10/0x10
    [   44.212045]  ? __pfx_xfrm_dump_sa_done+0x10/0x10
    [   44.212045]  ? __stack_depot_save+0x382/0x4e0
    [   44.212045]  ? filter_irq_stacks+0x1c/0x70
    [   44.212045]  ? kasan_save_stack+0x32/0x50
    [   44.212045]  ? kasan_save_stack+0x22/0x50
    [   44.212045]  ? kasan_set_track+0x25/0x30
    [   44.212045]  ? __kasan_slab_alloc+0x59/0x70
    [   44.212045]  ? kmem_cache_alloc_node+0xf7/0x260
    [   44.212045]  ? kmalloc_reserve+0xab/0x120
    [   44.212045]  ? __alloc_skb+0xcf/0x210
    [   44.212045]  ? netlink_sendmsg+0x509/0x700
    [   44.212045]  ? sock_sendmsg+0xde/0xe0
    [   44.212045]  ? __sys_sendto+0x18d/0x230
    [   44.212045]  ? __x64_sys_sendto+0x71/0x90
    [   44.212045]  ? do_syscall_64+0x3f/0x90
    [   44.212045]  ? entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [   44.212045]  ? netlink_sendmsg+0x509/0x700
    [   44.212045]  ? sock_sendmsg+0xde/0xe0
    [   44.212045]  ? __sys_sendto+0x18d/0x230
    [   44.212045]  ? __x64_sys_sendto+0x71/0x90
    [   44.212045]  ? do_syscall_64+0x3f/0x90
    [   44.212045]  ? entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [   44.212045]  ? kasan_save_stack+0x22/0x50
    [   44.212045]  ? kasan_set_track+0x25/0x30
    [   44.212045]  ? kasan_save_free_info+0x2e/0x50
    [   44.212045]  ? __kasan_slab_free+0x10a/0x190
    [   44.212045]  ? kmem_cache_free+0x9c/0x340
    [   44.212045]  ? netlink_recvmsg+0x23c/0x660
    [   44.212045]  ? sock_recvmsg+0xeb/0xf0
    [   44.212045]  ? __sys_recvfrom+0x13c/0x1f0
    [   44.212045]  ? __x64_sys_recvfrom+0x71/0x90
    [   44.212045]  ? do_syscall_64+0x3f/0x90
    [   44.212045]  ? entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [   44.212045]  ? copyout+0x3e/0x50
    [   44.212045]  netlink_rcv_skb+0xd6/0x210
    [   44.212045]  ? __pfx_xfrm_user_rcv_msg+0x10/0x10
    [   44.212045]  ? __pfx_netlink_rcv_skb+0x10/0x10
    [   44.212045]  ? __pfx_sock_has_perm+0x10/0x10
    [   44.212045]  ? mutex_lock+0x8d/0xe0
    [   44.212045]  ? __pfx_mutex_lock+0x10/0x10
    [   44.212045]  xfrm_netlink_rcv+0x44/0x50
    [   44.212045]  netlink_unicast+0x36f/0x4c0
    [   44.212045]  ? __pfx_netlink_unicast+0x10/0x10
    [   44.212045]  ? netlink_recvmsg+0x500/0x660
    [   44.212045]  netlink_sendmsg+0x3b7/0x700
    [   44.212045]  ? __pfx_netlink_sendmsg+0x10/0x10
    [   44.212045]  ? __pfx_netlink_sendmsg+0x10/0x10
    [   44.212045]  sock_sendmsg+0xde/0xe0
    [   44.212045]  __sys_sendto+0x18d/0x230
    [   44.212045]  ? __pfx___sys_sendto+0x10/0x10
    [   44.212045]  ? rcu_core+0x44a/0xe10
    [   44.212045]  ? __rseq_handle_notify_resume+0x45b/0x740
    [   44.212045]  ? _raw_spin_lock_irq+0x81/0xe0
    [   44.212045]  ? __pfx___rseq_handle_notify_resume+0x10/0x10
    [   44.212045]  ? __pfx_restore_fpregs_from_fpstate+0x10/0x10
    [   44.212045]  ? __pfx_blkcg_maybe_throttle_current+0x10/0x10
    [   44.212045]  ? __pfx_task_work_run+0x10/0x10
    [   44.212045]  __x64_sys_sendto+0x71/0x90
    [   44.212045]  do_syscall_64+0x3f/0x90
    [   44.212045]  entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [   44.212045] RIP: 0033:0x44b7da
    [   44.212045] RSP: 002b:00007ffdc8838548 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
    [   44.212045] RAX: ffffffffffffffda RBX: 00007ffdc8839978 RCX: 000000000044b7da
    [   44.212045] RDX: 0000000000000038 RSI: 00007ffdc8838770 RDI: 0000000000000003
    [   44.212045] RBP: 00007ffdc88385b0 R08: 00007ffdc883858c R09: 000000000000000c
    [   44.212045] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
    [   44.212045] R13: 00007ffdc8839968 R14: 00000000004c37d0 R15: 0000000000000001
    [   44.212045]  </TASK>
    [   44.212045]
    [   44.212045] Allocated by task 97:
    [   44.212045]  kasan_save_stack+0x22/0x50
    [   44.212045]  kasan_set_track+0x25/0x30
    [   44.212045]  __kasan_kmalloc+0x7f/0x90
    [   44.212045]  __kmalloc_node_track_caller+0x5b/0x140
    [   44.212045]  kmemdup+0x21/0x50
    [   44.212045]  xfrm_dump_sa+0x17d/0x290
    [   44.212045]  netlink_dump+0x322/0x6c0
    [   44.212045]  __netlink_dump_start+0x353/0x430
    [   44.212045]  xfrm_user_rcv_msg+0x3a4/0x410
    [   44.212045]  netlink_rcv_skb+0xd6/0x210
    [   44.212045]  xfrm_netlink_rcv+0x44/0x50
    [   44.212045]  netlink_unicast+0x36f/0x4c0
    [   44.212045]  netlink_sendmsg+0x3b7/0x700
    [   44.212045]  sock_sendmsg+0xde/0xe0
    [   44.212045]  __sys_sendto+0x18d/0x230
    [   44.212045]  __x64_sys_sendto+0x71/0x90
    [   44.212045]  do_syscall_64+0x3f/0x90
    [   44.212045]  entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [   44.212045]
    [   44.212045] The buggy address belongs to the object at ffff88800870f300
    [   44.212045]  which belongs to the cache kmalloc-64 of size 64
    [   44.212045] The buggy address is located 32 bytes inside of
    [   44.212045]  allocated 36-byte region [ffff88800870f300, ffff88800870f324)
    [   44.212045]
    [   44.212045] The buggy address belongs to the physical page:
    [   44.212045] page:00000000e4de16ee refcount:1 mapcount:0 mapping:000000000 ...
    [   44.212045] flags: 0x100000000000200(slab|node=0|zone=1)
    [   44.212045] page_type: 0xffffffff()
    [   44.212045] raw: 0100000000000200 ffff888004c41640 dead000000000122 0000000000000000
    [   44.212045] raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
    [   44.212045] page dumped because: kasan: bad access detected
    [   44.212045]
    [   44.212045] Memory state around the buggy address:
    [   44.212045]  ffff88800870f200: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
    [   44.212045]  ffff88800870f280: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
    [   44.212045] >ffff88800870f300: 00 00 00 00 04 fc fc fc fc fc fc fc fc fc fc fc
    [   44.212045]                                ^
    [   44.212045]  ffff88800870f380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [   44.212045]  ffff88800870f400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [   44.212045] ==================================================================

    By investigating the code, we find the root cause of this OOB is the lack
    of checks in xfrm_dump_sa(). The buggy code allows a malicious user to pass
    arbitrary value of filter->splen/dplen. Hence, with crafted xfrm states,
    the attacker can achieve 8 bytes heap OOB read, which causes info leak.

      if (attrs[XFRMA_ADDRESS_FILTER]) {
        filter = kmemdup(nla_data(attrs[XFRMA_ADDRESS_FILTER]),
            sizeof(*filter), GFP_KERNEL);
        if (filter == NULL)
          return -ENOMEM;
        // NO MORE CHECKS HERE !!!
      }

    This patch fixes the OOB by adding necessary boundary checks, just like
    the code in pfkey_dump() function.

    Fixes: d3623099d3 ("ipsec: add support of limited SA dump")
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
2023-09-01 14:01:09 -03:00
Jan Stancek 67467dfcb6 Merge: xfrm: out-of-bounds read of XFRMA_MTIMER_THRESH nlattr
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2922

Bugzilla: https://bugzilla.redhat.com/2218950
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git
CVE: CVE-2023-3773

commit 5e2424708da7207087934c5c75211e8584d553a0
Author: Lin Ma <linma@zju.edu.cn>
Date:   Sun Jul 23 15:41:10 2023 +0800

    xfrm: add forgotten nla_policy for XFRMA_MTIMER_THRESH

    The previous commit 4e484b3e969b ("xfrm: rate limit SA mapping change
    message to user space") added one additional attribute named
    XFRMA_MTIMER_THRESH and described its type at compat_policy
    (net/xfrm/xfrm_compat.c).

    However, the author forgot to also describe the nla_policy at
    xfrma_policy (net/xfrm/xfrm_user.c). Hence, this suppose NLA_U32 (4
    bytes) value can be faked as empty (0 bytes) by a malicious user, which
    leads to 4 bytes overflow read and heap information leak when parsing
    nlattrs.

    To exploit this, one malicious user can spray the SLUB objects and then
    leverage this 4 bytes OOB read to leak the heap data into
    x->mapping_maxage (see xfrm_update_ae_params(...)), and leak it to
    userspace via copy_to_user_state_extra(...).

    The above bug is assigned CVE-2023-3773. To fix it, this commit just
    completes the nla_policy description for XFRMA_MTIMER_THRESH, which
    enforces the length check and avoids such OOB read.

    Fixes: 4e484b3e969b ("xfrm: rate limit SA mapping change message to user space")
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Daniel Mendes <dmendes@redhat.com>

Approved-by: Xin Long <lxin@redhat.com>
Approved-by: Sabrina Dubroca <sdubroca@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-08-18 16:21:26 +02:00
Daniel Mendes bee5bf53e4 xfrm: out-of-bounds read of XFRMA_MTIMER_THRESH nlattr
Bugzilla: https://bugzilla.redhat.com/2218950
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git
CVE: CVE-2023-3773

commit 5e2424708da7207087934c5c75211e8584d553a0
Author: Lin Ma <linma@zju.edu.cn>
Date:   Sun Jul 23 15:41:10 2023 +0800

    xfrm: add forgotten nla_policy for XFRMA_MTIMER_THRESH

    The previous commit 4e484b3e969b ("xfrm: rate limit SA mapping change
    message to user space") added one additional attribute named
    XFRMA_MTIMER_THRESH and described its type at compat_policy
    (net/xfrm/xfrm_compat.c).

    However, the author forgot to also describe the nla_policy at
    xfrma_policy (net/xfrm/xfrm_user.c). Hence, this suppose NLA_U32 (4
    bytes) value can be faked as empty (0 bytes) by a malicious user, which
    leads to 4 bytes overflow read and heap information leak when parsing
    nlattrs.

    To exploit this, one malicious user can spray the SLUB objects and then
    leverage this 4 bytes OOB read to leak the heap data into
    x->mapping_maxage (see xfrm_update_ae_params(...)), and leak it to
    userspace via copy_to_user_state_extra(...).

    The above bug is assigned CVE-2023-3773. To fix it, this commit just
    completes the nla_policy description for XFRMA_MTIMER_THRESH, which
    enforces the length check and avoids such OOB read.

    Fixes: 4e484b3e969b ("xfrm: rate limit SA mapping change message to user space")
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Daniel Mendes <dmendes@redhat.com>
2023-08-15 11:40:52 -04:00
Daniel Mendes 4afe47c7ca xfrm: add NULL check in xfrm_update_ae_params
Bugzilla: https://bugzilla.redhat.com/2218947
CVE: CVE-2023-3772
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git

commit 00374d9b6d9f932802b55181be9831aa948e5b7c (HEAD)
Author: Lin Ma <linma@zju.edu.cn>
Date:   Fri Jul 21 22:51:03 2023 +0800

    xfrm: add NULL check in xfrm_update_ae_params

    Normally, x->replay_esn and x->preplay_esn should be allocated at
    xfrm_alloc_replay_state_esn(...) in xfrm_state_construct(...), hence the
    xfrm_update_ae_params(...) is okay to update them. However, the current
    implementation of xfrm_new_ae(...) allows a malicious user to directly
    dereference a NULL pointer and crash the kernel like below.

    BUG: kernel NULL pointer dereference, address: 0000000000000000
    PGD 8253067 P4D 8253067 PUD 8e0e067 PMD 0
    Oops: 0002 [#1] PREEMPT SMP KASAN NOPTI
    CPU: 0 PID: 98 Comm: poc.npd Not tainted 6.4.0-rc7-00072-gdad9774deaf1 #8
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.o4
    RIP: 0010:memcpy_orig+0xad/0x140
    Code: e8 4c 89 5f e0 48 8d 7f e0 73 d2 83 c2 20 48 29 d6 48 29 d7 83 fa 10 72 34 4c 8b 06 4c 8b 4e 08 c
    RSP: 0018:ffff888008f57658 EFLAGS: 00000202
    RAX: 0000000000000000 RBX: ffff888008bd0000 RCX: ffffffff8238e571
    RDX: 0000000000000018 RSI: ffff888007f64844 RDI: 0000000000000000
    RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000000 R12: ffff888008f57818
    R13: ffff888007f64aa4 R14: 0000000000000000 R15: 0000000000000000
    FS:  00000000014013c0(0000) GS:ffff88806d600000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000000000000 CR3: 00000000054d8000 CR4: 00000000000006f0
    Call Trace:
     <TASK>
     ? __die+0x1f/0x70
     ? page_fault_oops+0x1e8/0x500
     ? __pfx_is_prefetch.constprop.0+0x10/0x10
     ? __pfx_page_fault_oops+0x10/0x10
     ? _raw_spin_unlock_irqrestore+0x11/0x40
     ? fixup_exception+0x36/0x460
     ? _raw_spin_unlock_irqrestore+0x11/0x40
     ? exc_page_fault+0x5e/0xc0
     ? asm_exc_page_fault+0x26/0x30
     ? xfrm_update_ae_params+0xd1/0x260
     ? memcpy_orig+0xad/0x140
     ? __pfx__raw_spin_lock_bh+0x10/0x10
     xfrm_update_ae_params+0xe7/0x260
     xfrm_new_ae+0x298/0x4e0
     ? __pfx_xfrm_new_ae+0x10/0x10
     ? __pfx_xfrm_new_ae+0x10/0x10
     xfrm_user_rcv_msg+0x25a/0x410
     ? __pfx_xfrm_user_rcv_msg+0x10/0x10
     ? __alloc_skb+0xcf/0x210
     ? stack_trace_save+0x90/0xd0
     ? filter_irq_stacks+0x1c/0x70
     ? __stack_depot_save+0x39/0x4e0
     ? __kasan_slab_free+0x10a/0x190
     ? kmem_cache_free+0x9c/0x340
     ? netlink_recvmsg+0x23c/0x660
     ? sock_recvmsg+0xeb/0xf0
     ? __sys_recvfrom+0x13c/0x1f0
     ? __x64_sys_recvfrom+0x71/0x90
     ? do_syscall_64+0x3f/0x90
     ? entry_SYSCALL_64_after_hwframe+0x72/0xdc
     ? copyout+0x3e/0x50
     netlink_rcv_skb+0xd6/0x210
     ? __pfx_xfrm_user_rcv_msg+0x10/0x10
     ? __pfx_netlink_rcv_skb+0x10/0x10
     ? __pfx_sock_has_perm+0x10/0x10
     ? mutex_lock+0x8d/0xe0
     ? __pfx_mutex_lock+0x10/0x10
     xfrm_netlink_rcv+0x44/0x50
     netlink_unicast+0x36f/0x4c0
     ? __pfx_netlink_unicast+0x10/0x10
     ? netlink_recvmsg+0x500/0x660
     netlink_sendmsg+0x3b7/0x700

    This Null-ptr-deref bug is assigned CVE-2023-3772. And this commit
    adds additional NULL check in xfrm_update_ae_params to fix the NPD.

    Fixes: d8647b79c3 ("xfrm: Add user interface for esn and big anti-replay windows")
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
    Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Daniel Mendes <dmendes@redhat.com>
2023-08-11 10:51:50 -04:00
Sabrina Dubroca dc00ab5b0b xfrm: Reject optional tunnel/BEET mode templates in outbound policies
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2218900
Tested: IPsec tests

commit 3d776e31c841ba2f69895d2255a49320bec7cea6
Author: Tobias Brunner <tobias@strongswan.org>
Date:   Tue May 9 10:59:58 2023 +0200

    xfrm: Reject optional tunnel/BEET mode templates in outbound policies

    xfrm_state_find() uses `encap_family` of the current template with
    the passed local and remote addresses to find a matching state.
    If an optional tunnel or BEET mode template is skipped in a mixed-family
    scenario, there could be a mismatch causing an out-of-bounds read as
    the addresses were not replaced to match the family of the next template.

    While there are theoretical use cases for optional templates in outbound
    policies, the only practical one is to skip IPComp states in inbound
    policies if uncompressed packets are received that are handled by an
    implicitly created IPIP state instead.

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Signed-off-by: Tobias Brunner <tobias@strongswan.org>
    Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-06-30 20:04:11 +02:00
Sabrina Dubroca 6a410b2a8a xfrm: release all offloaded policy memory
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2218900
Tested: IPsec tests

commit 94b95dfaa814f565d92f5a65f0ff12a483095522
Author: Leon Romanovsky <leon@kernel.org>
Date:   Wed Apr 19 15:19:07 2023 +0300

    xfrm: release all offloaded policy memory

    Failure to add offloaded policy will cause to the following
    error once user will try to reload driver.

    Unregister_netdevice: waiting for eth3 to become free. Usage count = 2

    This was caused by xfrm_dev_policy_add() which increments reference
    to net_device. That reference was supposed to be decremented
    in xfrm_dev_policy_free(). However the latter wasn't called.

     unregister_netdevice: waiting for eth3 to become free. Usage count = 2
     leaked reference.
      xfrm_dev_policy_add+0xff/0x3d0
      xfrm_policy_construct+0x352/0x420
      xfrm_add_policy+0x179/0x320
      xfrm_user_rcv_msg+0x1d2/0x3d0
      netlink_rcv_skb+0xe0/0x210
      xfrm_netlink_rcv+0x45/0x50
      netlink_unicast+0x346/0x490
      netlink_sendmsg+0x3b0/0x6c0
      sock_sendmsg+0x73/0xc0
      sock_write_iter+0x13b/0x1f0
      vfs_write+0x528/0x5d0
      ksys_write+0x120/0x150
      do_syscall_64+0x3d/0x90
      entry_SYSCALL_64_after_hwframe+0x46/0xb0

    Fixes: 919e43fad516 ("xfrm: add an interface to offload policy")
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Reviewed-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-06-30 20:04:05 +02:00
Jan Stancek b2979a954d Merge: xfrm: backport fixes from upstream
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2426

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2189210
Tested: ipsec tests

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>

Approved-by: Hangbin Liu <haliu@redhat.com>
Approved-by: Andrea Claudi <aclaudi@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-05-19 08:29:26 +02:00
Sabrina Dubroca cf8bd329f4 xfrm: Zero padding when dumping algos and encap
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2189210
Tested: ipsec tests

commit 8222d5910dae08213b6d9d4bc9a7f8502855e624
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Feb 9 09:09:52 2023 +0800

    xfrm: Zero padding when dumping algos and encap

    When copying data to user-space we should ensure that only valid
    data is copied over.  Padding in structures may be filled with
    random (possibly sensitve) data and should never be given directly
    to user-space.

    This patch fixes the copying of xfrm algorithms and the encap
    template in xfrm_user so that padding is zeroed.

    Reported-by: syzbot+fa5414772d5c445dac3c@syzkaller.appspotmail.com
    Reported-by: Hyunwoo Kim <v4bel@theori.io>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-26 11:11:40 +02:00
Sabrina Dubroca f470d23f28 xfrm: add an interface to offload policy
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178699
Tested: basic IPsec tests + offload tests

commit 919e43fad5163a8ceb39826ecdee897a9f799351
Author: Leon Romanovsky <leon@kernel.org>
Date:   Fri Dec 2 20:41:29 2022 +0200

    xfrm: add an interface to offload policy

    Extend netlink interface to add and delete XFRM policy from the device.
    This functionality is a first step to implement packet IPsec offload solution.

    Signed-off-by: Raed Salem <raeds@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-19 11:51:36 +02:00
Sabrina Dubroca ee98865485 xfrm: add new packet offload flag
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178699
Tested: basic IPsec tests + offload tests

commit d14f28b8c1de668bab863bf5892a49c824cb110d
Author: Leon Romanovsky <leon@kernel.org>
Date:   Fri Dec 2 20:41:27 2022 +0200

    xfrm: add new packet offload flag

    In the next patches, the xfrm core code will be extended to support
    new type of offload - packet offload. In that mode, both policy and state
    should be specially configured in order to perform whole offloaded data
    path.

    Full offload takes care of encryption, decryption, encapsulation and
    other operations with headers.

    As this mode is new for XFRM policy flow, we can "start fresh" with flag
    bits and release first and second bit for future use.

    Reviewed-by: Raed Salem <raeds@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-19 11:51:35 +02:00
Sabrina Dubroca f2275c15a2 xfrm: add extack to xfrm_set_spdinfo
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit a741721680092b64ff71fc1f1c790123c6d40a02
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:44 2022 +0100

    xfrm: add extack to xfrm_set_spdinfo

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:17 +02:00
Sabrina Dubroca 531a02c2d3 xfrm: add extack to xfrm_alloc_userspi
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit c2dad11e0466a27d40041845cf63cdfb4fbd991f
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:43 2022 +0100

    xfrm: add extack to xfrm_alloc_userspi

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:17 +02:00
Sabrina Dubroca 6ab9fd6f9d xfrm: add extack to xfrm_do_migrate
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit bd12240337f43522b99c43f8976af34c712b5f57
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:42 2022 +0100

    xfrm: add extack to xfrm_do_migrate

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:16 +02:00
Sabrina Dubroca 6bba184b5d xfrm: add extack to xfrm_new_ae and xfrm_replay_verify_len
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 643bc1a2ee30efc9ab832401e89c9400cd9f52ac
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:41 2022 +0100

    xfrm: add extack to xfrm_new_ae and xfrm_replay_verify_len

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:15 +02:00
Sabrina Dubroca 2ad89d669b xfrm: add extack to xfrm_del_sa
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 880e475d2b0b1131a6e91464b2145820893e4ddf
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:40 2022 +0100

    xfrm: add extack to xfrm_del_sa

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:15 +02:00
Sabrina Dubroca 1fc94260ac xfrm: add extack to xfrm_add_sa_expire
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit a25b19f36f921b90bcb826c80b568266b8ad40a4
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:39 2022 +0100

    xfrm: add extack to xfrm_add_sa_expire

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:14 +02:00
Sabrina Dubroca 0d72c5d39a xfrm: a few coding style clean ups
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit f157c416c51ab8b7f5e833dfde8ace3a6325c19a
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Nov 24 15:43:38 2022 +0100

    xfrm: a few coding style clean ups

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:14 +02:00
Sabrina Dubroca 3e95d0bd48 xfrm: add extack support to xfrm_init_replay
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 1cf9a3ae3e2de359471a7036f48ac59e48b15256
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:06 2022 +0200

    xfrm: add extack support to xfrm_init_replay

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:10 +02:00
Sabrina Dubroca 25decd6fb5 xfrm: add extack to __xfrm_init_state
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 741f9a1064985512567eca1552643738ecfb5cc5
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:05 2022 +0200

    xfrm: add extack to __xfrm_init_state

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:10 +02:00
Sabrina Dubroca fd5a451ffb xfrm: add extack to attach_*
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 2b9168266d15dbb4b083b52e775c0399db427d4c
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:04 2022 +0200

    xfrm: add extack to attach_*

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:09 +02:00
Sabrina Dubroca 1ba9cf3400 xfrm: add extack support to xfrm_dev_state_add
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit adb5c33e4d4c83fb848a402e2191fbf3e2bf50d1
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:03 2022 +0200

    xfrm: add extack support to xfrm_dev_state_add

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:09 +02:00
Sabrina Dubroca 7e289639cb xfrm: add extack to verify_one_alg, verify_auth_trunc, verify_aead
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 1fc8fde553917bca7c9b65fafb045a2a5c97e683
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:02 2022 +0200

    xfrm: add extack to verify_one_alg, verify_auth_trunc, verify_aead

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:08 +02:00
Sabrina Dubroca 45461ca68b xfrm: add extack to verify_replay
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 785b87b220859170d8ca0e95c6396c7cfadce627
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:01 2022 +0200

    xfrm: add extack to verify_replay

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:08 +02:00
Sabrina Dubroca 9432dea5c1 xfrm: add extack support to verify_newsa_info
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 6999aae17a7b66c56e6cc8e05b3cd51718c3bfe3
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Sep 14 19:04:00 2022 +0200

    xfrm: add extack support to verify_newsa_info

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:07 +02:00
Sabrina Dubroca 9cc4560131 xfrm: add extack to verify_sec_ctx_len
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 08a717e4803798e066aa6b69ebf69da9fc8e1758
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:12 2022 +0200

    xfrm: add extack to verify_sec_ctx_len

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:07 +02:00
Sabrina Dubroca 3b4e5d3ec3 xfrm: add extack to validate_tmpl
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit d37bed89f082cb84cbdf1f38114cde1defc1724c
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:11 2022 +0200

    xfrm: add extack to validate_tmpl

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:06 +02:00
Sabrina Dubroca fb0e91324b xfrm: add extack to verify_policy_type
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit fb7deaba40cfc6b5eb91b7431102520c4b156513
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:10 2022 +0200

    xfrm: add extack to verify_policy_type

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:06 +02:00
Sabrina Dubroca 4fc4237ec9 xfrm: add extack to verify_policy_dir
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 24fc544fb525a2d1cabe4e77e673938bf2e45aed
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:09 2022 +0200

    xfrm: add extack to verify_policy_dir

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:05 +02:00
Sabrina Dubroca cdb145c0b6 xfrm: add extack support to verify_newpolicy_info
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit ec2b4f01536dcd9ecaae91e99334b5fdb510c0e2
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:08 2022 +0200

    xfrm: add extack support to verify_newpolicy_info

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:05 +02:00
Sabrina Dubroca 6d3c411152 xfrm: propagate extack to all netlink doit handlers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 3bec6c3e83b5c125ff35e3dae3127c8d62046a1d
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Tue Aug 30 16:23:07 2022 +0200

    xfrm: propagate extack to all netlink doit handlers

    xfrm_user_rcv_msg() already handles extack, we just need to pass it down.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:04 +02:00
Sabrina Dubroca 06e654d0b1 xfrm: rate limit SA mapping change message to user space
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 4e484b3e969b52effd95c17f7a86f39208b2ccf4
Author: Antony Antony <antony.antony@secunet.com>
Date:   Wed Dec 22 14:11:18 2021 +0100

    xfrm: rate limit SA mapping change message to user space

    Kernel generates mapping change message, XFRM_MSG_MAPPING,
    when a source port chage is detected on a input state with UDP
    encapsulation set.  Kernel generates a message for each IPsec packet
    with new source port.  For a high speed flow per packet mapping change
    message can be excessive, and can overload the user space listener.

    Introduce rate limiting for XFRM_MSG_MAPPING message to the user space.

    The rate limiting is configurable via netlink, when adding a new SA or
    updating it. Use the new attribute XFRMA_MTIMER_THRESH in seconds.

    v1->v2 change:
            update xfrm_sa_len()

    v2->v3 changes:
            use u32 insted unsigned long to reduce size of struct xfrm_state
            fix xfrm_ompat size Reported-by: kernel test robot <lkp@intel.com>
            accept XFRM_MSG_MAPPING only when XFRMA_ENCAP is present

    Co-developed-by: Thomas Egerer <thomas.egerer@secunet.com>
    Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
    Signed-off-by: Antony Antony <antony.antony@secunet.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:03 +02:00
Sabrina Dubroca 8a87d02045 xfrm: Check if_id in xfrm_migrate
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit c1aca3080e382886e2e58e809787441984a2f89b
Author: Yan Yan <evitayan@google.com>
Date:   Tue Jan 18 16:00:13 2022 -0800

    xfrm: Check if_id in xfrm_migrate

    This patch enables distinguishing SAs and SPs based on if_id during
    the xfrm_migrate flow. This ensures support for xfrm interfaces
    throughout the SA/SP lifecycle.

    When there are multiple existing SPs with the same direction,
    the same xfrm_selector and different endpoint addresses,
    xfrm_migrate might fail with ENODATA.

    Specifically, the code path for performing xfrm_migrate is:
      Stage 1: find policy to migrate with
        xfrm_migrate_policy_find(sel, dir, type, net)
      Stage 2: find and update state(s) with
        xfrm_migrate_state_find(mp, net)
      Stage 3: update endpoint address(es) of template(s) with
        xfrm_policy_migrate(pol, m, num_migrate)

    Currently "Stage 1" always returns the first xfrm_policy that
    matches, and "Stage 3" looks for the xfrm_tmpl that matches the
    old endpoint address. Thus if there are multiple xfrm_policy
    with same selector, direction, type and net, "Stage 1" might
    rertun a wrong xfrm_policy and "Stage 3" will fail with ENODATA
    because it cannot find a xfrm_tmpl with the matching endpoint
    address.

    The fix is to allow userspace to pass an if_id and add if_id
    to the matching rule in Stage 1 and Stage 2 since if_id is a
    unique ID for xfrm_policy and xfrm_state. For compatibility,
    if_id will only be checked if the attribute is set.

    Tested with additions to Android's kernel unit test suite:
    https://android-review.googlesource.com/c/kernel/tests/+/1668886

    Signed-off-by: Yan Yan <evitayan@google.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:02 +02:00
Sabrina Dubroca 7e18e73490 xfrm: fix rcu lock in xfrm_notify_userpolicy()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 93ec1320b0170d7a207eda2d119c669b673401ed
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Wed Sep 22 10:50:06 2021 +0200

    xfrm: fix rcu lock in xfrm_notify_userpolicy()

    As stated in the comment above xfrm_nlmsg_multicast(), rcu read lock must
    be held before calling this function.

    Reported-by: syzbot+3d9866419b4aa8f985d6@syzkaller.appspotmail.com
    Fixes: 703b94b93c19 ("xfrm: notify default policy on update")
    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:02 +02:00
Sabrina Dubroca 2049b51841 xfrm: rework default policy structure
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit b58b1f563ab78955d37e9e43e02790a85c66ac05
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Mon Mar 14 11:38:22 2022 +0100

    xfrm: rework default policy structure

    This is a follow up of commit f8d858e607b2 ("xfrm: make user policy API
    complete"). The goal is to align userland API to the internal structures.

    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
    Reviewed-by:  Antony Antony <antony.antony@secunet.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:02:01 +02:00
Sabrina Dubroca cf25b7c537 xfrm: notify default policy on update
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 88d0adb5f13b1c52fbb7d755f6f79db18c2f0c2c
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Tue Sep 14 16:46:34 2021 +0200

    xfrm: notify default policy on update

    This configuration knob is very sensible, it should be notified when
    changing.

    Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy")
    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:01:59 +02:00
Sabrina Dubroca c8486d8f7d xfrm: make user policy API complete
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit f8d858e607b2a36808ac6d4218f5f5203d7a7d63
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Tue Sep 14 16:46:33 2021 +0200

    xfrm: make user policy API complete

    >From a userland POV, this API was based on some magic values:
     - dirmask and action were bitfields but meaning of bits
       (XFRM_POL_DEFAULT_*) are not exported;
     - action is confusing, if a bit is set, does it mean drop or accept?

    Let's try to simplify this uapi by using explicit field and macros.

    Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy")
    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:01:59 +02:00
Sabrina Dubroca 3ac983f2eb net: xfrm: fix shift-out-of-bounds in xfrm_get_default
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 3c10ffddc61f8a1a59e29a110ba70b47e679206a
Author: Pavel Skripkin <paskripkin@gmail.com>
Date:   Thu Sep 2 22:04:00 2021 +0300

    net: xfrm: fix shift-out-of-bounds in xfrm_get_default

    Syzbot hit shift-out-of-bounds in xfrm_get_default. The problem was in
    missing validation check for user data.

    up->dirmask comes from user-space, so we need to check if this value
    is less than XFRM_USERPOLICY_DIRMASK_MAX to avoid shift-out-of-bounds bugs.

    Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy")
    Reported-and-tested-by: syzbot+b2be9dd8ca6f6c73ee2d@syzkaller.appspotmail.com
    Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:01:58 +02:00
Sabrina Dubroca 6a6e74b1c0 net: xfrm: fix shift-out-of-bounce
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 5d8dbb7fb82b8661c16d496644b931c0e2e3a12e
Author: Pavel Skripkin <paskripkin@gmail.com>
Date:   Wed Jul 28 19:38:18 2021 +0300

    net: xfrm: fix shift-out-of-bounce

    We need to check up->dirmask to avoid shift-out-of-bounce bug,
    since up->dirmask comes from userspace.

    Also, added XFRM_USERPOLICY_DIRMASK_MAX constant to uapi to inform
    user-space that up->dirmask has maximum possible value

    Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy")
    Reported-and-tested-by: syzbot+9cd5837a045bbee5b810@syzkaller.appspotmail.com
    Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:01:57 +02:00
Sabrina Dubroca ee93df1321 xfrm: Add possibility to set the default to block if we have no policy
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 2d151d39073aff498358543801fca0f670fea981
Author: Steffen Klassert <steffen.klassert@secunet.com>
Date:   Sun Jul 18 09:11:06 2021 +0200

    xfrm: Add possibility to set the default to block if we have no policy

    As the default we assume the traffic to pass, if we have no
    matching IPsec policy. With this patch, we have a possibility to
    change this default from allow to block. It can be configured
    via netlink. Each direction (input/output/forward) can be
    configured separately. With the default to block configuered,
    we need allow policies for all packet flows we accept.
    We do not use default policy lookup for the loopback device.

    v1->v2
     - fix compiling when XFRM is disabled
     - Reported-by: kernel test robot <lkp@intel.com>

    Co-developed-by: Christian Langrock <christian.langrock@secunet.com>
    Signed-off-by: Christian Langrock <christian.langrock@secunet.com>
    Co-developed-by: Antony Antony <antony.antony@secunet.com>
    Signed-off-by: Antony Antony <antony.antony@secunet.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-03-27 17:01:56 +02:00
Eric Chanudet f6b998dbea xfrm: Use memset_after() to clear padding
Bugzilla: https://bugzilla.redhat.com/2159468

commit caf283d040f53bc4fd81ce3d2a1a364b069cfd7d
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Jun 17 08:34:19 2021 -0700

    xfrm: Use memset_after() to clear padding

    In preparation for FORTIFY_SOURCE performing compile-time and run-time
    field bounds checking for memset(), avoid intentionally writing across
    neighboring fields.

    Clear trailing padding bytes using the new helper so that memset()
    doesn't get confused about writing "past the end" of the last struct
    member. There is no change to the resulting machine code.

    Cc: Steffen Klassert <steffen.klassert@secunet.com>
    Cc: Herbert Xu <herbert@gondor.apana.org.au>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Jakub Kicinski <kuba@kernel.org>
    Cc: netdev@vger.kernel.org
    Signed-off-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Eric Chanudet <echanude@redhat.com>
2023-01-09 13:32:41 -05:00