@@ -187,17 +187,6 @@ static int get_path_from_fd(int fd, struct path *root)
187
187
return 0 ;
188
188
}
189
189
190
- enum handle_to_path_flags {
191
- HANDLE_CHECK_PERMS = (1 << 0 ),
192
- HANDLE_CHECK_SUBTREE = (1 << 1 ),
193
- };
194
-
195
- struct handle_to_path_ctx {
196
- struct path root ;
197
- enum handle_to_path_flags flags ;
198
- unsigned int fh_flags ;
199
- };
200
-
201
190
static int vfs_dentry_acceptable (void * context , struct dentry * dentry )
202
191
{
203
192
struct handle_to_path_ctx * ctx = context ;
@@ -279,13 +268,13 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path,
279
268
return 0 ;
280
269
}
281
270
282
- static inline bool may_decode_fh (struct handle_to_path_ctx * ctx ,
283
- unsigned int o_flags )
271
+ static inline int may_decode_fh (struct handle_to_path_ctx * ctx ,
272
+ unsigned int o_flags )
284
273
{
285
274
struct path * root = & ctx -> root ;
286
275
287
276
if (capable (CAP_DAC_READ_SEARCH ))
288
- return true ;
277
+ return 0 ;
289
278
290
279
/*
291
280
* Allow relaxed permissions of file handles if the caller has
@@ -309,7 +298,7 @@ static inline bool may_decode_fh(struct handle_to_path_ctx *ctx,
309
298
* There's only one dentry for each directory inode (VFS rule)...
310
299
*/
311
300
if (!(o_flags & O_DIRECTORY ))
312
- return false ;
301
+ return - EPERM ;
313
302
314
303
if (ns_capable (root -> mnt -> mnt_sb -> s_user_ns , CAP_SYS_ADMIN ))
315
304
ctx -> flags = HANDLE_CHECK_PERMS ;
@@ -319,14 +308,14 @@ static inline bool may_decode_fh(struct handle_to_path_ctx *ctx,
319
308
!has_locked_children (real_mount (root -> mnt ), root -> dentry ))
320
309
ctx -> flags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE ;
321
310
else
322
- return false ;
311
+ return - EPERM ;
323
312
324
313
/* Are we able to override DAC permissions? */
325
314
if (!ns_capable (current_user_ns (), CAP_DAC_READ_SEARCH ))
326
- return false ;
315
+ return - EPERM ;
327
316
328
317
ctx -> fh_flags = EXPORT_FH_DIR_ONLY ;
329
- return true ;
318
+ return 0 ;
330
319
}
331
320
332
321
static int handle_to_path (int mountdirfd , struct file_handle __user * ufh ,
@@ -336,15 +325,19 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
336
325
struct file_handle f_handle ;
337
326
struct file_handle * handle = NULL ;
338
327
struct handle_to_path_ctx ctx = {};
328
+ const struct export_operations * eops ;
339
329
340
330
retval = get_path_from_fd (mountdirfd , & ctx .root );
341
331
if (retval )
342
332
goto out_err ;
343
333
344
- if (!may_decode_fh (& ctx , o_flags )) {
345
- retval = - EPERM ;
334
+ eops = ctx .root .mnt -> mnt_sb -> s_export_op ;
335
+ if (eops && eops -> permission )
336
+ retval = eops -> permission (& ctx , o_flags );
337
+ else
338
+ retval = may_decode_fh (& ctx , o_flags );
339
+ if (retval )
346
340
goto out_path ;
347
- }
348
341
349
342
if (copy_from_user (& f_handle , ufh , sizeof (struct file_handle ))) {
350
343
retval = - EFAULT ;
0 commit comments