Commit dd141a49 authored by Alexey Gladkov's avatar Alexey Gladkov Committed by Eric W. Biederman

ipc: Remove extra1 field abuse to pass ipc namespace

Eric Biederman pointed out that using .extra1 to pass ipc namespace
looks like an ugly hack and there is a better solution. We can get the
ipc_namespace using the .data field.

Link: https://lore.kernel.org/lkml/87czib9g38.fsf@email.froward.int.ebiederm.org/
Fixes: 1f5c135e ("ipc: Store ipc sysctls in the ipc namespace")
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarAlexey Gladkov <legion@kernel.org>
Link: https://lkml.kernel.org/r/93df64a8fe93ba20ebbe1d9f8eda484b2f325426.1651584847.git.legion@kernel.orgSigned-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent def7343f
...@@ -19,16 +19,11 @@ ...@@ -19,16 +19,11 @@
static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write, static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos) void *buffer, size_t *lenp, loff_t *ppos)
{ {
struct ipc_namespace *ns = table->extra1; struct ipc_namespace *ns =
struct ctl_table ipc_table; container_of(table->data, struct ipc_namespace, shm_rmid_forced);
int err; int err;
memcpy(&ipc_table, table, sizeof(ipc_table)); err = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
ipc_table.extra1 = SYSCTL_ZERO;
ipc_table.extra2 = SYSCTL_ONE;
err = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
if (err < 0) if (err < 0)
return err; return err;
...@@ -55,15 +50,10 @@ static int proc_ipc_auto_msgmni(struct ctl_table *table, int write, ...@@ -55,15 +50,10 @@ static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
static int proc_ipc_sem_dointvec(struct ctl_table *table, int write, static int proc_ipc_sem_dointvec(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos) void *buffer, size_t *lenp, loff_t *ppos)
{ {
struct ipc_namespace *ns = table->extra1; struct ipc_namespace *ns =
struct ctl_table ipc_table; container_of(table->data, struct ipc_namespace, sem_ctls);
int ret, semmni; int ret, semmni;
memcpy(&ipc_table, table, sizeof(ipc_table));
ipc_table.extra1 = NULL;
ipc_table.extra2 = NULL;
semmni = ns->sem_ctls[3]; semmni = ns->sem_ctls[3];
ret = proc_dointvec(table, write, buffer, lenp, ppos); ret = proc_dointvec(table, write, buffer, lenp, ppos);
...@@ -131,6 +121,8 @@ static struct ctl_table ipc_sysctls[] = { ...@@ -131,6 +121,8 @@ static struct ctl_table ipc_sysctls[] = {
.maxlen = sizeof(init_ipc_ns.shm_rmid_forced), .maxlen = sizeof(init_ipc_ns.shm_rmid_forced),
.mode = 0644, .mode = 0644,
.proc_handler = proc_ipc_dointvec_minmax_orphans, .proc_handler = proc_ipc_dointvec_minmax_orphans,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
}, },
{ {
.procname = "msgmax", .procname = "msgmax",
...@@ -237,7 +229,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns) ...@@ -237,7 +229,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns)
} else if (tbl[i].data == &init_ipc_ns.shm_rmid_forced) { } else if (tbl[i].data == &init_ipc_ns.shm_rmid_forced) {
tbl[i].data = &ns->shm_rmid_forced; tbl[i].data = &ns->shm_rmid_forced;
tbl[i].extra1 = ns;
} else if (tbl[i].data == &init_ipc_ns.msg_ctlmax) { } else if (tbl[i].data == &init_ipc_ns.msg_ctlmax) {
tbl[i].data = &ns->msg_ctlmax; tbl[i].data = &ns->msg_ctlmax;
...@@ -250,7 +241,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns) ...@@ -250,7 +241,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns)
} else if (tbl[i].data == &init_ipc_ns.sem_ctls) { } else if (tbl[i].data == &init_ipc_ns.sem_ctls) {
tbl[i].data = &ns->sem_ctls; tbl[i].data = &ns->sem_ctls;
tbl[i].extra1 = ns;
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_CHECKPOINT_RESTORE
} else if (tbl[i].data == &init_ipc_ns.ids[IPC_SEM_IDS].next_id) { } else if (tbl[i].data == &init_ipc_ns.ids[IPC_SEM_IDS].next_id) {
tbl[i].data = &ns->ids[IPC_SEM_IDS].next_id; tbl[i].data = &ns->ids[IPC_SEM_IDS].next_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment