Skip to content

Commit

Permalink
staging/lustre: fix build when CONFIG_UIDGID_STRICT_TYPE_CHECKS is on
Browse files Browse the repository at this point in the history
kuid_t/kgid_t are wrappered when CONFIG_UIDGID_STRICT_TYPE_CHECKS is on.
Lustre build is broken because we always treat them as plain __u32.
The patch fixes it. Internally, Lustre always use __u32 uid/gid, and
convert to kuid_t/kgid_t when necessary.

Signed-off-by: Peng Tao <tao.peng@emc.com>
  • Loading branch information
bergwolf committed Jul 9, 2013
1 parent 5f2c5ff commit fb8d38b
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 101 deletions.
2 changes: 0 additions & 2 deletions drivers/staging/lustre/include/linux/libcfs/curproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
* Implemented in portals/include/libcfs/<os>/
*/
int cfs_curproc_groups_nr(void);
int current_is_in_group(gid_t group);
void cfs_curproc_groups_dump(gid_t *array, int size);

/*
* Plus, platform-specific constant
Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/lustre/lustre/include/linux/lvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
/* simple.c */

struct lvfs_ucred {
__u32 luc_uid;
__u32 luc_gid;
__u32 luc_fsuid;
__u32 luc_fsgid;
kuid_t luc_uid;
kgid_t luc_gid;
kuid_t luc_fsuid;
kgid_t luc_fsgid;
kernel_cap_t luc_cap;
__u32 luc_umask;
struct group_info *luc_ginfo;
Expand Down
4 changes: 0 additions & 4 deletions drivers/staging/lustre/lustre/include/lustre_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ static inline int lustre_cfg_sanity_check(void *buf, int len)

#include <lustre/lustre_user.h>

#ifndef INVALID_UID
#define INVALID_UID (-1)
#endif

/** @} cfg */

#endif // _LUSTRE_CFG_H
16 changes: 0 additions & 16 deletions drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ int cfs_curproc_groups_nr(void)
return nr;
}

void cfs_curproc_groups_dump(gid_t *array, int size)
{
task_lock(current);
size = min_t(int, size, current_cred()->group_info->ngroups);
memcpy(array, current_cred()->group_info->blocks[0], size * sizeof(__u32));
task_unlock(current);
}


int current_is_in_group(gid_t gid)
{
return in_group_p(gid);
}

/* Currently all the CFS_CAP_* defines match CAP_* ones. */
#define cfs_cap_pack(cap) (cap)
#define cfs_cap_unpack(cap) (cap)
Expand Down Expand Up @@ -318,8 +304,6 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
EXPORT_SYMBOL(cfs_get_environ);

