2019-06-01 08:08:55 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-02-14 08:33:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007
|
|
|
|
*
|
|
|
|
* Author: Eric Biederman <ebiederm@xmision.com>
|
|
|
|
*/
|
|
|
|
|
2011-05-23 18:51:41 +00:00
|
|
|
#include <linux/export.h>
|
2007-02-14 08:33:58 +00:00
|
|
|
#include <linux/uts.h>
|
|
|
|
#include <linux/utsname.h>
|
2022-09-27 09:35:16 +00:00
|
|
|
#include <linux/random.h>
|
2007-02-14 08:33:58 +00:00
|
|
|
#include <linux/sysctl.h>
|
2011-11-02 20:39:22 +00:00
|
|
|
#include <linux/wait.h>
|
2017-02-08 17:51:58 +00:00
|
|
|
#include <linux/rwsem.h>
|
2007-02-14 08:33:58 +00:00
|
|
|
|
2013-02-28 01:05:22 +00:00
|
|
|
#ifdef CONFIG_PROC_SYSCTL
|
|
|
|
|
2024-05-18 13:53:40 +00:00
|
|
|
static void *get_uts(const struct ctl_table *table)
|
2007-02-14 08:33:58 +00:00
|
|
|
{
|
|
|
|
char *which = table->data;
|
2007-11-29 00:21:38 +00:00
|
|
|
struct uts_namespace *uts_ns;
|
|
|
|
|
|
|
|
uts_ns = current->nsproxy->uts_ns;
|
|
|
|
which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
|
2007-07-16 06:40:58 +00:00
|
|
|
|
2007-02-14 08:33:58 +00:00
|
|
|
return which;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case of dostring for the UTS structure. This has locks
|
|
|
|
* to observe. Should this be in kernel/sys.c ????
|
|
|
|
*/
|
sysctl: treewide: constify the ctl_table argument of proc_handlers
const qualify the struct ctl_table argument in the proc_handler function
signatures. This is a prerequisite to moving the static ctl_table
structs into .rodata data which will ensure that proc_handler function
pointers cannot be modified.
This patch has been generated by the following coccinelle script:
```
virtual patch
@r1@
identifier ctl, write, buffer, lenp, ppos;
identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)";
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos);
@r2@
identifier func, ctl, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos)
{ ... }
@r3@
identifier func;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int , void *, size_t *, loff_t *);
@r4@
identifier func, ctl;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int , void *, size_t *, loff_t *);
@r5@
identifier func, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int write, void *buffer, size_t *lenp, loff_t *ppos);
```
* Code formatting was adjusted in xfs_sysctl.c to comply with code
conventions. The xfs_stats_clear_proc_handler,
xfs_panic_mask_proc_handler and xfs_deprecated_dointvec_minmax where
adjusted.
* The ctl_table argument in proc_watchdog_common was const qualified.
This is called from a proc_handler itself and is calling back into
another proc_handler, making it necessary to change it as part of the
proc_handler migration.
Co-developed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Co-developed-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Joel Granados <j.granados@samsung.com>
2024-07-24 18:59:29 +00:00
|
|
|
static int proc_do_uts_string(const struct ctl_table *table, int write,
|
2020-04-24 06:43:38 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2007-02-14 08:33:58 +00:00
|
|
|
{
|
|
|
|
struct ctl_table uts_table;
|
|
|
|
int r;
|
2018-06-25 16:34:10 +00:00
|
|
|
char tmp_data[__NEW_UTS_LEN + 1];
|
|
|
|
|
2007-02-14 08:33:58 +00:00
|
|
|
memcpy(&uts_table, table, sizeof(uts_table));
|
2018-06-25 16:34:10 +00:00
|
|
|
uts_table.data = tmp_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer the value in tmp_data so that proc_dostring() can be called
|
|
|
|
* without holding any locks.
|
|
|
|
* We also need to read the original value in the write==1 case to
|
|
|
|
* support partial writes.
|
|
|
|
*/
|
|
|
|
down_read(&uts_sem);
|
|
|
|
memcpy(tmp_data, get_uts(table), sizeof(tmp_data));
|
|
|
|
up_read(&uts_sem);
|
2014-06-04 23:11:26 +00:00
|
|
|
r = proc_dostring(&uts_table, write, buffer, lenp, ppos);
|
2011-11-02 20:39:22 +00:00
|
|
|
|
2018-06-25 16:34:10 +00:00
|
|
|
if (write) {
|
|
|
|
/*
|
|
|
|
* Write back the new value.
|
|
|
|
* Note that, since we dropped uts_sem, the result can
|
|
|
|
* theoretically be incorrect if there are two parallel writes
|
|
|
|
* at non-zero offsets to the same sysctl.
|
|
|
|
*/
|
2022-09-27 09:35:16 +00:00
|
|
|
add_device_randomness(tmp_data, sizeof(tmp_data));
|
2018-06-25 16:34:10 +00:00
|
|
|
down_write(&uts_sem);
|
|
|
|
memcpy(get_uts(table), tmp_data, sizeof(tmp_data));
|
|
|
|
up_write(&uts_sem);
|
2011-11-02 20:39:22 +00:00
|
|
|
proc_sys_poll_notify(table->poll);
|
2018-06-25 16:34:10 +00:00
|
|
|
}
|
2011-11-02 20:39:22 +00:00
|
|
|
|
2007-02-14 08:33:58 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define proc_do_uts_string NULL
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 20:39:22 +00:00
|
|
|
static DEFINE_CTL_TABLE_POLL(hostname_poll);
|
|
|
|
static DEFINE_CTL_TABLE_POLL(domainname_poll);
|
|
|
|
|
2022-10-23 19:01:01 +00:00
|
|
|
// Note: update 'enum uts_proc' to match any changes to this table
|
2007-02-14 08:33:58 +00:00
|
|
|
static struct ctl_table uts_kern_table[] = {
|
2022-09-01 19:44:03 +00:00
|
|
|
{
|
|
|
|
.procname = "arch",
|
|
|
|
.data = init_uts_ns.name.machine,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.machine),
|
|
|
|
.mode = 0444,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
|
|
|
},
|
2007-02-14 08:33:58 +00:00
|
|
|
{
|
|
|
|
.procname = "ostype",
|
|
|
|
.data = init_uts_ns.name.sysname,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.sysname),
|
|
|
|
.mode = 0444,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "osrelease",
|
|
|
|
.data = init_uts_ns.name.release,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.release),
|
|
|
|
.mode = 0444,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "version",
|
|
|
|
.data = init_uts_ns.name.version,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.version),
|
|
|
|
.mode = 0444,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "hostname",
|
|
|
|
.data = init_uts_ns.name.nodename,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.nodename),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
2011-11-02 20:39:22 +00:00
|
|
|
.poll = &hostname_poll,
|
2007-02-14 08:33:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "domainname",
|
|
|
|
.data = init_uts_ns.name.domainname,
|
|
|
|
.maxlen = sizeof(init_uts_ns.name.domainname),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_do_uts_string,
|
2011-11-02 20:39:22 +00:00
|
|
|
.poll = &domainname_poll,
|
2007-02-14 08:33:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-02 20:39:22 +00:00
|
|
|
#ifdef CONFIG_PROC_SYSCTL
|
|
|
|
/*
|
|
|
|
* Notify userspace about a change in a certain entry of uts_kern_table,
|
|
|
|
* identified by the parameter proc.
|
|
|
|
*/
|
|
|
|
void uts_proc_notify(enum uts_proc proc)
|
|
|
|
{
|
|
|
|
struct ctl_table *table = &uts_kern_table[proc];
|
|
|
|
|
|
|
|
proc_sys_poll_notify(table->poll);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-14 08:33:58 +00:00
|
|
|
static int __init utsname_sysctl_init(void)
|
|
|
|
{
|
2023-03-10 09:24:10 +00:00
|
|
|
register_sysctl("kernel", uts_kern_table);
|
2007-02-14 08:33:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-04 23:11:26 +00:00
|
|
|
device_initcall(utsname_sysctl_init);
|