File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
tools/testing/selftests/filesystems/nsfs Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -152,19 +152,49 @@ static int copy_ns_info_to_user(const struct mnt_namespace *mnt_ns,
152
152
return 0 ;
153
153
}
154
154
155
+ static bool nsfs_ioctl_valid (unsigned int cmd )
156
+ {
157
+ switch (cmd ) {
158
+ case NS_GET_USERNS :
159
+ case NS_GET_PARENT :
160
+ case NS_GET_NSTYPE :
161
+ case NS_GET_OWNER_UID :
162
+ case NS_GET_MNTNS_ID :
163
+ case NS_GET_PID_FROM_PIDNS :
164
+ case NS_GET_TGID_FROM_PIDNS :
165
+ case NS_GET_PID_IN_PIDNS :
166
+ case NS_GET_TGID_IN_PIDNS :
167
+ return (_IOC_TYPE (cmd ) == _IOC_TYPE (cmd ));
168
+ }
169
+
170
+ /* Extensible ioctls require some extra handling. */
171
+ switch (_IOC_NR (cmd )) {
172
+ case _IOC_NR (NS_MNT_GET_INFO ):
173
+ case _IOC_NR (NS_MNT_GET_NEXT ):
174
+ case _IOC_NR (NS_MNT_GET_PREV ):
175
+ return (_IOC_TYPE (cmd ) == _IOC_TYPE (cmd ));
176
+ }
177
+
178
+ return false;
179
+ }
180
+
155
181
static long ns_ioctl (struct file * filp , unsigned int ioctl ,
156
182
unsigned long arg )
157
183
{
158
184
struct user_namespace * user_ns ;
159
185
struct pid_namespace * pid_ns ;
160
186
struct task_struct * tsk ;
161
- struct ns_common * ns = get_proc_ns ( file_inode ( filp )) ;
187
+ struct ns_common * ns ;
162
188
struct mnt_namespace * mnt_ns ;
163
189
bool previous = false;
164
190
uid_t __user * argp ;
165
191
uid_t uid ;
166
192
int ret ;
167
193
194
+ if (!nsfs_ioctl_valid (ioctl ))
195
+ return - ENOIOCTLCMD ;
196
+
197
+ ns = get_proc_ns (file_inode (filp ));
168
198
switch (ioctl ) {
169
199
case NS_GET_USERNS :
170
200
return open_related_ns (ns , ns_get_owner );
Original file line number Diff line number Diff line change 3
3
4
4
#define _GNU_SOURCE
5
5
#include <fcntl.h>
6
+ #include <linux/auto_dev-ioctl.h>
7
+ #include <linux/errno.h>
6
8
#include <sched.h>
7
9
#include <stdio.h>
8
10
#include <string.h>
@@ -146,4 +148,16 @@ TEST_F(iterate_mount_namespaces, iterate_backward)
146
148
}
147
149
}
148
150
151
+ TEST_F (iterate_mount_namespaces , nfs_valid_ioctl )
152
+ {
153
+ ASSERT_NE (ioctl (self -> fd_mnt_ns [0 ], AUTOFS_DEV_IOCTL_OPENMOUNT , NULL ), 0 );
154
+ ASSERT_EQ (errno , ENOTTY );
155
+
156
+ ASSERT_NE (ioctl (self -> fd_mnt_ns [0 ], AUTOFS_DEV_IOCTL_CLOSEMOUNT , NULL ), 0 );
157
+ ASSERT_EQ (errno , ENOTTY );
158
+
159
+ ASSERT_NE (ioctl (self -> fd_mnt_ns [0 ], AUTOFS_DEV_IOCTL_READY , NULL ), 0 );
160
+ ASSERT_EQ (errno , ENOTTY );
161
+ }
162
+
149
163
TEST_HARNESS_MAIN
You can’t perform that action at this time.
0 commit comments