EXPORT_SYMBOL(cfs_curproc_groups_nr);
EXPORT_SYMBOL(cfs_curproc_groups_dump);
EXPORT_SYMBOL(current_is_in_group);
EXPORT_SYMBOL(cfs_cap_raise);
EXPORT_SYMBOL(cfs_cap_lower);
EXPORT_SYMBOL(cfs_cap_raised);
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/lustre/lustre/libcfs/linux/linux-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static long libcfs_ioctl(struct file *file,
struct cfs_psdev_file pfile;
int rc = 0;

if (current_fsuid() != 0)
if (!capable(CAP_SYS_ADMIN))
return -EACCES;

if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
Expand Down
9 changes: 6 additions & 3 deletions drivers/staging/lustre/lustre/llite/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,

op_data->op_cli_flags |= CLI_SET_MEA;
err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
current_fsuid(), current_fsgid(),
from_kuid(&init_user_ns, current_fsuid()),
from_kgid(&init_user_ns, current_fsgid()),
cfs_curproc_cap_pack(), 0, &request);
ll_finish_md_op_data(op_data);
if (err)
Expand Down Expand Up @@ -1105,8 +1106,10 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
RETURN(-EPERM);
break;
case Q_GETQUOTA:
if (((type == USRQUOTA && current_euid() != id) ||
(type == GRPQUOTA && !in_egroup_p(id))) &&
if (((type == USRQUOTA &&
uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
(type == GRPQUOTA &&
!in_egroup_p(make_kgid(&init_user_ns, id)))) &&
(!cfs_capable(CFS_CAP_SYS_ADMIN) ||
sbi->ll_flags & LL_SBI_RMT_CLIENT))
RETURN(-EPERM);
Expand Down
13 changes: 7 additions & 6 deletions drivers/staging/lustre/lustre/llite/llite_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr)

/* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
if (attr->ia_valid & TIMES_SET_FLAGS) {
if (current_fsuid() != inode->i_uid &&
if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
!cfs_capable(CFS_CAP_FOWNER))
RETURN(-EPERM);
}
Expand Down Expand Up @@ -1707,9 +1707,9 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
inode->i_blkbits = inode->i_sb->s_blocksize_bits;
}
if (body->valid & OBD_MD_FLUID)
inode->i_uid = body->uid;
inode->i_uid = make_kuid(&init_user_ns, body->uid);
if (body->valid & OBD_MD_FLGID)
inode->i_gid = body->gid;
inode->i_gid = make_kgid(&init_user_ns, body->gid);
if (body->valid & OBD_MD_FLFLAGS)
inode->i_flags = ll_ext_to_inode_flags(body->flags);
if (body->valid & OBD_MD_FLNLINK)
Expand Down Expand Up @@ -1959,7 +1959,8 @@ int ll_flush_ctx(struct inode *inode)
{
struct ll_sb_info *sbi = ll_i2sbi(inode);

CDEBUG(D_SEC, "flush context for user %d\n", current_uid());
CDEBUG(D_SEC, "flush context for user %d\n",
from_kuid(&init_user_ns, current_uid()));

obd_set_info_async(NULL, sbi->ll_md_exp,
sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
Expand Down Expand Up @@ -2238,8 +2239,8 @@ struct md_op_data * ll_prep_md_op_data(struct md_op_data *op_data,
op_data->op_namelen = namelen;
op_data->op_mode = mode;
op_data->op_mod_time = cfs_time_current_sec();
op_data->op_fsuid = current_fsuid();
op_data->op_fsgid = current_fsgid();
op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
op_data->op_cap = cfs_curproc_cap_pack();
op_data->op_bias = 0;
op_data->op_cli_flags = 0;
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/lustre/lustre/llite/lproc_llite.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
sbi->ll_stats_track_id == current->parent->pid)
lprocfs_counter_add(sbi->ll_stats, op, count);
else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
sbi->ll_stats_track_id == current_gid())
sbi->ll_stats_track_id ==
from_kgid(&init_user_ns, current_gid()))
lprocfs_counter_add(sbi->ll_stats, op, count);
}
EXPORT_SYMBOL(ll_stats_ops_tally);
Expand Down
7 changes: 4 additions & 3 deletions drivers/staging/lustre/lustre/llite/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,

__u32 ll_i2suppgid(struct inode *i)
{
if (current_is_in_group(i->i_gid))
return (__u32)i->i_gid;
if (in_group_p(i->i_gid))
return (__u32)from_kgid(&init_user_ns, i->i_gid);
else
return (__u32)(-1);
}
Expand Down Expand Up @@ -805,7 +805,8 @@ static int ll_new_node(struct inode *dir, struct qstr *name,
GOTO(err_exit, err = PTR_ERR(op_data));

err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
current_fsuid(), current_fsgid(),
from_kuid(&init_user_ns, current_fsuid()),
from_kgid(&init_user_ns, current_fsgid()),
cfs_curproc_cap_pack(), rdev, &request);
ll_finish_md_op_data(op_data);
if (err)
Expand Down
11 changes: 6 additions & 5 deletions drivers/staging/lustre/lustre/llite/remote_perm.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ static int do_check_remote_perm(struct ll_inode_info *lli, int mask)
if (!lli->lli_remote_perms)
RETURN(-ENOENT);

head = lli->lli_remote_perms + remote_perm_hashfunc(current_uid());
head = lli->lli_remote_perms +
remote_perm_hashfunc(from_kuid(&init_user_ns, current_uid()));

spin_lock(&lli->lli_lock);
hlist_for_each_entry(lrp, head, lrp_list) {
if (lrp->lrp_uid != current_uid())
if (lrp->lrp_uid != from_kuid(&init_user_ns, current_uid()))
continue;
if (lrp->lrp_gid != current_gid())
if (lrp->lrp_gid != from_kgid(&init_user_ns, current_gid()))
continue;
if (lrp->lrp_fsuid != current_fsuid())
if (lrp->lrp_fsuid != from_kuid(&init_user_ns, current_fsuid()))
continue;
if (lrp->lrp_fsgid != current_fsgid())
if (lrp->lrp_fsgid != from_kgid(&init_user_ns, current_fsgid()))
continue;
found = 1;
break;
Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/lustre/lustre/llite/vvp_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static int vvp_attr_get(const struct lu_env *env, struct cl_object *obj,
attr->cat_atime = LTIME_S(inode->i_atime);
attr->cat_ctime = LTIME_S(inode->i_ctime);
attr->cat_blocks = inode->i_blocks;
attr->cat_uid = inode->i_uid;
attr->cat_gid = inode->i_gid;
attr->cat_uid = from_kuid(&init_user_ns, inode->i_uid);
attr->cat_gid = from_kgid(&init_user_ns, inode->i_gid);
/* KMS is not known by this layer */
return 0; /* layers below have to fill in the rest */
}
Expand All @@ -103,9 +103,9 @@ static int vvp_attr_set(const struct lu_env *env, struct cl_object *obj,
struct inode *inode = ccc_object_inode(obj);

if (valid & CAT_UID)
inode->i_uid = attr->cat_uid;
inode->i_uid = make_kuid(&init_user_ns, attr->cat_uid);
if (valid & CAT_GID)
inode->i_gid = attr->cat_gid;
inode->i_gid = make_kgid(&init_user_ns, attr->cat_gid);
if (valid & CAT_ATIME)
LTIME_S(inode->i_atime) = attr->cat_atime;
if (valid & CAT_MTIME)
Expand Down
12 changes: 6 additions & 6 deletions drivers/staging/lustre/lustre/lmv/lmv_obd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1757,8 +1757,8 @@ static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
PFID(&op_data->op_fid2), op_data->op_namelen,
op_data->op_name, PFID(&op_data->op_fid1));

