From 6e792b1825beeab77bbdd9ee7942ebf49e2919e9 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 18 Jun 2024 16:01:18 +0200 Subject: [PATCH] 6.6-stable patches added patches: clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch dma-buf-handle-testing-kthreads-creation-failure.patch irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch kheaders-explicitly-define-file-modes-for-archived-headers.patch null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch perf-auxtrace-fix-multiple-use-of-itrace-option.patch perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch riscv-fix-overlap-of-allocated-page-and-ptr_err.patch sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch spmi-hisi-spmi-controller-do-not-override-device-identifier.patch tracing-add-module_description-to-preemptirq_delay_test.patch tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch x86-amd_nb-check-for-invalid-smn-reads.patch x86-kexec-fix-bug-with-call-depth-tracking.patch --- ...v-id-usage-to-allow-for-longer-names.patch | 49 ++++++ ...le-testing-kthreads-creation-failure.patch | 44 ++++++ ...ce-condition-in-its_vlpi_prop_update.patch | 141 ++++++++++++++++++ ...fine-file-modes-for-archived-headers.patch | 37 +++++ ...n-zones-limit-in-null_init_zoned_dev.patch | 34 +++++ ...ce-fix-multiple-use-of-itrace-option.patch | 66 ++++++++ ...p-when-waiting-for-context-reference.patch | 106 +++++++++++++ ...verlap-of-allocated-page-and-ptr_err.patch | 69 +++++++++ queue-6.6/series | 15 ++ ...ween-sock_map_close-and-sk_psock_put.patch | 115 ++++++++++++++ ...er-do-not-override-device-identifier.patch | 36 +++++ ...description-to-preemptirq_delay_test.patch | 34 +++++ ...event-name-test-for-.isra.-functions.patch | 50 +++++++ ...by-sanitizing-event-in-event_deliver.patch | 56 +++++++ ...6-amd_nb-check-for-invalid-smn-reads.patch | 59 ++++++++ ...xec-fix-bug-with-call-depth-tracking.patch | 56 +++++++ 16 files changed, 967 insertions(+) create mode 100644 queue-6.6/clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch create mode 100644 queue-6.6/dma-buf-handle-testing-kthreads-creation-failure.patch create mode 100644 queue-6.6/irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch create mode 100644 queue-6.6/kheaders-explicitly-define-file-modes-for-archived-headers.patch create mode 100644 queue-6.6/null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch create mode 100644 queue-6.6/perf-auxtrace-fix-multiple-use-of-itrace-option.patch create mode 100644 queue-6.6/perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch create mode 100644 queue-6.6/riscv-fix-overlap-of-allocated-page-and-ptr_err.patch create mode 100644 queue-6.6/sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch create mode 100644 queue-6.6/spmi-hisi-spmi-controller-do-not-override-device-identifier.patch create mode 100644 queue-6.6/tracing-add-module_description-to-preemptirq_delay_test.patch create mode 100644 queue-6.6/tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch create mode 100644 queue-6.6/vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch create mode 100644 queue-6.6/x86-amd_nb-check-for-invalid-smn-reads.patch create mode 100644 queue-6.6/x86-kexec-fix-bug-with-call-depth-tracking.patch diff --git a/queue-6.6/clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch b/queue-6.6/clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch new file mode 100644 index 00000000000..281ea32dec5 --- /dev/null +++ b/queue-6.6/clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch @@ -0,0 +1,49 @@ +From 99f4570cfba1e60daafde737cb7e395006d719e6 Mon Sep 17 00:00:00 2001 +From: "Michael J. Ruhl" +Date: Fri, 23 Feb 2024 15:25:56 -0500 +Subject: clkdev: Update clkdev id usage to allow for longer names + +From: Michael J. Ruhl + +commit 99f4570cfba1e60daafde737cb7e395006d719e6 upstream. + +clkdev DEV ID information is limited to an array of 20 bytes +(MAX_DEV_ID). It is possible that the ID could be longer than +that. If so, the lookup will fail because the "real ID" will +not match the copied value. + +For instance, generating a device name for the I2C Designware +module using the PCI ID can result in a name of: + +i2c_designware.39424 + +clkdev_create() will store: + +i2c_designware.3942 + +The stored name is one off and will not match correctly during probe. + +Increase the size of the ID to allow for a longer name. + +Reviewed-by: Russell King (Oracle) +Signed-off-by: Michael J. Ruhl +Link: https://lore.kernel.org/r/20240223202556.2194021-1-michael.j.ruhl@intel.com +Reviewed-by: Andy Shevchenko +Signed-off-by: Stephen Boyd +Cc: Guenter Roeck +Signed-off-by: Greg Kroah-Hartman +--- + drivers/clk/clkdev.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/clk/clkdev.c ++++ b/drivers/clk/clkdev.c +@@ -144,7 +144,7 @@ void clkdev_add_table(struct clk_lookup + mutex_unlock(&clocks_mutex); + } + +-#define MAX_DEV_ID 20 ++#define MAX_DEV_ID 24 + #define MAX_CON_ID 16 + + struct clk_lookup_alloc { diff --git a/queue-6.6/dma-buf-handle-testing-kthreads-creation-failure.patch b/queue-6.6/dma-buf-handle-testing-kthreads-creation-failure.patch new file mode 100644 index 00000000000..f6129214d6f --- /dev/null +++ b/queue-6.6/dma-buf-handle-testing-kthreads-creation-failure.patch @@ -0,0 +1,44 @@ +From 6cb05d89fd62a76a9b74bd16211fb0930e89fea8 Mon Sep 17 00:00:00 2001 +From: Fedor Pchelkin +Date: Wed, 22 May 2024 21:13:08 +0300 +Subject: dma-buf: handle testing kthreads creation failure +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Fedor Pchelkin + +commit 6cb05d89fd62a76a9b74bd16211fb0930e89fea8 upstream. + +kthread creation may possibly fail inside race_signal_callback(). In +such a case stop the already started threads, put the already taken +references to them and return with error code. + +Found by Linux Verification Center (linuxtesting.org). + +Fixes: 2989f6451084 ("dma-buf: Add selftests for dma-fence") +Cc: stable@vger.kernel.org +Signed-off-by: Fedor Pchelkin +Reviewed-by: T.J. Mercier +Link: https://patchwork.freedesktop.org/patch/msgid/20240522181308.841686-1-pchelkin@ispras.ru +Signed-off-by: Christian König +Signed-off-by: Greg Kroah-Hartman +--- + drivers/dma-buf/st-dma-fence.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/drivers/dma-buf/st-dma-fence.c ++++ b/drivers/dma-buf/st-dma-fence.c +@@ -540,6 +540,12 @@ static int race_signal_callback(void *ar + t[i].before = pass; + t[i].task = kthread_run(thread_signal_callback, &t[i], + "dma-fence:%d", i); ++ if (IS_ERR(t[i].task)) { ++ ret = PTR_ERR(t[i].task); ++ while (--i >= 0) ++ kthread_stop_put(t[i].task); ++ return ret; ++ } + get_task_struct(t[i].task); + } + diff --git a/queue-6.6/irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch b/queue-6.6/irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch new file mode 100644 index 00000000000..93ebef53f14 --- /dev/null +++ b/queue-6.6/irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch @@ -0,0 +1,141 @@ +From b97e8a2f7130a4b30d1502003095833d16c028b3 Mon Sep 17 00:00:00 2001 +From: Hagar Hemdan +Date: Fri, 31 May 2024 16:21:44 +0000 +Subject: irqchip/gic-v3-its: Fix potential race condition in its_vlpi_prop_update() + +From: Hagar Hemdan + +commit b97e8a2f7130a4b30d1502003095833d16c028b3 upstream. + +its_vlpi_prop_update() calls lpi_write_config() which obtains the +mapping information for a VLPI without lock held. So it could race +with its_vlpi_unmap(). + +Since all calls from its_irq_set_vcpu_affinity() require the same +lock to be held, hoist the locking there instead of sprinkling the +locking all over the place. + +This bug was discovered using Coverity Static Analysis Security Testing +(SAST) by Synopsys, Inc. + +[ tglx: Use guard() instead of goto ] + +Fixes: 015ec0386ab6 ("irqchip/gic-v3-its: Add VLPI configuration handling") +Suggested-by: Marc Zyngier +Signed-off-by: Hagar Hemdan +Signed-off-by: Thomas Gleixner +Cc: stable@vger.kernel.org +Reviewed-by: Marc Zyngier +Link: https://lore.kernel.org/r/20240531162144.28650-1-hagarhem@amazon.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/irqchip/irq-gic-v3-its.c | 44 ++++++++++----------------------------- + 1 file changed, 12 insertions(+), 32 deletions(-) + +--- a/drivers/irqchip/irq-gic-v3-its.c ++++ b/drivers/irqchip/irq-gic-v3-its.c +@@ -1840,28 +1840,22 @@ static int its_vlpi_map(struct irq_data + { + struct its_device *its_dev = irq_data_get_irq_chip_data(d); + u32 event = its_get_event_id(d); +- int ret = 0; + + if (!info->map) + return -EINVAL; + +- raw_spin_lock(&its_dev->event_map.vlpi_lock); +- + if (!its_dev->event_map.vm) { + struct its_vlpi_map *maps; + + maps = kcalloc(its_dev->event_map.nr_lpis, sizeof(*maps), + GFP_ATOMIC); +- if (!maps) { +- ret = -ENOMEM; +- goto out; +- } ++ if (!maps) ++ return -ENOMEM; + + its_dev->event_map.vm = info->map->vm; + its_dev->event_map.vlpi_maps = maps; + } else if (its_dev->event_map.vm != info->map->vm) { +- ret = -EINVAL; +- goto out; ++ return -EINVAL; + } + + /* Get our private copy of the mapping information */ +@@ -1893,46 +1887,32 @@ static int its_vlpi_map(struct irq_data + its_dev->event_map.nr_vlpis++; + } + +-out: +- raw_spin_unlock(&its_dev->event_map.vlpi_lock); +- return ret; ++ return 0; + } + + static int its_vlpi_get(struct irq_data *d, struct its_cmd_info *info) + { + struct its_device *its_dev = irq_data_get_irq_chip_data(d); + struct its_vlpi_map *map; +- int ret = 0; +- +- raw_spin_lock(&its_dev->event_map.vlpi_lock); + + map = get_vlpi_map(d); + +- if (!its_dev->event_map.vm || !map) { +- ret = -EINVAL; +- goto out; +- } ++ if (!its_dev->event_map.vm || !map) ++ return -EINVAL; + + /* Copy our mapping information to the incoming request */ + *info->map = *map; + +-out: +- raw_spin_unlock(&its_dev->event_map.vlpi_lock); +- return ret; ++ return 0; + } + + static int its_vlpi_unmap(struct irq_data *d) + { + struct its_device *its_dev = irq_data_get_irq_chip_data(d); + u32 event = its_get_event_id(d); +- int ret = 0; + +- raw_spin_lock(&its_dev->event_map.vlpi_lock); +- +- if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) { +- ret = -EINVAL; +- goto out; +- } ++ if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) ++ return -EINVAL; + + /* Drop the virtual mapping */ + its_send_discard(its_dev, event); +@@ -1956,9 +1936,7 @@ static int its_vlpi_unmap(struct irq_dat + kfree(its_dev->event_map.vlpi_maps); + } + +-out: +- raw_spin_unlock(&its_dev->event_map.vlpi_lock); +- return ret; ++ return 0; + } + + static int its_vlpi_prop_update(struct irq_data *d, struct its_cmd_info *info) +@@ -1986,6 +1964,8 @@ static int its_irq_set_vcpu_affinity(str + if (!is_v4(its_dev->its)) + return -EINVAL; + ++ guard(raw_spinlock_irq)(&its_dev->event_map.vlpi_lock); ++ + /* Unmap request? */ + if (!info) + return its_vlpi_unmap(d); diff --git a/queue-6.6/kheaders-explicitly-define-file-modes-for-archived-headers.patch b/queue-6.6/kheaders-explicitly-define-file-modes-for-archived-headers.patch new file mode 100644 index 00000000000..6c22c09173c --- /dev/null +++ b/queue-6.6/kheaders-explicitly-define-file-modes-for-archived-headers.patch @@ -0,0 +1,37 @@ +From 3bd27a847a3a4827a948387cc8f0dbc9fa5931d5 Mon Sep 17 00:00:00 2001 +From: Matthias Maennich +Date: Tue, 28 May 2024 11:32:43 +0000 +Subject: kheaders: explicitly define file modes for archived headers + +From: Matthias Maennich + +commit 3bd27a847a3a4827a948387cc8f0dbc9fa5931d5 upstream. + +Build environments might be running with different umask settings +resulting in indeterministic file modes for the files contained in +kheaders.tar.xz. The file itself is served with 444, i.e. world +readable. Archive the files explicitly with 744,a+X to improve +reproducibility across build environments. + +--mode=0444 is not suitable as directories need to be executable. Also, +444 makes it hard to delete all the readonly files after extraction. + +Cc: stable@vger.kernel.org +Signed-off-by: Matthias Maennich +Signed-off-by: Masahiro Yamada +Signed-off-by: Greg Kroah-Hartman +--- + kernel/gen_kheaders.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/kernel/gen_kheaders.sh ++++ b/kernel/gen_kheaders.sh +@@ -89,7 +89,7 @@ find $cpio_dir -type f -print0 | + + # Create archive and try to normalize metadata for reproducibility. + tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \ +- --owner=0 --group=0 --sort=name --numeric-owner \ ++ --owner=0 --group=0 --sort=name --numeric-owner --mode=u=rw,go=r,a+X \ + -I $XZ -cf $tarfile -C $cpio_dir/ . > /dev/null + + echo $headers_md5 > kernel/kheaders.md5 diff --git a/queue-6.6/null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch b/queue-6.6/null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch new file mode 100644 index 00000000000..96e48197946 --- /dev/null +++ b/queue-6.6/null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch @@ -0,0 +1,34 @@ +From 233e27b4d21c3e44eb863f03e566d3a22e81a7ae Mon Sep 17 00:00:00 2001 +From: Damien Le Moal +Date: Tue, 28 May 2024 15:28:52 +0900 +Subject: null_blk: Print correct max open zones limit in null_init_zoned_dev() + +From: Damien Le Moal + +commit 233e27b4d21c3e44eb863f03e566d3a22e81a7ae upstream. + +When changing the maximum number of open zones, print that number +instead of the total number of zones. + +Fixes: dc4d137ee3b7 ("null_blk: add support for max open/active zone limit for zoned devices") +Cc: stable@vger.kernel.org +Signed-off-by: Damien Le Moal +Reviewed-by: Niklas Cassel +Link: https://lore.kernel.org/r/20240528062852.437599-1-dlemoal@kernel.org +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + drivers/block/null_blk/zoned.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/block/null_blk/zoned.c ++++ b/drivers/block/null_blk/zoned.c +@@ -112,7 +112,7 @@ int null_init_zoned_dev(struct nullb_dev + if (dev->zone_max_active && dev->zone_max_open > dev->zone_max_active) { + dev->zone_max_open = dev->zone_max_active; + pr_info("changed the maximum number of open zones to %u\n", +- dev->nr_zones); ++ dev->zone_max_open); + } else if (dev->zone_max_open >= dev->nr_zones - dev->zone_nr_conv) { + dev->zone_max_open = 0; + pr_info("zone_max_open limit disabled, limit >= zone count\n"); diff --git a/queue-6.6/perf-auxtrace-fix-multiple-use-of-itrace-option.patch b/queue-6.6/perf-auxtrace-fix-multiple-use-of-itrace-option.patch new file mode 100644 index 00000000000..840c40fd157 --- /dev/null +++ b/queue-6.6/perf-auxtrace-fix-multiple-use-of-itrace-option.patch @@ -0,0 +1,66 @@ +From bb69c912c4e8005cf1ee6c63782d2fc28838dee2 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 15 Mar 2024 09:13:34 +0200 +Subject: perf auxtrace: Fix multiple use of --itrace option + +From: Adrian Hunter + +commit bb69c912c4e8005cf1ee6c63782d2fc28838dee2 upstream. + +If the --itrace option is used more than once, the options are +combined, but "i" and "y" (sub-)options can be corrupted because +itrace_do_parse_synth_opts() incorrectly overwrites the period type and +period with default values. + +For example, with: + + --itrace=i0ns --itrace=e + +The processing of "--itrace=e", resets the "i" period from 0 nanoseconds +to the default 100 microseconds. + +Fix by performing the default setting of period type and period only if +"i" or "y" are present in the currently processed --itrace value. + +Fixes: f6986c95af84ff2a ("perf session: Add instruction tracing options") +Signed-off-by: Adrian Hunter +Cc: Adrian Hunter +Cc: Andi Kleen +Cc: Ian Rogers +Cc: Jiri Olsa +Cc: Namhyung Kim +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20240315071334.3478-2-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman +--- + tools/perf/util/auxtrace.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +--- a/tools/perf/util/auxtrace.c ++++ b/tools/perf/util/auxtrace.c +@@ -1466,6 +1466,7 @@ int itrace_do_parse_synth_opts(struct it + char *endptr; + bool period_type_set = false; + bool period_set = false; ++ bool iy = false; + + synth_opts->set = true; + +@@ -1484,6 +1485,7 @@ int itrace_do_parse_synth_opts(struct it + switch (*p++) { + case 'i': + case 'y': ++ iy = true; + if (p[-1] == 'y') + synth_opts->cycles = true; + else +@@ -1646,7 +1648,7 @@ int itrace_do_parse_synth_opts(struct it + } + } + out: +- if (synth_opts->instructions || synth_opts->cycles) { ++ if (iy) { + if (!period_type_set) + synth_opts->period_type = + PERF_ITRACE_DEFAULT_PERIOD_TYPE; diff --git a/queue-6.6/perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch b/queue-6.6/perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch new file mode 100644 index 00000000000..3281328ce64 --- /dev/null +++ b/queue-6.6/perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch @@ -0,0 +1,106 @@ +From 74751ef5c1912ebd3e65c3b65f45587e05ce5d36 Mon Sep 17 00:00:00 2001 +From: Haifeng Xu +Date: Mon, 13 May 2024 10:39:48 +0000 +Subject: perf/core: Fix missing wakeup when waiting for context reference + +From: Haifeng Xu + +commit 74751ef5c1912ebd3e65c3b65f45587e05ce5d36 upstream. + +In our production environment, we found many hung tasks which are +blocked for more than 18 hours. Their call traces are like this: + +[346278.191038] __schedule+0x2d8/0x890 +[346278.191046] schedule+0x4e/0xb0 +[346278.191049] perf_event_free_task+0x220/0x270 +[346278.191056] ? init_wait_var_entry+0x50/0x50 +[346278.191060] copy_process+0x663/0x18d0 +[346278.191068] kernel_clone+0x9d/0x3d0 +[346278.191072] __do_sys_clone+0x5d/0x80 +[346278.191076] __x64_sys_clone+0x25/0x30 +[346278.191079] do_syscall_64+0x5c/0xc0 +[346278.191083] ? syscall_exit_to_user_mode+0x27/0x50 +[346278.191086] ? do_syscall_64+0x69/0xc0 +[346278.191088] ? irqentry_exit_to_user_mode+0x9/0x20 +[346278.191092] ? irqentry_exit+0x19/0x30 +[346278.191095] ? exc_page_fault+0x89/0x160 +[346278.191097] ? asm_exc_page_fault+0x8/0x30 +[346278.191102] entry_SYSCALL_64_after_hwframe+0x44/0xae + +The task was waiting for the refcount become to 1, but from the vmcore, +we found the refcount has already been 1. It seems that the task didn't +get woken up by perf_event_release_kernel() and got stuck forever. The +below scenario may cause the problem. + +Thread A Thread B +... ... +perf_event_free_task perf_event_release_kernel + ... + acquire event->child_mutex + ... + get_ctx + ... release event->child_mutex + acquire ctx->mutex + ... + perf_free_event (acquire/release event->child_mutex) + ... + release ctx->mutex + wait_var_event + acquire ctx->mutex + acquire event->child_mutex + # move existing events to free_list + release event->child_mutex + release ctx->mutex + put_ctx +... ... + +In this case, all events of the ctx have been freed, so we couldn't +find the ctx in free_list and Thread A will miss the wakeup. It's thus +necessary to add a wakeup after dropping the reference. + +Fixes: 1cf8dfe8a661 ("perf/core: Fix race between close() and fork()") +Signed-off-by: Haifeng Xu +Signed-off-by: Peter Zijlstra (Intel) +Reviewed-by: Frederic Weisbecker +Acked-by: Mark Rutland +Cc: stable@vger.kernel.org +Link: https://lkml.kernel.org/r/20240513103948.33570-1-haifeng.xu@shopee.com +Signed-off-by: Greg Kroah-Hartman +--- + kernel/events/core.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +--- a/kernel/events/core.c ++++ b/kernel/events/core.c +@@ -5353,6 +5353,7 @@ int perf_event_release_kernel(struct per + again: + mutex_lock(&event->child_mutex); + list_for_each_entry(child, &event->child_list, child_list) { ++ void *var = NULL; + + /* + * Cannot change, child events are not migrated, see the +@@ -5393,11 +5394,23 @@ again: + * this can't be the last reference. + */ + put_event(event); ++ } else { ++ var = &ctx->refcount; + } + + mutex_unlock(&event->child_mutex); + mutex_unlock(&ctx->mutex); + put_ctx(ctx); ++ ++ if (var) { ++ /* ++ * If perf_event_free_task() has deleted all events from the ++ * ctx while the child_mutex got released above, make sure to ++ * notify about the preceding put_ctx(). ++ */ ++ smp_mb(); /* pairs with wait_var_event() */ ++ wake_up_var(var); ++ } + goto again; + } + mutex_unlock(&event->child_mutex); diff --git a/queue-6.6/riscv-fix-overlap-of-allocated-page-and-ptr_err.patch b/queue-6.6/riscv-fix-overlap-of-allocated-page-and-ptr_err.patch new file mode 100644 index 00000000000..72fc0fe6b85 --- /dev/null +++ b/queue-6.6/riscv-fix-overlap-of-allocated-page-and-ptr_err.patch @@ -0,0 +1,69 @@ +From 994af1825a2aa286f4903ff64a1c7378b52defe6 Mon Sep 17 00:00:00 2001 +From: Nam Cao +Date: Thu, 25 Apr 2024 13:52:01 +0200 +Subject: riscv: fix overlap of allocated page and PTR_ERR +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Nam Cao + +commit 994af1825a2aa286f4903ff64a1c7378b52defe6 upstream. + +On riscv32, it is possible for the last page in virtual address space +(0xfffff000) to be allocated. This page overlaps with PTR_ERR, so that +shouldn't happen. + +There is already some code to ensure memblock won't allocate the last page. +However, buddy allocator is left unchecked. + +Fix this by reserving physical memory that would be mapped at virtual +addresses greater than 0xfffff000. + +Reported-by: Björn Töpel +Closes: https://lore.kernel.org/linux-riscv/878r1ibpdn.fsf@all.your.base.are.belong.to.us +Fixes: 76d2a0493a17 ("RISC-V: Init and Halt Code") +Signed-off-by: Nam Cao +Cc: +Tested-by: Björn Töpel +Reviewed-by: Björn Töpel +Reviewed-by: Mike Rapoport (IBM) +Link: https://lore.kernel.org/r/20240425115201.3044202-1-namcao@linutronix.de +Signed-off-by: Palmer Dabbelt +Signed-off-by: Greg Kroah-Hartman +--- + arch/riscv/mm/init.c | 21 +++++++++++---------- + 1 file changed, 11 insertions(+), 10 deletions(-) + +--- a/arch/riscv/mm/init.c ++++ b/arch/riscv/mm/init.c +@@ -234,18 +234,19 @@ static void __init setup_bootmem(void) + kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base; + + /* +- * memblock allocator is not aware of the fact that last 4K bytes of +- * the addressable memory can not be mapped because of IS_ERR_VALUE +- * macro. Make sure that last 4k bytes are not usable by memblock +- * if end of dram is equal to maximum addressable memory. For 64-bit +- * kernel, this problem can't happen here as the end of the virtual +- * address space is occupied by the kernel mapping then this check must +- * be done as soon as the kernel mapping base address is determined. ++ * Reserve physical address space that would be mapped to virtual ++ * addresses greater than (void *)(-PAGE_SIZE) because: ++ * - This memory would overlap with ERR_PTR ++ * - This memory belongs to high memory, which is not supported ++ * ++ * This is not applicable to 64-bit kernel, because virtual addresses ++ * after (void *)(-PAGE_SIZE) are not linearly mapped: they are ++ * occupied by kernel mapping. Also it is unrealistic for high memory ++ * to exist on 64-bit platforms. + */ + if (!IS_ENABLED(CONFIG_64BIT)) { +- max_mapped_addr = __pa(~(ulong)0); +- if (max_mapped_addr == (phys_ram_end - 1)) +- memblock_set_current_limit(max_mapped_addr - 4096); ++ max_mapped_addr = __va_to_pa_nodebug(-PAGE_SIZE); ++ memblock_reserve(max_mapped_addr, (phys_addr_t)-max_mapped_addr); + } + + min_low_pfn = PFN_UP(phys_ram_base); diff --git a/queue-6.6/series b/queue-6.6/series index 41a9165d1e9..044d1ce4283 100644 --- a/queue-6.6/series +++ b/queue-6.6/series @@ -196,3 +196,18 @@ drm-exynos-hdmi-report-safe-640x480-mode-as-a-fallback-when-no-edid-found.patch mptcp-ensure-snd_una-is-properly-initialized-on-connect.patch mptcp-pm-inc-rmaddr-mib-counter-once-per-rm_addr-id.patch mptcp-pm-update-add_addr-counters-after-connect.patch +clkdev-update-clkdev-id-usage-to-allow-for-longer-names.patch +irqchip-gic-v3-its-fix-potential-race-condition-in-its_vlpi_prop_update.patch +x86-kexec-fix-bug-with-call-depth-tracking.patch +x86-amd_nb-check-for-invalid-smn-reads.patch +perf-core-fix-missing-wakeup-when-waiting-for-context-reference.patch +perf-auxtrace-fix-multiple-use-of-itrace-option.patch +riscv-fix-overlap-of-allocated-page-and-ptr_err.patch +tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch +kheaders-explicitly-define-file-modes-for-archived-headers.patch +null_blk-print-correct-max-open-zones-limit-in-null_init_zoned_dev.patch +sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch +dma-buf-handle-testing-kthreads-creation-failure.patch +tracing-add-module_description-to-preemptirq_delay_test.patch +vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch +spmi-hisi-spmi-controller-do-not-override-device-identifier.patch diff --git a/queue-6.6/sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch b/queue-6.6/sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch new file mode 100644 index 00000000000..53f4a64e934 --- /dev/null +++ b/queue-6.6/sock_map-avoid-race-between-sock_map_close-and-sk_psock_put.patch @@ -0,0 +1,115 @@ +From 4b4647add7d3c8530493f7247d11e257ee425bf0 Mon Sep 17 00:00:00 2001 +From: Thadeu Lima de Souza Cascardo +Date: Fri, 24 May 2024 11:47:02 -0300 +Subject: sock_map: avoid race between sock_map_close and sk_psock_put + +From: Thadeu Lima de Souza Cascardo + +commit 4b4647add7d3c8530493f7247d11e257ee425bf0 upstream. + +sk_psock_get will return NULL if the refcount of psock has gone to 0, which +will happen when the last call of sk_psock_put is done. However, +sk_psock_drop may not have finished yet, so the close callback will still +point to sock_map_close despite psock being NULL. + +This can be reproduced with a thread deleting an element from the sock map, +while the second one creates a socket, adds it to the map and closes it. + +That will trigger the WARN_ON_ONCE: + +------------[ cut here ]------------ +WARNING: CPU: 1 PID: 7220 at net/core/sock_map.c:1701 sock_map_close+0x2a2/0x2d0 net/core/sock_map.c:1701 +Modules linked in: +CPU: 1 PID: 7220 Comm: syz-executor380 Not tainted 6.9.0-syzkaller-07726-g3c999d1ae3c7 #0 +Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024 +RIP: 0010:sock_map_close+0x2a2/0x2d0 net/core/sock_map.c:1701 +Code: df e8 92 29 88 f8 48 8b 1b 48 89 d8 48 c1 e8 03 42 80 3c 20 00 74 08 48 89 df e8 79 29 88 f8 4c 8b 23 eb 89 e8 4f 15 23 f8 90 <0f> 0b 90 48 83 c4 08 5b 41 5c 41 5d 41 5e 41 5f 5d e9 13 26 3d 02 +RSP: 0018:ffffc9000441fda8 EFLAGS: 00010293 +RAX: ffffffff89731ae1 RBX: ffffffff94b87540 RCX: ffff888029470000 +RDX: 0000000000000000 RSI: ffffffff8bcab5c0 RDI: ffffffff8c1faba0 +RBP: 0000000000000000 R08: ffffffff92f9b61f R09: 1ffffffff25f36c3 +R10: dffffc0000000000 R11: fffffbfff25f36c4 R12: ffffffff89731840 +R13: ffff88804b587000 R14: ffff88804b587000 R15: ffffffff89731870 +FS: 000055555e080380(0000) GS:ffff8880b9500000(0000) knlGS:0000000000000000 +CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +CR2: 0000000000000000 CR3: 00000000207d4000 CR4: 0000000000350ef0 +Call Trace: + + unix_release+0x87/0xc0 net/unix/af_unix.c:1048 + __sock_release net/socket.c:659 [inline] + sock_close+0xbe/0x240 net/socket.c:1421 + __fput+0x42b/0x8a0 fs/file_table.c:422 + __do_sys_close fs/open.c:1556 [inline] + __se_sys_close fs/open.c:1541 [inline] + __x64_sys_close+0x7f/0x110 fs/open.c:1541 + do_syscall_x64 arch/x86/entry/common.c:52 [inline] + do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 + entry_SYSCALL_64_after_hwframe+0x77/0x7f +RIP: 0033:0x7fb37d618070 +Code: 00 00 48 c7 c2 b8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff eb d4 e8 10 2c 00 00 80 3d 31 f0 07 00 00 74 17 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 48 c3 0f 1f 80 00 00 00 00 48 83 ec 18 89 7c +RSP: 002b:00007ffcd4a525d8 EFLAGS: 00000202 ORIG_RAX: 0000000000000003 +RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 00007fb37d618070 +RDX: 0000000000000010 RSI: 00000000200001c0 RDI: 0000000000000004 +RBP: 0000000000000000 R08: 0000000100000000 R09: 0000000100000000 +R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000 +R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 + + +Use sk_psock, which will only check that the pointer is not been set to +NULL yet, which should only happen after the callbacks are restored. If, +then, a reference can still be gotten, we may call sk_psock_stop and cancel +psock->work. + +As suggested by Paolo Abeni, reorder the condition so the control flow is +less convoluted. + +After that change, the reproducer does not trigger the WARN_ON_ONCE +anymore. + +Suggested-by: Paolo Abeni +Reported-by: syzbot+07a2e4a1a57118ef7355@syzkaller.appspotmail.com +Closes: https://syzkaller.appspot.com/bug?extid=07a2e4a1a57118ef7355 +Fixes: aadb2bb83ff7 ("sock_map: Fix a potential use-after-free in sock_map_close()") +Fixes: 5b4a79ba65a1 ("bpf, sockmap: Don't let sock_map_{close,destroy,unhash} call itself") +Cc: stable@vger.kernel.org +Signed-off-by: Thadeu Lima de Souza Cascardo +Acked-by: Jakub Sitnicki +Link: https://lore.kernel.org/r/20240524144702.1178377-1-cascardo@igalia.com +Signed-off-by: Paolo Abeni +Signed-off-by: Greg Kroah-Hartman +--- + net/core/sock_map.c | 16 ++++++++++------ + 1 file changed, 10 insertions(+), 6 deletions(-) + +--- a/net/core/sock_map.c ++++ b/net/core/sock_map.c +@@ -1639,19 +1639,23 @@ void sock_map_close(struct sock *sk, lon + + lock_sock(sk); + rcu_read_lock(); +- psock = sk_psock_get(sk); +- if (unlikely(!psock)) { +- rcu_read_unlock(); +- release_sock(sk); +- saved_close = READ_ONCE(sk->sk_prot)->close; +- } else { ++ psock = sk_psock(sk); ++ if (likely(psock)) { + saved_close = psock->saved_close; + sock_map_remove_links(sk, psock); ++ psock = sk_psock_get(sk); ++ if (unlikely(!psock)) ++ goto no_psock; + rcu_read_unlock(); + sk_psock_stop(psock); + release_sock(sk); + cancel_delayed_work_sync(&psock->work); + sk_psock_put(sk, psock); ++ } else { ++ saved_close = READ_ONCE(sk->sk_prot)->close; ++no_psock: ++ rcu_read_unlock(); ++ release_sock(sk); + } + + /* Make sure we do not recurse. This is a bug. diff --git a/queue-6.6/spmi-hisi-spmi-controller-do-not-override-device-identifier.patch b/queue-6.6/spmi-hisi-spmi-controller-do-not-override-device-identifier.patch new file mode 100644 index 00000000000..f0ac9e4daa3 --- /dev/null +++ b/queue-6.6/spmi-hisi-spmi-controller-do-not-override-device-identifier.patch @@ -0,0 +1,36 @@ +From eda4923d78d634482227c0b189d9b7ca18824146 Mon Sep 17 00:00:00 2001 +From: Vamshi Gajjela +Date: Tue, 7 May 2024 14:07:41 -0700 +Subject: spmi: hisi-spmi-controller: Do not override device identifier + +From: Vamshi Gajjela + +commit eda4923d78d634482227c0b189d9b7ca18824146 upstream. + +'nr' member of struct spmi_controller, which serves as an identifier +for the controller/bus. This value is a dynamic ID assigned in +spmi_controller_alloc, and overriding it from the driver results in an +ida_free error "ida_free called for id=xx which is not allocated". + +Signed-off-by: Vamshi Gajjela +Fixes: 70f59c90c819 ("staging: spmi: add Hikey 970 SPMI controller driver") +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20240228185116.1269-1-vamshigajjela@google.com +Signed-off-by: Stephen Boyd +Link: https://lore.kernel.org/r/20240507210809.3479953-5-sboyd@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Greg Kroah-Hartman +--- + drivers/spmi/hisi-spmi-controller.c | 1 - + 1 file changed, 1 deletion(-) + +--- a/drivers/spmi/hisi-spmi-controller.c ++++ b/drivers/spmi/hisi-spmi-controller.c +@@ -303,7 +303,6 @@ static int spmi_controller_probe(struct + + spin_lock_init(&spmi_controller->lock); + +- ctrl->nr = spmi_controller->channel; + ctrl->dev.parent = pdev->dev.parent; + ctrl->dev.of_node = of_node_get(pdev->dev.of_node); + diff --git a/queue-6.6/tracing-add-module_description-to-preemptirq_delay_test.patch b/queue-6.6/tracing-add-module_description-to-preemptirq_delay_test.patch new file mode 100644 index 00000000000..63514604d8b --- /dev/null +++ b/queue-6.6/tracing-add-module_description-to-preemptirq_delay_test.patch @@ -0,0 +1,34 @@ +From 23748e3e0fbfe471eff5ce439921629f6a427828 Mon Sep 17 00:00:00 2001 +From: Jeff Johnson +Date: Sat, 18 May 2024 15:54:49 -0700 +Subject: tracing: Add MODULE_DESCRIPTION() to preemptirq_delay_test + +From: Jeff Johnson + +commit 23748e3e0fbfe471eff5ce439921629f6a427828 upstream. + +Fix the 'make W=1' warning: + +WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/trace/preemptirq_delay_test.o + +Link: https://lore.kernel.org/linux-trace-kernel/20240518-md-preemptirq_delay_test-v1-1-387d11b30d85@quicinc.com + +Cc: stable@vger.kernel.org +Cc: Mathieu Desnoyers +Fixes: f96e8577da10 ("lib: Add module for testing preemptoff/irqsoff latency tracers") +Acked-by: Masami Hiramatsu (Google) +Signed-off-by: Jeff Johnson +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Greg Kroah-Hartman +--- + kernel/trace/preemptirq_delay_test.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/kernel/trace/preemptirq_delay_test.c ++++ b/kernel/trace/preemptirq_delay_test.c +@@ -215,4 +215,5 @@ static void __exit preemptirq_delay_exit + + module_init(preemptirq_delay_init) + module_exit(preemptirq_delay_exit) ++MODULE_DESCRIPTION("Preempt / IRQ disable delay thread to test latency tracers"); + MODULE_LICENSE("GPL v2"); diff --git a/queue-6.6/tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch b/queue-6.6/tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch new file mode 100644 index 00000000000..18c3db0ca2f --- /dev/null +++ b/queue-6.6/tracing-selftests-fix-kprobe-event-name-test-for-.isra.-functions.patch @@ -0,0 +1,50 @@ +From 23a4b108accc29a6125ed14de4a044689ffeda78 Mon Sep 17 00:00:00 2001 +From: "Steven Rostedt (Google)" +Date: Mon, 20 May 2024 20:57:37 -0400 +Subject: tracing/selftests: Fix kprobe event name test for .isra. functions + +From: Steven Rostedt (Google) + +commit 23a4b108accc29a6125ed14de4a044689ffeda78 upstream. + +The kprobe_eventname.tc test checks if a function with .isra. can have a +kprobe attached to it. It loops through the kallsyms file for all the +functions that have the .isra. name, and checks if it exists in the +available_filter_functions file, and if it does, it uses it to attach a +kprobe to it. + +The issue is that kprobes can not attach to functions that are listed more +than once in available_filter_functions. With the latest kernel, the +function that is found is: rapl_event_update.isra.0 + + # grep rapl_event_update.isra.0 /sys/kernel/tracing/available_filter_functions + rapl_event_update.isra.0 + rapl_event_update.isra.0 + +It is listed twice. This causes the attached kprobe to it to fail which in +turn fails the test. Instead of just picking the function function that is +found in available_filter_functions, pick the first one that is listed +only once in available_filter_functions. + +Cc: stable@vger.kernel.org +Fixes: 604e3548236d ("selftests/ftrace: Select an existing function in kprobe_eventname test") +Signed-off-by: Steven Rostedt (Google) +Acked-by: Masami Hiramatsu (Google) +Signed-off-by: Shuah Khan +Signed-off-by: Greg Kroah-Hartman +--- + tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc ++++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +@@ -30,7 +30,8 @@ find_dot_func() { + fi + + grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do +- if grep -s $f available_filter_functions; then ++ cnt=`grep -s $f available_filter_functions | wc -l`; ++ if [ $cnt -eq 1 ]; then + echo $f + break + fi diff --git a/queue-6.6/vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch b/queue-6.6/vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch new file mode 100644 index 00000000000..bec9e30cacd --- /dev/null +++ b/queue-6.6/vmci-prevent-speculation-leaks-by-sanitizing-event-in-event_deliver.patch @@ -0,0 +1,56 @@ +From 8003f00d895310d409b2bf9ef907c56b42a4e0f4 Mon Sep 17 00:00:00 2001 +From: Hagar Gamal Halim Hemdan +Date: Tue, 30 Apr 2024 08:59:16 +0000 +Subject: vmci: prevent speculation leaks by sanitizing event in event_deliver() + +From: Hagar Gamal Halim Hemdan + +commit 8003f00d895310d409b2bf9ef907c56b42a4e0f4 upstream. + +Coverity spotted that event_msg is controlled by user-space, +event_msg->event_data.event is passed to event_deliver() and used +as an index without sanitization. + +This change ensures that the event index is sanitized to mitigate any +possibility of speculative information leaks. + +This bug was discovered and resolved using Coverity Static Analysis +Security Testing (SAST) by Synopsys, Inc. + +Only compile tested, no access to HW. + +Fixes: 1d990201f9bb ("VMCI: event handling implementation.") +Cc: stable +Signed-off-by: Hagar Gamal Halim Hemdan +Link: https://lore.kernel.org/stable/20231127193533.46174-1-hagarhem%40amazon.com +Link: https://lore.kernel.org/r/20240430085916.4753-1-hagarhem@amazon.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Greg Kroah-Hartman +--- + drivers/misc/vmw_vmci/vmci_event.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +--- a/drivers/misc/vmw_vmci/vmci_event.c ++++ b/drivers/misc/vmw_vmci/vmci_event.c +@@ -9,6 +9,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -86,9 +87,12 @@ static void event_deliver(struct vmci_ev + { + struct vmci_subscription *cur; + struct list_head *subscriber_list; ++ u32 sanitized_event, max_vmci_event; + + rcu_read_lock(); +- subscriber_list = &subscriber_array[event_msg->event_data.event]; ++ max_vmci_event = ARRAY_SIZE(subscriber_array); ++ sanitized_event = array_index_nospec(event_msg->event_data.event, max_vmci_event); ++ subscriber_list = &subscriber_array[sanitized_event]; + list_for_each_entry_rcu(cur, subscriber_list, node) { + cur->callback(cur->id, &event_msg->event_data, + cur->callback_data); diff --git a/queue-6.6/x86-amd_nb-check-for-invalid-smn-reads.patch b/queue-6.6/x86-amd_nb-check-for-invalid-smn-reads.patch new file mode 100644 index 00000000000..238ff9ae94d --- /dev/null +++ b/queue-6.6/x86-amd_nb-check-for-invalid-smn-reads.patch @@ -0,0 +1,59 @@ +From c625dabbf1c4a8e77e4734014f2fde7aa9071a1f Mon Sep 17 00:00:00 2001 +From: Yazen Ghannam +Date: Mon, 3 Apr 2023 16:42:44 +0000 +Subject: x86/amd_nb: Check for invalid SMN reads + +From: Yazen Ghannam + +commit c625dabbf1c4a8e77e4734014f2fde7aa9071a1f upstream. + +AMD Zen-based systems use a System Management Network (SMN) that +provides access to implementation-specific registers. + +SMN accesses are done indirectly through an index/data pair in PCI +config space. The PCI config access may fail and return an error code. +This would prevent the "read" value from being updated. + +However, the PCI config access may succeed, but the return value may be +invalid. This is in similar fashion to PCI bad reads, i.e. return all +bits set. + +Most systems will return 0 for SMN addresses that are not accessible. +This is in line with AMD convention that unavailable registers are +Read-as-Zero/Writes-Ignored. + +However, some systems will return a "PCI Error Response" instead. This +value, along with an error code of 0 from the PCI config access, will +confuse callers of the amd_smn_read() function. + +Check for this condition, clear the return value, and set a proper error +code. + +Fixes: ddfe43cdc0da ("x86/amd_nb: Add SMN and Indirect Data Fabric access for AMD Fam17h") +Signed-off-by: Yazen Ghannam +Signed-off-by: Borislav Petkov (AMD) +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20230403164244.471141-1-yazen.ghannam@amd.com +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kernel/amd_nb.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +--- a/arch/x86/kernel/amd_nb.c ++++ b/arch/x86/kernel/amd_nb.c +@@ -209,7 +209,14 @@ out: + + int amd_smn_read(u16 node, u32 address, u32 *value) + { +- return __amd_smn_rw(node, address, value, false); ++ int err = __amd_smn_rw(node, address, value, false); ++ ++ if (PCI_POSSIBLE_ERROR(*value)) { ++ err = -ENODEV; ++ *value = 0; ++ } ++ ++ return err; + } + EXPORT_SYMBOL_GPL(amd_smn_read); + diff --git a/queue-6.6/x86-kexec-fix-bug-with-call-depth-tracking.patch b/queue-6.6/x86-kexec-fix-bug-with-call-depth-tracking.patch new file mode 100644 index 00000000000..163eb4de6fe --- /dev/null +++ b/queue-6.6/x86-kexec-fix-bug-with-call-depth-tracking.patch @@ -0,0 +1,56 @@ +From 93c1800b3799f17375989b0daf76497dd3e80922 Mon Sep 17 00:00:00 2001 +From: David Kaplan +Date: Sun, 2 Jun 2024 13:19:09 -0500 +Subject: x86/kexec: Fix bug with call depth tracking + +From: David Kaplan + +commit 93c1800b3799f17375989b0daf76497dd3e80922 upstream. + +The call to cc_platform_has() triggers a fault and system crash if call depth +tracking is active because the GS segment has been reset by load_segments() and +GS_BASE is now 0 but call depth tracking uses per-CPU variables to operate. + +Call cc_platform_has() earlier in the function when GS is still valid. + + [ bp: Massage. ] + +Fixes: 5d8213864ade ("x86/retbleed: Add SKL return thunk") +Signed-off-by: David Kaplan +Signed-off-by: Borislav Petkov (AMD) +Reviewed-by: Tom Lendacky +Cc: +Link: https://lore.kernel.org/r/20240603083036.637-1-bp@kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kernel/machine_kexec_64.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +--- a/arch/x86/kernel/machine_kexec_64.c ++++ b/arch/x86/kernel/machine_kexec_64.c +@@ -298,8 +298,15 @@ void machine_kexec_cleanup(struct kimage + void machine_kexec(struct kimage *image) + { + unsigned long page_list[PAGES_NR]; +- void *control_page; ++ unsigned int host_mem_enc_active; + int save_ftrace_enabled; ++ void *control_page; ++ ++ /* ++ * This must be done before load_segments() since if call depth tracking ++ * is used then GS must be valid to make any function calls. ++ */ ++ host_mem_enc_active = cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT); + + #ifdef CONFIG_KEXEC_JUMP + if (image->preserve_context) +@@ -361,7 +368,7 @@ void machine_kexec(struct kimage *image) + (unsigned long)page_list, + image->start, + image->preserve_context, +- cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)); ++ host_mem_enc_active); + + #ifdef CONFIG_KEXEC_JUMP + if (image->preserve_context) -- 2.47.3