Centos-kernel-stream-9/kernel
Augusto Caringi 509e36e98a Merge: CVE-2022-49648: tracing/histograms: Fix memory leak problem
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6444

JIRA: https://issues.redhat.com/browse/RHEL-81008
CVE: CVE-2022-49648

```
commit 7edc3945bdce9c39198a10d6129377a5c53559c2
Author: Zheng Yejian <zhengyejian1@huawei.com>
Date:   Mon Jul 11 09:47:31 2022 +0800

    tracing/histograms: Fix memory leak problem

    This reverts commit 46bbe5c671.

    As commit 46bbe5c671 ("tracing: fix double free") said, the
    "double free" problem reported by clang static analyzer is:
      > In parse_var_defs() if there is a problem allocating
      > var_defs.expr, the earlier var_defs.name is freed.
      > This free is duplicated by free_var_defs() which frees
      > the rest of the list.

    However, if there is a problem allocating N-th var_defs.expr:
      + in parse_var_defs(), the freed 'earlier var_defs.name' is
        actually the N-th var_defs.name;
      + then in free_var_defs(), the names from 0th to (N-1)-th are freed;

                            IF ALLOCATING PROBLEM HAPPENED HERE!!! -+
                                                                     \
                                                                      |
              0th           1th                 (N-1)-th      N-th    V
              +-------------+-------------+-----+-------------+-----------
    var_defs: | name | expr | name | expr | ... | name | expr | name | ///
              +-------------+-------------+-----+-------------+-----------

    These two frees don't act on same name, so there was no "double free"
    problem before. Conversely, after that commit, we get a "memory leak"
    problem because the above "N-th var_defs.name" is not freed.

    If enable CONFIG_DEBUG_KMEMLEAK and inject a fault at where the N-th
    var_defs.expr allocated, then execute on shell like:
      $ echo 'hist:key=call_site:val=$v1,$v2:v1=bytes_req,v2=bytes_alloc' > \
    /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger

    Then kmemleak reports:
      unreferenced object 0xffff8fb100ef3518 (size 8):
        comm "bash", pid 196, jiffies 4295681690 (age 28.538s)
        hex dump (first 8 bytes):
          76 31 00 00 b1 8f ff ff                          v1......
        backtrace:
          [<0000000038fe4895>] kstrdup+0x2d/0x60
          [<00000000c99c049a>] event_hist_trigger_parse+0x206f/0x20e0
          [<00000000ae70d2cc>] trigger_process_regex+0xc0/0x110
          [<0000000066737a4c>] event_trigger_write+0x75/0xd0
          [<000000007341e40c>] vfs_write+0xbb/0x2a0
          [<0000000087fde4c2>] ksys_write+0x59/0xd0
          [<00000000581e9cdf>] do_syscall_64+0x3a/0x80
          [<00000000cf3b065c>] entry_SYSCALL_64_after_hwframe+0x46/0xb0

    Link: https://lkml.kernel.org/r/20220711014731.69520-1-zhengyejian1@huawei.com

    Cc: stable@vger.kernel.org
    Fixes: 46bbe5c671 ("tracing: fix double free")
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Suggested-by: Steven Rostedt <rostedt@goodmis.org>
    Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>
    Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>```

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

---

