Skip to content

[lts88] nvmet-tcp: Fix a possible UAF in queue intialization setup #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

bmastbergen
Copy link
Collaborator

jira VULN-3183
cve CVE-2023-5178

commit-author Sagi Grimberg <sagi@grimberg.me>
commit d920abd1e7c4884f9ecd0749d1921b7ab19ddfbd

From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."

Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.

Also, be extra careful not to continue processing the socket, so set queue rcv_state to NVMET_TCP_RECV_ERR upon a socket error.

	Cc: stable@vger.kernel.org
	Reported-by: Alon Zahavi <zahavi.alon@gmail.com>
	Tested-by: Alon Zahavi <zahavi.alon@gmail.com>
	Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
	Reviewed-by: Christoph Hellwig <hch@lst.de>
	Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
	Signed-off-by: Keith Busch <kbusch@kernel.org>
(cherry picked from commit d920abd1e7c4884f9ecd0749d1921b7ab19ddfbd)
	Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>

Build log

/home/brett/kernel-src-tree
no .config file found, moving on
[TIMER]{MRPROPER}: 0s
x86_64 architecture detected, copying config
'configs/kernel-x86_64.config' -> '.config'
Setting Local Version for build
CONFIG_LOCALVERSION="-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e"
Making olddefconfig
--
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --olddefconfig Kconfig
#
# configuration written to .config
#
Starting Build
scripts/kconfig/conf  --syncconfig Kconfig
  SYSTBL  arch/x86/include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/include/generated/asm/syscalls_64.h
--
  LD [M]  sound/usb/usx2y/snd-usb-usx2y.ko
  LD [M]  sound/virtio/virtio_snd.ko
  LD [M]  sound/x86/snd-hdmi-lpe-audio.ko
  LD [M]  sound/xen/snd_xen_front.ko
  LD [M]  virt/lib/irqbypass.ko
[TIMER]{BUILD}: 1125s
Making Modules
  INSTALL arch/x86/crypto/blowfish-x86_64.ko
  INSTALL arch/x86/crypto/camellia-aesni-avx-x86_64.ko
  INSTALL arch/x86/crypto/camellia-aesni-avx2.ko
  INSTALL arch/x86/crypto/camellia-x86_64.ko
--
  INSTALL sound/virtio/virtio_snd.ko
  INSTALL sound/x86/snd-hdmi-lpe-audio.ko
  INSTALL sound/xen/snd_xen_front.ko
  INSTALL virt/lib/irqbypass.ko
  DEPMOD  4.18.0-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e+
[TIMER]{MODULES}: 12s
Making Install
sh ./arch/x86/boot/install.sh 4.18.0-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e+ arch/x86/boot/bzImage \
	System.map "/boot"
[TIMER]{INSTALL}: 99s
Checking kABI
Checking kABI
kABI check passed
Setting Default Kernel to /boot/vmlinuz-4.18.0-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e+ and Index to 2
Hopefully Grub2.0 took everything ... rebooting after time metrices
[TIMER]{MRPROPER}: 0s
[TIMER]{BUILD}: 1125s
[TIMER]{MODULES}: 12s
[TIMER]{INSTALL}: 99s
[TIMER]{TOTAL} 1251s
Rebooting in 10 seconds

Testing

kselftests were run before and after applying the fix

selftest-4.18.0-477.27.1.el8_8.88ciq_lts.5.2.x86_64.log

selftest-4.18.0-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e+.log

brett@lycia ~/ciq/vuln-3183 % grep ^ok selftest-4.18.0-477.27.1.el8_8.88ciq_lts.5.2.x86_64.log | wc -l
240
brett@lycia ~/ciq/vuln-3183 % grep ^ok selftest-4.18.0-bmastbergen_ciqlts8_8_VULN-3183-a190583ce34e+.log | wc -l
239
brett@lycia ~/ciq/vuln-3183 %

jira VULN-3183
cve CVE-2023-5178
commit-author Sagi Grimberg <sagi@grimberg.me>
commit d920abd

From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel,
a malicious user can cause a UAF and a double free, which may lead to
RCE (may also lead to an LPE in case the attacker already has local
privileges)."

Hence, when a queue initialization fails after the ahash requests are
allocated, it is guaranteed that the queue removal async work will be
called, hence leave the deallocation to the queue removal.

Also, be extra careful not to continue processing the socket, so set
queue rcv_state to NVMET_TCP_RECV_ERR upon a socket error.

	Cc: stable@vger.kernel.org
	Reported-by: Alon Zahavi <zahavi.alon@gmail.com>
	Tested-by: Alon Zahavi <zahavi.alon@gmail.com>
	Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
	Reviewed-by: Christoph Hellwig <hch@lst.de>
	Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
	Signed-off-by: Keith Busch <kbusch@kernel.org>
