mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	Add the const qualifier to all the ctl_tables in the tree except for
watchdog_hardlockup_sysctl, memory_allocation_profiling_sysctls,
loadpin_sysctl_table and the ones calling register_net_sysctl (./net,
drivers/inifiniband dirs). These are special cases as they use a
registration function with a non-const qualified ctl_table argument or
modify the arrays before passing them on to the registration function.
Constifying ctl_table structs will prevent the modification of
proc_handler function pointers as the arrays would reside in .rodata.
This is made possible after commit 78eb4ea25c ("sysctl: treewide:
constify the ctl_table argument of proc_handlers") constified all the
proc_handlers.
Created this by running an spatch followed by a sed command:
Spatch:
    virtual patch
    @
    depends on !(file in "net")
    disable optional_qualifier
    @
    identifier table_name != {
      watchdog_hardlockup_sysctl,
      iwcm_ctl_table,
      ucma_ctl_table,
      memory_allocation_profiling_sysctls,
      loadpin_sysctl_table
    };
    @@
    + const
    struct ctl_table table_name [] = { ... };
sed:
    sed --in-place \
      -e "s/struct ctl_table .table = &uts_kern/const struct ctl_table *table = \&uts_kern/" \
      kernel/utsname_sysctl.c
Reviewed-by: Song Liu <song@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org> # for kernel/trace/
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> # SCSI
Reviewed-by: Darrick J. Wong <djwong@kernel.org> # xfs
Acked-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Acked-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Joel Granados <joel.granados@kernel.org>
		
	
			
		
			
				
	
	
		
			53 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* SPDX-License-Identifier: GPL-2.0 */
 | 
						|
#ifndef LINUX_PID_SYSCTL_H
 | 
						|
#define LINUX_PID_SYSCTL_H
 | 
						|
 | 
						|
#include <linux/pid_namespace.h>
 | 
						|
 | 
						|
#if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE)
 | 
						|
static int pid_mfd_noexec_dointvec_minmax(const struct ctl_table *table,
 | 
						|
	int write, void *buf, size_t *lenp, loff_t *ppos)
 | 
						|
{
 | 
						|
	struct pid_namespace *ns = task_active_pid_ns(current);
 | 
						|
	struct ctl_table table_copy;
 | 
						|
	int err, scope, parent_scope;
 | 
						|
 | 
						|
	if (write && !ns_capable(ns->user_ns, CAP_SYS_ADMIN))
 | 
						|
		return -EPERM;
 | 
						|
 | 
						|
	table_copy = *table;
 | 
						|
 | 
						|
	/* You cannot set a lower enforcement value than your parent. */
 | 
						|
	parent_scope = pidns_memfd_noexec_scope(ns->parent);
 | 
						|
	/* Equivalent to pidns_memfd_noexec_scope(ns). */
 | 
						|
	scope = max(READ_ONCE(ns->memfd_noexec_scope), parent_scope);
 | 
						|
 | 
						|
	table_copy.data = &scope;
 | 
						|
	table_copy.extra1 = &parent_scope;
 | 
						|
 | 
						|
	err = proc_dointvec_minmax(&table_copy, write, buf, lenp, ppos);
 | 
						|
	if (!err && write)
 | 
						|
		WRITE_ONCE(ns->memfd_noexec_scope, scope);
 | 
						|
	return err;
 | 
						|
}
 | 
						|
 | 
						|
static const struct ctl_table pid_ns_ctl_table_vm[] = {
 | 
						|
	{
 | 
						|
		.procname	= "memfd_noexec",
 | 
						|
		.data		= &init_pid_ns.memfd_noexec_scope,
 | 
						|
		.maxlen		= sizeof(init_pid_ns.memfd_noexec_scope),
 | 
						|
		.mode		= 0644,
 | 
						|
		.proc_handler	= pid_mfd_noexec_dointvec_minmax,
 | 
						|
		.extra1		= SYSCTL_ZERO,
 | 
						|
		.extra2		= SYSCTL_TWO,
 | 
						|
	},
 | 
						|
};
 | 
						|
static inline void register_pid_ns_sysctl_table_vm(void)
 | 
						|
{
 | 
						|
	register_sysctl("vm", pid_ns_ctl_table_vm);
 | 
						|
}
 | 
						|
#else
 | 
						|
static inline void register_pid_ns_sysctl_table_vm(void) {}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* LINUX_PID_SYSCTL_H */
 |