Skip to content

Commit dd141a4

Browse files
legionusebiederm
authored andcommitted
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: 1f5c135 ("ipc: Store ipc sysctls in the ipc namespace") Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Alexey Gladkov <legion@kernel.org> Link: https://lkml.kernel.org/r/93df64a8fe93ba20ebbe1d9f8eda484b2f325426.1651584847.git.legion@kernel.org Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
1 parent def7343 commit dd141a4

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

ipc/ipc_sysctl.c

+7-17
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@
1919
static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
2020
void *buffer, size_t *lenp, loff_t *ppos)
2121
{
22-
struct ipc_namespace *ns = table->extra1;
23-
struct ctl_table ipc_table;
22+
struct ipc_namespace *ns =
23+
container_of(table->data, struct ipc_namespace, shm_rmid_forced);
2424
int err;
2525

26-
memcpy(&ipc_table, table, sizeof(ipc_table));
27-
28-
ipc_table.extra1 = SYSCTL_ZERO;
29-
ipc_table.extra2 = SYSCTL_ONE;
30-
31-
err = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
26+
err = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
3227

3328
if (err < 0)
3429
return err;
@@ -55,15 +50,10 @@ static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
5550
static int proc_ipc_sem_dointvec(struct ctl_table *table, int write,
5651
void *buffer, size_t *lenp, loff_t *ppos)
5752
{
58-
struct ipc_namespace *ns = table->extra1;
59-
struct ctl_table ipc_table;
53+
struct ipc_namespace *ns =
54+
container_of(table->data, struct ipc_namespace, sem_ctls);
6055
int ret, semmni;
6156

62-
memcpy(&ipc_table, table, sizeof(ipc_table));
63-
64-
ipc_table.extra1 = NULL;
65-
ipc_table.extra2 = NULL;
66-
6757
semmni = ns->sem_ctls[3];
6858
ret = proc_dointvec(table, write, buffer, lenp, ppos);
6959

@@ -131,6 +121,8 @@ static struct ctl_table ipc_sysctls[] = {
131121
.maxlen = sizeof(init_ipc_ns.shm_rmid_forced),
132122
.mode = 0644,
133123
.proc_handler = proc_ipc_dointvec_minmax_orphans,
124+
.extra1 = SYSCTL_ZERO,
125+
.extra2 = SYSCTL_ONE,
134126
},
135127
{
136128
.procname = "msgmax",
@@ -237,7 +229,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns)
237229

238230
} else if (tbl[i].data == &init_ipc_ns.shm_rmid_forced) {
239231
tbl[i].data = &ns->shm_rmid_forced;
240-
tbl[i].extra1 = ns;
241232

242233
} else if (tbl[i].data == &init_ipc_ns.msg_ctlmax) {
243234
tbl[i].data = &ns->msg_ctlmax;
@@ -250,7 +241,6 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns)
250241

251242
} else if (tbl[i].data == &init_ipc_ns.sem_ctls) {
252243
tbl[i].data = &ns->sem_ctls;
253-
tbl[i].extra1 = ns;
254244
#ifdef CONFIG_CHECKPOINT_RESTORE
255245
} else if (tbl[i].data == &init_ipc_ns.ids[IPC_SEM_IDS].next_id) {
256246
tbl[i].data = &ns->ids[IPC_SEM_IDS].next_id;

0 commit comments

Comments
 (0)