Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

alloc_tag: fix rw permission issue when handling boot parameter

Boot parameters prefixed with "sysctl." are processed during the final
stage of system initialization via kernel_init()-> do_sysctl_args(). When
CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled, the sysctl.vm.mem_profiling
entry is not writable and will cause a warning.

Before run_init_process(), system initialization executes in kernel thread
context. Use current->mm to distinguish sysctl writes during
do_sysctl_args() from user-space triggered ones.

And when the proc_handler is from do_sysctl_args(), always return success
because the same value was already set by setup_early_mem_profiling() and
this eliminates a permission denied warning.

Link: https://lkml.kernel.org/r/20260115031536.164254-1-ranxiaokai627@163.com
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ran Xiaokai and committed by
Andrew Morton
77bcee8d d468d8f8

+16 -6
+16 -6
lib/alloc_tag.c
··· 776 776 static int proc_mem_profiling_handler(const struct ctl_table *table, int write, 777 777 void *buffer, size_t *lenp, loff_t *ppos) 778 778 { 779 - if (!mem_profiling_support && write) 780 - return -EINVAL; 779 + if (write) { 780 + /* 781 + * Call from do_sysctl_args() which is a no-op since the same 782 + * value was already set by setup_early_mem_profiling. 783 + * Return success to avoid warnings from do_sysctl_args(). 784 + */ 785 + if (!current->mm) 786 + return 0; 787 + 788 + #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG 789 + /* User can't toggle profiling while debugging */ 790 + return -EACCES; 791 + #endif 792 + if (!mem_profiling_support) 793 + return -EINVAL; 794 + } 781 795 782 796 return proc_do_static_key(table, write, buffer, lenp, ppos); 783 797 } ··· 801 787 { 802 788 .procname = "mem_profiling", 803 789 .data = &mem_alloc_profiling_key, 804 - #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG 805 - .mode = 0444, 806 - #else 807 790 .mode = 0644, 808 - #endif 809 791 .proc_handler = proc_mem_profiling_handler, 810 792 }, 811 793 };