aboutsummaryrefslogtreecommitdiffstats
path: root/fs/open.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/fs/open.c b/fs/open.c
index 92335f663545..e16680138323 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -506,15 +506,24 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
506 struct inode *inode = path->dentry->d_inode; 506 struct inode *inode = path->dentry->d_inode;
507 int error; 507 int error;
508 struct iattr newattrs; 508 struct iattr newattrs;
509 kuid_t uid;
510 kgid_t gid;
511
512 uid = make_kuid(current_user_ns(), user);
513 gid = make_kgid(current_user_ns(), group);
509 514
510 newattrs.ia_valid = ATTR_CTIME; 515 newattrs.ia_valid = ATTR_CTIME;
511 if (user != (uid_t) -1) { 516 if (user != (uid_t) -1) {
517 if (!uid_valid(uid))
518 return -EINVAL;
512 newattrs.ia_valid |= ATTR_UID; 519 newattrs.ia_valid |= ATTR_UID;
513 newattrs.ia_uid = user; 520 newattrs.ia_uid = uid;
514 } 521 }
515 if (group != (gid_t) -1) { 522 if (group != (gid_t) -1) {
523 if (!gid_valid(gid))
524 return -EINVAL;
516 newattrs.ia_valid |= ATTR_GID; 525 newattrs.ia_valid |= ATTR_GID;
517 newattrs.ia_gid = group; 526 newattrs.ia_gid = gid;
518 } 527 }
519 if (!S_ISDIR(inode->i_mode)) 528 if (!S_ISDIR(inode->i_mode))
520 newattrs.ia_valid |= 529 newattrs.ia_valid |=