<small>Created 2025-02-26 22:20 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: Waiman Long <longman@redhat.com>
Approved-by: Jerome Marchand <jmarchan@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Augusto Caringi <acaringi@redhat.com>
2025-05-21 18:34:48 -03:00
..
bpf mm: switch mm->get_unmapped_area() to a flag 2025-03-18 17:09:47 +01:00
cgroup cgroup/cpuset: Add warnings to catch inconsistency in exclusive CPUs 2025-04-09 21:58:43 -04:00
configs mm/slab: rename CONFIG_SLAB to CONFIG_SLAB_DEPRECATED 2024-09-05 20:35:59 -04:00
debug
dma dma-mapping: fix swapped dir/flags arguments to trace_dma_alloc_sgt_err 2025-04-03 09:22:41 -07:00
entry
events kernel: be more careful about dup_mmap() failures and uprobe registering 2025-04-18 08:39:53 -04:00
futex fault-inject: improve build for CONFIG_FAULT_INJECTION=n 2024-12-17 22:59:23 +01:00
gcov
irq genirq/msi: Silence 'set affinity failed' warning 2025-02-18 09:48:09 -07:00
kcsan
livepatch livepatch: Add stack_order sysfs attribute 2025-04-03 13:23:15 -04:00
locking locking/lockdep: Add kasan_check_byte() check in lock_acquire() 2025-03-07 23:10:46 -05:00
module module, bpf: Store BTF base pointer in struct module 2024-11-26 15:55:10 +01:00
power arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernate 2025-04-10 08:35:33 -04:00
printk Flush console log from kernel_power_off() 2025-05-02 11:11:41 -04:00
rcu rcu/kvfree: Fix data-race in __mod_timer / kvfree_call_rcu 2025-01-08 17:48:13 -05:00
sched Merge: sched/rt: Fix race in push_rt_task 2025-05-19 15:19:09 -03:00
time Merge: Scheduler updates for 9.7 2025-03-12 14:53:01 -03:00
trace Merge: CVE-2022-49648: tracing/histograms: Fix memory leak problem 2025-05-21 18:34:48 -03:00
.gitignore
Kconfig.freezer
Kconfig.hz
Kconfig.kexec crash: clean up kdump related config items 2024-12-23 09:35:35 +08:00
Kconfig.locks
Kconfig.preempt
Makefile Merge: RHEL9.6 drm backport dependencies 2025-01-06 08:26:14 +00:00
acct.c
async.c
audit.c Merge: audit: Send netlink ACK before setting connection in auditd_set 2024-08-16 14:22:20 +00:00
audit.h
audit_fsnotify.c
audit_tree.c audit: Annotate struct audit_chunk with __counted_by 2024-07-04 14:52:57 -03:00
audit_watch.c
auditfilter.c audit: remove unnecessary assignment in audit_dupe_lsm_field() 2024-07-04 14:53:06 -03:00
auditsc.c fs: port xattr to mnt_idmap 2024-10-16 10:45:21 +08:00
backtracetest.c
bounds.c
capability.c fs: port i_{g,u}id_into_vfs{g,u}id() to mnt_idmap 2024-10-16 11:02:01 +08:00
cfi.c
compat.c
configs.c
context_tracking.c
cpu.c Merge: Update arch/{x86,powerpc,arm64}/mm to v6.6 2024-11-12 08:02:20 +00:00
cpu_pm.c
crash_core.c Document/kexec: generalize crash hotplug description 2024-12-23 09:35:36 +08:00
crash_reserve.c crash: add prefix for crash dumping messages 2024-12-23 09:35:36 +08:00
cred.c
delayacct.c delayacct: track delays from IRQ/SOFTIRQ 2024-07-15 11:12:08 -04:00
dma.c
elfcorehdr.c crash: remove dependency of FA_DUMP on CRASH_DUMP 2024-12-23 09:35:35 +08:00
exec_domain.c
exit.c lazy tlb: introduce lazy tlb mm refcount helper functions 2024-11-04 09:14:17 -05:00
exit.h exit: add internal include file with helpers 2024-07-02 09:45:34 -04:00
extable.c
fail_function.c
fork.c kernel: be more careful about dup_mmap() failures and uprobe registering 2025-04-18 08:39:53 -04:00
freezer.c
gen_kheaders.sh
groups.c
hung_task.c
iomem.c mm: move is_ioremap_addr() into new header file 2024-10-01 11:17:52 -04:00
irq_work.c
jump_label.c jump_label: Fix static_key_slow_dec() yet again 2025-04-20 20:01:13 -04:00
kallsyms.c
kallsyms_internal.h
kallsyms_selftest.c
kallsyms_selftest.h
kcmp.c
kcov.c
kexec.c crash: add a new kexec flag for hotplug support 2024-12-23 09:35:36 +08:00
kexec_core.c crash: split crash dumping code out from kexec_core.c 2024-12-23 09:35:35 +08:00
kexec_elf.c
kexec_file.c kexec_file: fix elfcorehdr digest exclusion when CONFIG_CRASH_HOTPLUG=y 2024-12-23 09:35:36 +08:00
kexec_internal.h crash: remove dependency of FA_DUMP on CRASH_DUMP 2024-12-23 09:35:35 +08:00
kheaders.c
kprobes.c fprobe: Pass return address to the handlers 2024-10-25 09:07:32 +02:00
ksyms_common.c
ksysfs.c crash: split crash dumping code out from kexec_core.c 2024-12-23 09:35:35 +08:00
kthread.c kthread: unpark only parked kthread 2024-11-25 12:31:48 +00:00
latencytop.c
module_signature.c
notifier.c
nsproxy.c
padata.c padata: avoid UAF for reorder_work 2025-02-28 11:00:53 -05:00
panic.c mm: remove arguments of show_mem() 2024-10-01 11:17:31 -04:00
params.c
pid.c
pid_namespace.c Revert "rcu-tasks: Fix synchronize_rcu_tasks() VS zap_pid_ns_processes()" 2024-08-26 10:57:50 -04:00
pid_sysctl.h
profile.c
ptrace.c mm: make __access_remote_vm() static 2024-12-09 12:22:45 -05:00
range.c
reboot.c Flush console log from kernel_power_off() 2025-05-02 11:11:41 -04:00
regset.c
relay.c
resource.c resource: fix region_intersects() vs add_memory_driver_managed() 2024-10-29 10:10:23 -06:00
resource_kunit.c
rh_messages.c
rh_messages.h [redhat] rh_messages.h: driver and device updates 2025-02-04 16:04:03 -05:00
rh_shadowman.c
rseq.c
scftorture.c
scs.c
seccomp.c
signal.c signal: restore the override_rlimit logic 2024-12-20 15:33:02 +00:00
smp.c
smpboot.c kthread: add kthread_stop_put 2024-09-20 12:26:34 -07:00
smpboot.h
softirq.c softirq: Allow raising SCHED_SOFTIRQ from SMP-call-function on RT kernel 2024-12-11 19:37:36 +00:00
stackleak.c
stacktrace.c
static_call.c
static_call_inline.c x86/static-call: provide a way to do very early static-call updates 2025-02-18 17:58:05 +01:00
stop_machine.c
sys.c Merge: CVE-2024-50271: ucounts: Split rlimit and ucount values and max values 2025-02-03 10:00:41 -05:00
sys_ni.c x86/shstk: Introduce map_shadow_stack syscall 2024-10-01 11:17:15 -04:00
sysctl-test.c
sysctl.c mm: hugetlb: move hugeltb sysctls to its own file 2024-07-16 09:29:59 -04:00
task_work.c task_work: Add TWA_NMI_CURRENT as an additional notify mode. 2024-10-14 13:02:40 +02:00
taskstats.c
test_kprobes.c
torture.c
tracepoint.c
tsacct.c
ucount.c signal: restore the override_rlimit logic 2024-12-20 15:33:02 +00:00
uid16.c
uid16.h
umh.c
up.c
user-return-notifier.c
user.c
user_namespace.c Merge: CVE-2024-50271: ucounts: Split rlimit and ucount values and max values 2025-02-03 10:00:41 -05:00
usermode_driver.c
utsname.c
utsname_sysctl.c
vmcore_info.c crash: split vmcoreinfo exporting code out from crash_core.c 2024-12-23 09:35:35 +08:00
watch_queue.c watch_queue: fix pipe accounting mismatch 2025-04-02 10:32:41 +02:00
watchdog.c
watchdog_hld.c
workqueue.c workqueue: Put the pwq after detaching the rescuer from the pool 2025-02-27 22:46:55 +00:00
workqueue_internal.h