]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
6.6-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Feb 2025 07:04:58 +0000 (08:04 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Feb 2025 07:04:58 +0000 (08:04 +0100)
added patches:
revert-vfio-platform-check-the-bounds-of-read-write-syscalls.patch
vsock-keep-the-binding-until-socket-destruction.patch
vsock-orphan-socket-after-transport-release.patch
x86-i8253-disable-pit-timer-0-when-not-in-use.patch

queue-6.6/revert-vfio-platform-check-the-bounds-of-read-write-syscalls.patch [new file with mode: 0644]
queue-6.6/series
queue-6.6/vsock-keep-the-binding-until-socket-destruction.patch [new file with mode: 0644]
queue-6.6/vsock-orphan-socket-after-transport-release.patch [new file with mode: 0644]
queue-6.6/x86-i8253-disable-pit-timer-0-when-not-in-use.patch [new file with mode: 0644]

diff --git a/queue-6.6/revert-vfio-platform-check-the-bounds-of-read-write-syscalls.patch b/queue-6.6/revert-vfio-platform-check-the-bounds-of-read-write-syscalls.patch
new file mode 100644 (file)
index 0000000..170c277
--- /dev/null
@@ -0,0 +1,45 @@
+From c59171a0f6e59a39aa2c6ccea532632353e585ce Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Wed, 19 Feb 2025 08:01:16 +0100
+Subject: Revert "vfio/platform: check the bounds of read/write syscalls"
+
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+This reverts commit 03844b1908114680ca35fa0a0aba3d906a6d78af.
+
+It had been committed multiple times to the tree, and isn't needed
+again.
+
+Link: https://lore.kernel.org/r/a082db2605514513a0a8568382d5bd2b6f1877a0.camel@cyberus-technology.de
+Reported-by: Stefan Nürnberger <stefan.nuernberger@cyberus-technology.de>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/vfio/platform/vfio_platform_common.c |   10 ----------
+ 1 file changed, 10 deletions(-)
+
+--- a/drivers/vfio/platform/vfio_platform_common.c
++++ b/drivers/vfio/platform/vfio_platform_common.c
+@@ -393,11 +393,6 @@ static ssize_t vfio_platform_read_mmio(s
+       count = min_t(size_t, count, reg->size - off);
+-      if (off >= reg->size)
+-              return -EINVAL;
+-
+-      count = min_t(size_t, count, reg->size - off);
+-
+       if (!reg->ioaddr) {
+               reg->ioaddr =
+                       ioremap(reg->addr, reg->size);
+@@ -479,11 +474,6 @@ static ssize_t vfio_platform_write_mmio(
+       if (off >= reg->size)
+               return -EINVAL;
+-
+-      count = min_t(size_t, count, reg->size - off);
+-
+-      if (off >= reg->size)
+-              return -EINVAL;
+       count = min_t(size_t, count, reg->size - off);
index 8cff11b7a5b41f2b95016c0497d5e197ac7ffbd5..79325ba6010fa79949f1d3a04b3e215cd11dc2f9 100644 (file)
@@ -146,3 +146,7 @@ mm-gup-fix-infinite-loop-within-__get_longterm_locked.patch
 alpha-replace-hardcoded-stack-offsets-with-autogenerated-ones.patch
 hid-hid-steam-don-t-use-cancel_delayed_work_sync-in-irq-context.patch
 io_uring-kbuf-reallocate-buf-lists-on-upgrade.patch
+vsock-keep-the-binding-until-socket-destruction.patch
+vsock-orphan-socket-after-transport-release.patch
+x86-i8253-disable-pit-timer-0-when-not-in-use.patch
+revert-vfio-platform-check-the-bounds-of-read-write-syscalls.patch
diff --git a/queue-6.6/vsock-keep-the-binding-until-socket-destruction.patch b/queue-6.6/vsock-keep-the-binding-until-socket-destruction.patch
new file mode 100644 (file)
index 0000000..7e7a1a9
--- /dev/null
@@ -0,0 +1,131 @@
+From fcdd2242c0231032fc84e1404315c245ae56322a Mon Sep 17 00:00:00 2001
+From: Michal Luczaj <mhal@rbox.co>
+Date: Tue, 28 Jan 2025 14:15:27 +0100
+Subject: vsock: Keep the binding until socket destruction
+
+From: Michal Luczaj <mhal@rbox.co>
+
+commit fcdd2242c0231032fc84e1404315c245ae56322a upstream.
+
+Preserve sockets bindings; this includes both resulting from an explicit
+bind() and those implicitly bound through autobind during connect().
+
+Prevents socket unbinding during a transport reassignment, which fixes a
+use-after-free:
+
+    1. vsock_create() (refcnt=1) calls vsock_insert_unbound() (refcnt=2)
+    2. transport->release() calls vsock_remove_bound() without checking if
+       sk was bound and moved to bound list (refcnt=1)
+    3. vsock_bind() assumes sk is in unbound list and before
+       __vsock_insert_bound(vsock_bound_sockets()) calls
+       __vsock_remove_bound() which does:
+           list_del_init(&vsk->bound_table); // nop
+           sock_put(&vsk->sk);               // refcnt=0
+
+BUG: KASAN: slab-use-after-free in __vsock_bind+0x62e/0x730
+Read of size 4 at addr ffff88816b46a74c by task a.out/2057
+ dump_stack_lvl+0x68/0x90
+ print_report+0x174/0x4f6
+ kasan_report+0xb9/0x190
+ __vsock_bind+0x62e/0x730
+ vsock_bind+0x97/0xe0
+ __sys_bind+0x154/0x1f0
+ __x64_sys_bind+0x6e/0xb0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+Allocated by task 2057:
+ kasan_save_stack+0x1e/0x40
+ kasan_save_track+0x10/0x30
+ __kasan_slab_alloc+0x85/0x90
+ kmem_cache_alloc_noprof+0x131/0x450
+ sk_prot_alloc+0x5b/0x220
+ sk_alloc+0x2c/0x870
+ __vsock_create.constprop.0+0x2e/0xb60
+ vsock_create+0xe4/0x420
+ __sock_create+0x241/0x650
+ __sys_socket+0xf2/0x1a0
+ __x64_sys_socket+0x6e/0xb0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+Freed by task 2057:
+ kasan_save_stack+0x1e/0x40
+ kasan_save_track+0x10/0x30
+ kasan_save_free_info+0x37/0x60
+ __kasan_slab_free+0x4b/0x70
+ kmem_cache_free+0x1a1/0x590
+ __sk_destruct+0x388/0x5a0
+ __vsock_bind+0x5e1/0x730
+ vsock_bind+0x97/0xe0
+ __sys_bind+0x154/0x1f0
+ __x64_sys_bind+0x6e/0xb0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+refcount_t: addition on 0; use-after-free.
+WARNING: CPU: 7 PID: 2057 at lib/refcount.c:25 refcount_warn_saturate+0xce/0x150
+RIP: 0010:refcount_warn_saturate+0xce/0x150
+ __vsock_bind+0x66d/0x730
+ vsock_bind+0x97/0xe0
+ __sys_bind+0x154/0x1f0
+ __x64_sys_bind+0x6e/0xb0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+refcount_t: underflow; use-after-free.
+WARNING: CPU: 7 PID: 2057 at lib/refcount.c:28 refcount_warn_saturate+0xee/0x150
+RIP: 0010:refcount_warn_saturate+0xee/0x150
+ vsock_remove_bound+0x187/0x1e0
+ __vsock_release+0x383/0x4a0
+ vsock_release+0x90/0x120
+ __sock_release+0xa3/0x250
+ sock_close+0x14/0x20
+ __fput+0x359/0xa80
+ task_work_run+0x107/0x1d0
+ do_exit+0x847/0x2560
+ do_group_exit+0xb8/0x250
+ __x64_sys_exit_group+0x3a/0x50
+ x64_sys_call+0xfec/0x14f0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
+Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
+Signed-off-by: Michal Luczaj <mhal@rbox.co>
+Link: https://patch.msgid.link/20250128-vsock-transport-vs-autobind-v3-1-1cf57065b770@rbox.co
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/vmw_vsock/af_vsock.c |    8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+--- a/net/vmw_vsock/af_vsock.c
++++ b/net/vmw_vsock/af_vsock.c
+@@ -336,7 +336,10 @@ EXPORT_SYMBOL_GPL(vsock_find_connected_s
+ void vsock_remove_sock(struct vsock_sock *vsk)
+ {
+-      vsock_remove_bound(vsk);
++      /* Transport reassignment must not remove the binding. */
++      if (sock_flag(sk_vsock(vsk), SOCK_DEAD))
++              vsock_remove_bound(vsk);
++
+       vsock_remove_connected(vsk);
+ }
+ EXPORT_SYMBOL_GPL(vsock_remove_sock);
+@@ -820,12 +823,13 @@ static void __vsock_release(struct sock
+        */
+       lock_sock_nested(sk, level);
++      sock_orphan(sk);
++
+       if (vsk->transport)
+               vsk->transport->release(vsk);
+       else if (sock_type_connectible(sk->sk_type))
+               vsock_remove_sock(vsk);
+-      sock_orphan(sk);
+       sk->sk_shutdown = SHUTDOWN_MASK;
+       skb_queue_purge(&sk->sk_receive_queue);
diff --git a/queue-6.6/vsock-orphan-socket-after-transport-release.patch b/queue-6.6/vsock-orphan-socket-after-transport-release.patch
new file mode 100644 (file)
index 0000000..495d9cd
--- /dev/null
@@ -0,0 +1,67 @@
+From 78dafe1cf3afa02ed71084b350713b07e72a18fb Mon Sep 17 00:00:00 2001
+From: Michal Luczaj <mhal@rbox.co>
+Date: Mon, 10 Feb 2025 13:15:00 +0100
+Subject: vsock: Orphan socket after transport release
+
+From: Michal Luczaj <mhal@rbox.co>
+
+commit 78dafe1cf3afa02ed71084b350713b07e72a18fb upstream.
+
+During socket release, sock_orphan() is called without considering that it
+sets sk->sk_wq to NULL. Later, if SO_LINGER is enabled, this leads to a
+null pointer dereferenced in virtio_transport_wait_close().
+
+Orphan the socket only after transport release.
+
+Partially reverts the 'Fixes:' commit.
+
+KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
+ lock_acquire+0x19e/0x500
+ _raw_spin_lock_irqsave+0x47/0x70
+ add_wait_queue+0x46/0x230
+ virtio_transport_release+0x4e7/0x7f0
+ __vsock_release+0xfd/0x490
+ vsock_release+0x90/0x120
+ __sock_release+0xa3/0x250
+ sock_close+0x14/0x20
+ __fput+0x35e/0xa90
+ __x64_sys_close+0x78/0xd0
+ do_syscall_64+0x93/0x1b0
+ entry_SYSCALL_64_after_hwframe+0x76/0x7e
+
+Reported-by: syzbot+9d55b199192a4be7d02c@syzkaller.appspotmail.com
+Closes: https://syzkaller.appspot.com/bug?extid=9d55b199192a4be7d02c
+Fixes: fcdd2242c023 ("vsock: Keep the binding until socket destruction")
+Tested-by: Luigi Leonardi <leonardi@redhat.com>
+Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
+Signed-off-by: Michal Luczaj <mhal@rbox.co>
+Link: https://patch.msgid.link/20250210-vsock-linger-nullderef-v3-1-ef6244d02b54@rbox.co
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/vmw_vsock/af_vsock.c |    8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+--- a/net/vmw_vsock/af_vsock.c
++++ b/net/vmw_vsock/af_vsock.c
+@@ -823,13 +823,19 @@ static void __vsock_release(struct sock
+        */
+       lock_sock_nested(sk, level);
+-      sock_orphan(sk);
++      /* Indicate to vsock_remove_sock() that the socket is being released and
++       * can be removed from the bound_table. Unlike transport reassignment
++       * case, where the socket must remain bound despite vsock_remove_sock()
++       * being called from the transport release() callback.
++       */
++      sock_set_flag(sk, SOCK_DEAD);
+       if (vsk->transport)
+               vsk->transport->release(vsk);
+       else if (sock_type_connectible(sk->sk_type))
+               vsock_remove_sock(vsk);
++      sock_orphan(sk);
+       sk->sk_shutdown = SHUTDOWN_MASK;
+       skb_queue_purge(&sk->sk_receive_queue);
diff --git a/queue-6.6/x86-i8253-disable-pit-timer-0-when-not-in-use.patch b/queue-6.6/x86-i8253-disable-pit-timer-0-when-not-in-use.patch
new file mode 100644 (file)
index 0000000..61180b1
--- /dev/null
@@ -0,0 +1,96 @@
+From 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60 Mon Sep 17 00:00:00 2001
+From: David Woodhouse <dwmw@amazon.co.uk>
+Date: Fri, 2 Aug 2024 14:55:54 +0100
+Subject: x86/i8253: Disable PIT timer 0 when not in use
+
+From: David Woodhouse <dwmw@amazon.co.uk>
+
+commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60 upstream.
+
+Leaving the PIT interrupt running can cause noticeable steal time for
+virtual guests. The VMM generally has a timer which toggles the IRQ input
+to the PIC and I/O APIC, which takes CPU time away from the guest. Even
+on real hardware, running the counter may use power needlessly (albeit
+not much).
+
+Make sure it's turned off if it isn't going to be used.
+
+Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
+Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
+Tested-by: Michael Kelley <mhkelley@outlook.com>
+Link: https://lore.kernel.org/all/20240802135555.564941-1-dwmw2@infradead.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/x86/kernel/i8253.c     |   11 +++++++++--
+ drivers/clocksource/i8253.c |   13 +++++++++----
+ include/linux/i8253.h       |    1 +
+ 3 files changed, 19 insertions(+), 6 deletions(-)
+
+--- a/arch/x86/kernel/i8253.c
++++ b/arch/x86/kernel/i8253.c
+@@ -8,6 +8,7 @@
+ #include <linux/timex.h>
+ #include <linux/i8253.h>
++#include <asm/hypervisor.h>
+ #include <asm/apic.h>
+ #include <asm/hpet.h>
+ #include <asm/time.h>
+@@ -39,9 +40,15 @@ static bool __init use_pit(void)
+ bool __init pit_timer_init(void)
+ {
+-      if (!use_pit())
++      if (!use_pit()) {
++              /*
++               * Don't just ignore the PIT. Ensure it's stopped, because
++               * VMMs otherwise steal CPU time just to pointlessly waggle
++               * the (masked) IRQ.
++               */
++              clockevent_i8253_disable();
+               return false;
+-
++      }
+       clockevent_i8253_init(true);
+       global_clock_event = &i8253_clockevent;
+       return true;
+--- a/drivers/clocksource/i8253.c
++++ b/drivers/clocksource/i8253.c
+@@ -108,11 +108,8 @@ int __init clocksource_i8253_init(void)
+ #endif
+ #ifdef CONFIG_CLKEVT_I8253
+-static int pit_shutdown(struct clock_event_device *evt)
++void clockevent_i8253_disable(void)
+ {
+-      if (!clockevent_state_oneshot(evt) && !clockevent_state_periodic(evt))
+-              return 0;
+-
+       raw_spin_lock(&i8253_lock);
+       outb_p(0x30, PIT_MODE);
+@@ -123,6 +120,14 @@ static int pit_shutdown(struct clock_eve
+       }
+       raw_spin_unlock(&i8253_lock);
++}
++
++static int pit_shutdown(struct clock_event_device *evt)
++{
++      if (!clockevent_state_oneshot(evt) && !clockevent_state_periodic(evt))
++              return 0;
++
++      clockevent_i8253_disable();
+       return 0;
+ }
+--- a/include/linux/i8253.h
++++ b/include/linux/i8253.h
+@@ -24,6 +24,7 @@ extern raw_spinlock_t i8253_lock;
+ extern bool i8253_clear_counter_on_shutdown;
+ extern struct clock_event_device i8253_clockevent;
+ extern void clockevent_i8253_init(bool oneshot);
++extern void clockevent_i8253_disable(void);
+ extern void setup_pit_timer(void);