Skip to content

Commit 8ce3528

Browse files
committed
pidfs: check for valid ioctl commands
Prior to doing any work, check whether the provided ioctl command is supported by pidfs. Signed-off-by: Christian Brauner <[email protected]>
1 parent dc14abd commit 8ce3528

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: fs/pidfs.c

+24
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,27 @@ static long pidfd_info(struct task_struct *task, unsigned int cmd, unsigned long
264264
return 0;
265265
}
266266

267+
static bool pidfs_ioctl_valid(unsigned int cmd)
268+
{
269+
switch (cmd) {
270+
case FS_IOC_GETVERSION:
271+
case PIDFD_GET_CGROUP_NAMESPACE:
272+
case PIDFD_GET_INFO:
273+
case PIDFD_GET_IPC_NAMESPACE:
274+
case PIDFD_GET_MNT_NAMESPACE:
275+
case PIDFD_GET_NET_NAMESPACE:
276+
case PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE:
277+
case PIDFD_GET_TIME_NAMESPACE:
278+
case PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE:
279+
case PIDFD_GET_UTS_NAMESPACE:
280+
case PIDFD_GET_USER_NAMESPACE:
281+
case PIDFD_GET_PID_NAMESPACE:
282+
return true;
283+
}
284+
285+
return false;
286+
}
287+
267288
static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
268289
{
269290
struct task_struct *task __free(put_task) = NULL;
@@ -272,6 +293,9 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
272293
struct ns_common *ns_common = NULL;
273294
struct pid_namespace *pid_ns;
274295

296+
if (!pidfs_ioctl_valid(cmd))
297+
return -ENOIOCTLCMD;
298+
275299
if (cmd == FS_IOC_GETVERSION) {
276300
if (!arg)
277301
return -EINVAL;

0 commit comments

Comments
 (0)