op_data->op_fsuid = current_fsuid();
op_data->op_fsgid = current_fsgid();
op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
op_data->op_cap = cfs_curproc_cap_pack();
tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
if (IS_ERR(tgt))
Expand Down Expand Up @@ -1799,8 +1799,8 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
if (rc)
RETURN(rc);

op_data->op_fsuid = current_fsuid();
op_data->op_fsgid = current_fsgid();
op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
op_data->op_cap = cfs_curproc_cap_pack();
src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
if (IS_ERR(src_tgt))
Expand Down Expand Up @@ -2061,8 +2061,8 @@ static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
if (IS_ERR(tgt))
RETURN(PTR_ERR(tgt));

op_data->op_fsuid = current_fsuid();
op_data->op_fsgid = current_fsgid();
op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
op_data->op_cap = cfs_curproc_cap_pack();

/*
Expand Down
25 changes: 13 additions & 12 deletions drivers/staging/lustre/lustre/mdc/mdc_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ static void __mdc_pack_body(struct mdt_body *b, __u32 suppgid)
LASSERT (b != NULL);

b->suppgid = suppgid;
b->uid = current_uid();
b->gid = current_gid();
b->fsuid = current_fsuid();
b->fsgid = current_fsgid();
b->uid = from_kuid(&init_user_ns, current_uid());
b->gid = from_kgid(&init_user_ns, current_gid());
b->fsuid = from_kuid(&init_user_ns, current_fsuid());
b->fsgid = from_kgid(&init_user_ns, current_fsgid());
b->capability = cfs_curproc_cap_pack();
}

Expand Down Expand Up @@ -219,8 +219,8 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data,

/* XXX do something about time, uid, gid */
rec->cr_opcode = REINT_OPEN;
rec->cr_fsuid = current_fsuid();
rec->cr_fsgid = current_fsgid();
rec->cr_fsuid = from_kuid(&init_user_ns, current_fsuid());
rec->cr_fsgid = from_kgid(&init_user_ns, current_fsgid());
rec->cr_cap = cfs_curproc_cap_pack();
if (op_data != NULL) {
rec->cr_fid1 = op_data->op_fid1;
Expand Down Expand Up @@ -299,25 +299,26 @@ static void mdc_setattr_pack_rec(struct mdt_rec_setattr *rec,
struct md_op_data *op_data)
{
rec->sa_opcode = REINT_SETATTR;
rec->sa_fsuid = current_fsuid();
rec->sa_fsgid = current_fsgid();
rec->sa_fsuid = from_kuid(&init_user_ns, current_fsuid());
rec->sa_fsgid = from_kgid(&init_user_ns, current_fsgid());
rec->sa_cap = cfs_curproc_cap_pack();
rec->sa_suppgid = -1;

rec->sa_fid = op_data->op_fid1;
rec->sa_valid = attr_pack(op_data->op_attr.ia_valid);
rec->sa_mode = op_data->op_attr.ia_mode;
rec->sa_uid = op_data->op_attr.ia_uid;
rec->sa_gid = op_data->op_attr.ia_gid;
rec->sa_uid = from_kuid(&init_user_ns, op_data->op_attr.ia_uid);
rec->sa_gid = from_kgid(&init_user_ns, op_data->op_attr.ia_gid);
rec->sa_size = op_data->op_attr.ia_size;
rec->sa_blocks = op_data->op_attr_blocks;
rec->sa_atime = LTIME_S(op_data->op_attr.ia_atime);
rec->sa_mtime = LTIME_S(op_data->op_attr.ia_mtime);
rec->sa_ctime = LTIME_S(op_data->op_attr.ia_ctime);
rec->sa_attr_flags = ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
if ((op_data->op_attr.ia_valid & ATTR_GID) &&
current_is_in_group(op_data->op_attr.ia_gid))
rec->sa_suppgid = op_data->op_attr.ia_gid;
in_group_p(op_data->op_attr.ia_gid))
rec->sa_suppgid =
from_kgid(&init_user_ns, op_data->op_attr.ia_gid);
else
rec->sa_suppgid = op_data->op_suppgids[0];

Expand Down
8 changes: 2 additions & 6 deletions drivers/staging/lustre/lustre/mdc/mdc_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,8 @@ static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
sizeof(struct mdt_rec_reint));
rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
rec->sx_opcode = REINT_SETXATTR;
/* TODO:
* cfs_curproc_fs{u,g}id() should replace
* current->fs{u,g}id for portability.
*/
rec->sx_fsuid = current_fsuid();
rec->sx_fsgid = current_fsgid();
rec->sx_fsuid = from_kuid(&init_user_ns, current_fsuid());
rec->sx_fsgid = from_kgid(&init_user_ns, current_fsgid());
rec->sx_cap = cfs_curproc_cap_pack();
rec->sx_suppgid1 = suppgid;
rec->sx_suppgid2 = -1;
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/lustre/lustre/obdclass/class_obd.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ int lustre_get_jobid(char *jobid)
/* Use process name + fsuid as jobid */
if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) {
snprintf(jobid, JOBSTATS_JOBID_SIZE, "%s.%u",
current_comm(), current_fsuid());
current_comm(),
from_kuid(&init_user_ns, current_fsuid()));
RETURN(0);
}