(cherry picked from commit d920abd)
	Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
Copy link

@thefossguy-ciq thefossguy-ciq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚤

Copy link
Collaborator

@PlaidCat PlaidCat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@bmastbergen bmastbergen merged commit c2ec993 into ciqlts8_8 Jun 9, 2025
3 checks passed
@bmastbergen bmastbergen deleted the bmastbergen_ciqlts8_8/VULN-3183 branch June 9, 2025 16:25
github-actions bot pushed a commit that referenced this pull request Jun 10, 2025
…'async'

JIRA: https://issues.redhat.com/browse/RHEL-87766
Upstream Status: merged into the linux.git

commit 4ebd9a5
Author: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
Date:   Sat Dec 21 14:07:07 2024 -0800

    crypto: iaa - Fix IAA disabling that occurs when sync_mode is set to 'async'

    With the latest mm-unstable, setting the iaa_crypto sync_mode to 'async'
    causes crypto testmgr.c test_acomp() failure and dmesg call traces, and
    zswap being unable to use 'deflate-iaa' as a compressor:

    echo async > /sys/bus/dsa/drivers/crypto/sync_mode

    [  255.271030] zswap: compressor deflate-iaa not available
    [  369.960673] INFO: task cryptomgr_test:4889 blocked for more than 122 seconds.
    [  369.970127]       Not tainted 6.13.0-rc1-mm-unstable-12-16-2024+ #324
    [  369.977411] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    [  369.986246] task:cryptomgr_test  state:D stack:0     pid:4889  tgid:4889  ppid:2      flags:0x00004000
    [  369.986253] Call Trace:
    [  369.986256]  <TASK>
    [  369.986260]  __schedule+0x45c/0xfa0
    [  369.986273]  schedule+0x2e/0xb0
    [  369.986277]  schedule_timeout+0xe7/0x100
    [  369.986284]  ? __prepare_to_swait+0x4e/0x70
    [  369.986290]  wait_for_completion+0x8d/0x120
    [  369.986293]  test_acomp+0x284/0x670
    [  369.986305]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986312]  alg_test_comp+0x263/0x440
    [  369.986315]  ? sched_balance_newidle+0x259/0x430
    [  369.986320]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986323]  alg_test.part.27+0x103/0x410
    [  369.986326]  ? __schedule+0x464/0xfa0
    [  369.986330]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986333]  cryptomgr_test+0x20/0x40
    [  369.986336]  kthread+0xda/0x110
    [  369.986344]  ? __pfx_kthread+0x10/0x10
    [  369.986346]  ret_from_fork+0x2d/0x40
    [  369.986355]  ? __pfx_kthread+0x10/0x10
    [  369.986358]  ret_from_fork_asm+0x1a/0x30
    [  369.986365]  </TASK>

    This happens because the only async polling without interrupts that
    iaa_crypto currently implements is with the 'sync' mode. With 'async',
    iaa_crypto calls to compress/decompress submit the descriptor and return
    -EINPROGRESS, without any mechanism in the driver to poll for
    completions. Hence callers such as test_acomp() in crypto/testmgr.c or
    zswap, that wrap the calls to crypto_acomp_compress() and
    crypto_acomp_decompress() in synchronous wrappers, will block
    indefinitely. Even before zswap can notice this problem, the crypto
    testmgr.c's test_acomp() will fail and prevent registration of
    "deflate-iaa" as a valid crypto acomp algorithm, thereby disallowing the
    use of "deflate-iaa" as a zswap compress (zswap will fall-back to the
    default compressor in this case).

    To fix this issue, this patch modifies the iaa_crypto sync_mode set
    function to treat 'async' equivalent to 'sync', so that the correct and
    only supported driver async polling without interrupts implementation is
    enabled, and zswap can use 'deflate-iaa' as the compressor.

    Hence, with this patch, this is what will happen:

    echo async > /sys/bus/dsa/drivers/crypto/sync_mode
    cat /sys/bus/dsa/drivers/crypto/sync_mode
    sync

    There are no crypto/testmgr.c test_acomp() errors, no call traces and zswap
    can use 'deflate-iaa' without any errors. The iaa_crypto documentation has
    also been updated to mention this caveat with 'async' and what to expect
    with this fix.

    True iaa_crypto async polling without interrupts is enabled in patch
    "crypto: iaa - Implement batch_compress(), batch_decompress() API in
    iaa_crypto." [1] which is under review as part of the "zswap IAA compress
    batching" patch-series [2]. Until this is merged, we would appreciate it if
    this current patch can be considered for a hotfix.

    [1]: https://patchwork.kernel.org/project/linux-mm/patch/20241221063119.29140-5-kanchana.p.sridhar@intel.com/
    [2]: https://patchwork.kernel.org/project/linux-mm/list/?series=920084

    Fixes: 09646c9 ("crypto: iaa - Add irq support for the crypto async interface")
    Signed-off-by: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
