Skip to content

Commit 5563cab

Browse files
mclapinskitorvalds
authored andcommitted
ipc: check checkpoint_restore_ns_capable() to modify C/R proc files
This commit removes the requirement to be root to modify sem_next_id, msg_next_id and shm_next_id and checks checkpoint_restore_ns_capable instead. Since those files are specific to the IPC namespace, there is no reason they should require root privileges. This is similar to ns_last_pid, which also only checks checkpoint_restore_ns_capable. [[email protected]: ipc/ipc_sysctl.c needs capability.h for checkpoint_restore_ns_capable()] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Michal Clapinski <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Reviewed-by: Manfred Spraul <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 303f8e2 commit 5563cab

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

ipc/ipc_sysctl.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/nsproxy.h>
1111
#include <linux/sysctl.h>
1212
#include <linux/uaccess.h>
13+
#include <linux/capability.h>
1314
#include <linux/ipc_namespace.h>
1415
#include <linux/msg.h>
1516
#include "util.h"
@@ -104,13 +105,29 @@ static int proc_ipc_sem_dointvec(struct ctl_table *table, int write,
104105
return ret;
105106
}
106107

108+
#ifdef CONFIG_CHECKPOINT_RESTORE
109+
static int proc_ipc_dointvec_minmax_checkpoint_restore(struct ctl_table *table,
110+
int write, void *buffer, size_t *lenp, loff_t *ppos)
111+
{
112+
struct user_namespace *user_ns = current->nsproxy->ipc_ns->user_ns;
113+
114+
if (write && !checkpoint_restore_ns_capable(user_ns))
115+
return -EPERM;
116+
117+
return proc_ipc_dointvec_minmax(table, write, buffer, lenp, ppos);
118+
}
119+
#endif
120+
107121
#else
108122
#define proc_ipc_doulongvec_minmax NULL
109123
#define proc_ipc_dointvec NULL
110124
#define proc_ipc_dointvec_minmax NULL
111125
#define proc_ipc_dointvec_minmax_orphans NULL
112126
#define proc_ipc_auto_msgmni NULL
113127
#define proc_ipc_sem_dointvec NULL
128+
#ifdef CONFIG_CHECKPOINT_RESTORE
129+
#define proc_ipc_dointvec_minmax_checkpoint_restore NULL
130+
#endif /* CONFIG_CHECKPOINT_RESTORE */
114131
#endif
115132

116133
int ipc_mni = IPCMNI;
@@ -198,26 +215,26 @@ static struct ctl_table ipc_kern_table[] = {
198215
.procname = "sem_next_id",
199216
.data = &init_ipc_ns.ids[IPC_SEM_IDS].next_id,
200217
.maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
201-
.mode = 0644,
202-
.proc_handler = proc_ipc_dointvec_minmax,
218+
.mode = 0666,
219+
.proc_handler = proc_ipc_dointvec_minmax_checkpoint_restore,
203220
.extra1 = SYSCTL_ZERO,
204221
.extra2 = SYSCTL_INT_MAX,
205222
},
206223
{
207224
.procname = "msg_next_id",
208225
.data = &init_ipc_ns.ids[IPC_MSG_IDS].next_id,
209226
.maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
210-
.mode = 0644,
211-
.proc_handler = proc_ipc_dointvec_minmax,
227+
.mode = 0666,
228+
.proc_handler = proc_ipc_dointvec_minmax_checkpoint_restore,
212229
.extra1 = SYSCTL_ZERO,
213230
.extra2 = SYSCTL_INT_MAX,
214231
},
215232
{
216233
.procname = "shm_next_id",
217234
.data = &init_ipc_ns.ids[IPC_SHM_IDS].next_id,
218235
.maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
219-
.mode = 0644,
220-
.proc_handler = proc_ipc_dointvec_minmax,
236+
.mode = 0666,
237+
.proc_handler = proc_ipc_dointvec_minmax_checkpoint_restore,
221238
.extra1 = SYSCTL_ZERO,
222239
.extra2 = SYSCTL_INT_MAX,
223240
},

0 commit comments

Comments
 (0)