Skip to content

Commit 9470451

Browse files
author
Miklos Szeredi
committed
vfs: split out access_override_creds()
Split out a helper that overrides the credentials in preparation for actually doing the access check. This prepares for the next patch that optionally disables the creds override. Suggested-by: Christoph Hellwig <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 9f6c61f commit 9470451

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

fs/open.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,21 +345,14 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
345345
* We do this by temporarily clearing all FS-related capabilities and
346346
* switching the fsuid/fsgid around to the real ones.
347347
*/
348-
long do_faccessat(int dfd, const char __user *filename, int mode)
348+
static const struct cred *access_override_creds(void)
349349
{
350350
const struct cred *old_cred;
351351
struct cred *override_cred;
352-
struct path path;
353-
struct inode *inode;
354-
int res;
355-
unsigned int lookup_flags = LOOKUP_FOLLOW;
356-
357-
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
358-
return -EINVAL;
359352

360353
override_cred = prepare_creds();
361354
if (!override_cred)
362-
return -ENOMEM;
355+
return NULL;
363356

364357
override_cred->fsuid = override_cred->uid;
365358
override_cred->fsgid = override_cred->gid;
@@ -394,6 +387,28 @@ long do_faccessat(int dfd, const char __user *filename, int mode)
394387
override_cred->non_rcu = 1;
395388

396389
old_cred = override_creds(override_cred);
390+
391+
/* override_cred() gets its own ref */
392+
put_cred(override_cred);
393+
394+
return old_cred;
395+
}
396+
397+
long do_faccessat(int dfd, const char __user *filename, int mode)
398+
{
399+
struct path path;
400+
struct inode *inode;
401+
int res;
402+
unsigned int lookup_flags = LOOKUP_FOLLOW;
403+
const struct cred *old_cred;
404+
405+
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
406+
return -EINVAL;
407+
408+
old_cred = access_override_creds();
409+
if (!old_cred)
410+
return -ENOMEM;
411+
397412
retry:
398413
res = user_path_at(dfd, filename, lookup_flags, &path);
399414
if (res)
@@ -436,7 +451,6 @@ long do_faccessat(int dfd, const char __user *filename, int mode)
436451
}
437452
out:
438453
revert_creds(old_cred);
439-
put_cred(override_cred);
440454
return res;
441455
}
442456

0 commit comments

Comments
 (0)