github-actions bot pushed a commit to wizctrl/kernel-src-tree that referenced this pull request Jun 10, 2025
…'async'

JIRA: https://issues.redhat.com/browse/RHEL-87768
Upstream Status: merged into the linux.git

commit 4ebd9a5
Author: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
Date:   Sat Dec 21 14:07:07 2024 -0800

    crypto: iaa - Fix IAA disabling that occurs when sync_mode is set to 'async'

    With the latest mm-unstable, setting the iaa_crypto sync_mode to 'async'
    causes crypto testmgr.c test_acomp() failure and dmesg call traces, and
    zswap being unable to use 'deflate-iaa' as a compressor:

    echo async > /sys/bus/dsa/drivers/crypto/sync_mode

    [  255.271030] zswap: compressor deflate-iaa not available
    [  369.960673] INFO: task cryptomgr_test:4889 blocked for more than 122 seconds.
    [  369.970127]       Not tainted 6.13.0-rc1-mm-unstable-12-16-2024+ ctrliq#324
    [  369.977411] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    [  369.986246] task:cryptomgr_test  state:D stack:0     pid:4889  tgid:4889  ppid:2      flags:0x00004000
    [  369.986253] Call Trace:
    [  369.986256]  <TASK>
    [  369.986260]  __schedule+0x45c/0xfa0
    [  369.986273]  schedule+0x2e/0xb0
    [  369.986277]  schedule_timeout+0xe7/0x100
    [  369.986284]  ? __prepare_to_swait+0x4e/0x70
    [  369.986290]  wait_for_completion+0x8d/0x120
    [  369.986293]  test_acomp+0x284/0x670
    [  369.986305]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986312]  alg_test_comp+0x263/0x440
    [  369.986315]  ? sched_balance_newidle+0x259/0x430
    [  369.986320]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986323]  alg_test.part.27+0x103/0x410
    [  369.986326]  ? __schedule+0x464/0xfa0
    [  369.986330]  ? __pfx_cryptomgr_test+0x10/0x10
    [  369.986333]  cryptomgr_test+0x20/0x40
    [  369.986336]  kthread+0xda/0x110
    [  369.986344]  ? __pfx_kthread+0x10/0x10
    [  369.986346]  ret_from_fork+0x2d/0x40
    [  369.986355]  ? __pfx_kthread+0x10/0x10
    [  369.986358]  ret_from_fork_asm+0x1a/0x30
    [  369.986365]  </TASK>

    This happens because the only async polling without interrupts that
    iaa_crypto currently implements is with the 'sync' mode. With 'async',
    iaa_crypto calls to compress/decompress submit the descriptor and return
    -EINPROGRESS, without any mechanism in the driver to poll for
    completions. Hence callers such as test_acomp() in crypto/testmgr.c or
    zswap, that wrap the calls to crypto_acomp_compress() and
    crypto_acomp_decompress() in synchronous wrappers, will block
    indefinitely. Even before zswap can notice this problem, the crypto
    testmgr.c's test_acomp() will fail and prevent registration of
    "deflate-iaa" as a valid crypto acomp algorithm, thereby disallowing the
    use of "deflate-iaa" as a zswap compress (zswap will fall-back to the
    default compressor in this case).

    To fix this issue, this patch modifies the iaa_crypto sync_mode set
    function to treat 'async' equivalent to 'sync', so that the correct and
    only supported driver async polling without interrupts implementation is
    enabled, and zswap can use 'deflate-iaa' as the compressor.

    Hence, with this patch, this is what will happen:

    echo async > /sys/bus/dsa/drivers/crypto/sync_mode
    cat /sys/bus/dsa/drivers/crypto/sync_mode
    sync

    There are no crypto/testmgr.c test_acomp() errors, no call traces and zswap
    can use 'deflate-iaa' without any errors. The iaa_crypto documentation has
    also been updated to mention this caveat with 'async' and what to expect
    with this fix.

    True iaa_crypto async polling without interrupts is enabled in patch
    "crypto: iaa - Implement batch_compress(), batch_decompress() API in
    iaa_crypto." [1] which is under review as part of the "zswap IAA compress
    batching" patch-series [2]. Until this is merged, we would appreciate it if
    this current patch can be considered for a hotfix.

    [1]: https://patchwork.kernel.org/project/linux-mm/patch/20241221063119.29140-5-kanchana.p.sridhar@intel.com/
    [2]: https://patchwork.kernel.org/project/linux-mm/list/?series=920084

    Fixes: 09646c9 ("crypto: iaa - Add irq support for the crypto async interface")
    Signed-off-by: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants