Skip to content

Commit 28edfba

Browse files
braunergregkh
authored andcommitted
pidfs: check for valid ioctl commands
commit 8ce3528 upstream. Prior to doing any work, check whether the provided ioctl command is supported by pidfs. Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 853d2e0 commit 28edfba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

fs/pidfs.c

+24
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ static long pidfd_info(struct task_struct *task, unsigned int cmd, unsigned long
190190
return 0;
191191
}
192192

193+
static bool pidfs_ioctl_valid(unsigned int cmd)
194+
{
195+
switch (cmd) {
196+
case FS_IOC_GETVERSION:
197+
case PIDFD_GET_CGROUP_NAMESPACE:
198+
case PIDFD_GET_INFO:
199+
case PIDFD_GET_IPC_NAMESPACE:
200+
case PIDFD_GET_MNT_NAMESPACE:
201+
case PIDFD_GET_NET_NAMESPACE:
202+
case PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE:
203+
case PIDFD_GET_TIME_NAMESPACE:
204+
case PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE:
205+
case PIDFD_GET_UTS_NAMESPACE:
206+
case PIDFD_GET_USER_NAMESPACE:
207+
case PIDFD_GET_PID_NAMESPACE:
208+
return true;
209+
}
210+
211+
return false;
212+
}
213+
193214
static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
194215
{
195216
struct task_struct *task __free(put_task) = NULL;
@@ -198,6 +219,9 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
198219
struct ns_common *ns_common = NULL;
199220
struct pid_namespace *pid_ns;
200221

222+
if (!pidfs_ioctl_valid(cmd))
223+
return -ENOIOCTLCMD;
224+
201225
task = get_pid_task(pid, PIDTYPE_PID);
202226
if (!task)
203227
return -ESRCH;

0 commit comments

Comments
 (0)