Expand Down
12 changes: 8 additions & 4 deletions drivers/staging/lustre/lustre/obdclass/idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ static int lustre_groups_search(group_info_t *group_info,
right = group_info->ngroups;
while (left < right) {
int mid = (left + right) / 2;
int cmp = grp - CFS_GROUP_AT(group_info, mid);
int cmp = grp -
from_kgid(&init_user_ns, CFS_GROUP_AT(group_info, mid));

if (cmp > 0)
left = mid + 1;
Expand Down Expand Up @@ -116,16 +117,19 @@ void lustre_groups_sort(group_info_t *group_info)
for (base = 0; base < max; base++) {
int left = base;
int right = left + stride;
gid_t tmp = CFS_GROUP_AT(group_info, right);
gid_t tmp = from_kgid(&init_user_ns,
CFS_GROUP_AT(group_info, right));

while (left >= 0 &&
CFS_GROUP_AT(group_info, left) > tmp) {
tmp < from_kgid(&init_user_ns,
CFS_GROUP_AT(group_info, left))) {
CFS_GROUP_AT(group_info, right) =
CFS_GROUP_AT(group_info, left);
right = left;
left -= stride;
}
CFS_GROUP_AT(group_info, right) = tmp;
CFS_GROUP_AT(group_info, right) =
make_kgid(&init_user_ns, tmp);
}
stride /= 3;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
if (valid & OBD_MD_FLMODE)
dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
if (valid & OBD_MD_FLUID)
dst->i_uid = src->o_uid;
dst->i_uid = make_kuid(&init_user_ns, src->o_uid);
if (valid & OBD_MD_FLGID)
dst->i_gid = src->o_gid;
dst->i_gid = make_kgid(&init_user_ns, src->o_gid);
if (valid & OBD_MD_FLFLAGS)
dst->i_flags = src->o_flags;
}
Expand Down
Loading

0 comments on commit fb8d38b

Please sign in to comment.