Skip to content

Commit

Permalink
userns: Convert qutoactl
Browse files Browse the repository at this point in the history
Update the quotactl user space interface to successfull compile with
user namespaces support enabled and to hand off quota identifiers to
lower layers of the kernel in struct kqid instead of type and qid
pairs.

The quota on function is not converted because while it takes a quota
type and an id.  The id is the on disk quota format to use, which
is something completely different.

The signature of two struct quotactl_ops methods were changed to take
struct kqid argumetns get_dqblk and set_dqblk.

The dquot, xfs, and ocfs2 implementations of get_dqblk and set_dqblk
are minimally changed so that the code continues to work with
the change in parameter type.

This is the first in a series of changes to always store quota
identifiers in the kernel in struct kqid and only use raw type and qid
values when interacting with on disk structures or userspace.  Always
using struct kqid internally makes it hard to miss places that need
conversion to or from the kernel internal values.

Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Ben Myers <bpm@sgi.com>
Cc: Alex Elder <elder@kernel.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
  • Loading branch information
Eric W. Biederman committed Sep 18, 2012
1 parent e8a3e47 commit 74a8a10
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 30 deletions.
20 changes: 11 additions & 9 deletions fs/gfs2/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,28 +1469,29 @@ static int gfs2_quota_get_xstate(struct super_block *sb,
return 0;
}

static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id,
static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid,
struct fs_disk_quota *fdq)
{
struct gfs2_sbd *sdp = sb->s_fs_info;
struct gfs2_quota_lvb *qlvb;
struct gfs2_quota_data *qd;
struct gfs2_holder q_gh;
int error;
int type;

memset(fdq, 0, sizeof(struct fs_disk_quota));

if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
return -ESRCH; /* Crazy XFS error code */

if (type == USRQUOTA)
if (qid.type == USRQUOTA)
type = QUOTA_USER;
else if (type == GRPQUOTA)
else if (qid.type == GRPQUOTA)
type = QUOTA_GROUP;
else
return -EINVAL;

error = qd_get(sdp, type, id, &qd);
error = qd_get(sdp, type, from_kqid(&init_user_ns, qid), &qd);
if (error)
return error;
error = do_glock(qd, FORCE, &q_gh);
Expand All @@ -1500,7 +1501,7 @@ static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id,
qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
fdq->d_version = FS_DQUOT_VERSION;
fdq->d_flags = (type == QUOTA_USER) ? FS_USER_QUOTA : FS_GROUP_QUOTA;
fdq->d_id = id;
fdq->d_id = from_kqid(&init_user_ns, qid);
fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift;
fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift;
fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift;
Expand All @@ -1514,7 +1515,7 @@ static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id,
/* GFS2 only supports a subset of the XFS fields */
#define GFS2_FIELDMASK (FS_DQ_BSOFT|FS_DQ_BHARD|FS_DQ_BCOUNT)

static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid,
struct fs_disk_quota *fdq)
{
struct gfs2_sbd *sdp = sb->s_fs_info;
Expand All @@ -1526,11 +1527,12 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
int alloc_required;
loff_t offset;
int error;
int type;

if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
return -ESRCH; /* Crazy XFS error code */

switch(type) {
switch(qid.type) {
case USRQUOTA:
type = QUOTA_USER;
if (fdq->d_flags != FS_USER_QUOTA)
Expand All @@ -1547,10 +1549,10 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,

if (fdq->d_fieldmask & ~GFS2_FIELDMASK)
return -EINVAL;
if (fdq->d_id != id)
if (fdq->d_id != from_kqid(&init_user_ns, qid))
return -EINVAL;

error = qd_get(sdp, type, id, &qd);
error = qd_get(sdp, type, from_kqid(&init_user_ns, qid), &qd);
if (error)
return error;

Expand Down
8 changes: 4 additions & 4 deletions fs/quota/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2376,12 +2376,12 @@ static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
spin_unlock(&dq_data_lock);
}

int dquot_get_dqblk(struct super_block *sb, int type, qid_t id,
int dquot_get_dqblk(struct super_block *sb, struct kqid qid,
struct fs_disk_quota *di)
{
struct dquot *dquot;

dquot = dqget(sb, id, type);
dquot = dqget(sb, qid.type, from_kqid(&init_user_ns, qid));
if (!dquot)
return -ESRCH;
do_get_dqblk(dquot, di);
Expand Down Expand Up @@ -2488,13 +2488,13 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
return 0;
}

int dquot_set_dqblk(struct super_block *sb, int type, qid_t id,
int dquot_set_dqblk(struct super_block *sb, struct kqid qid,
struct fs_disk_quota *di)
{
struct dquot *dquot;
int rc;

dquot = dqget(sb, id, type);
dquot = dqget(sb, qid.type, from_kqid(&init_user_ns, qid));
if (!dquot) {
rc = -ESRCH;
goto out;
Expand Down
28 changes: 22 additions & 6 deletions fs/quota/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
/* allow to query information for dquots we "own" */
case Q_GETQUOTA:
case Q_XGETQUOTA:
if ((type == USRQUOTA && current_euid() == id) ||
(type == GRPQUOTA && in_egroup_p(id)))
if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) ||
(type == GRPQUOTA && in_egroup_p(make_kgid(current_user_ns(), id))))
break;
/*FALLTHROUGH*/
default:
Expand Down Expand Up @@ -130,13 +130,17 @@ static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src)
static int quota_getquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct kqid qid;
struct fs_disk_quota fdq;
struct if_dqblk idq;
int ret;

if (!sb->s_qcop->get_dqblk)
return -ENOSYS;
ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq);
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
ret = sb->s_qcop->get_dqblk(sb, qid, &fdq);
if (ret)
return ret;
copy_to_if_dqblk(&idq, &fdq);
Expand Down Expand Up @@ -176,13 +180,17 @@ static int quota_setquota(struct super_block *sb, int type, qid_t id,
{
struct fs_disk_quota fdq;
struct if_dqblk idq;
struct kqid qid;

if (copy_from_user(&idq, addr, sizeof(idq)))
return -EFAULT;
if (!sb->s_qcop->set_dqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
copy_from_if_dqblk(&fdq, &idq);
return sb->s_qcop->set_dqblk(sb, type, id, &fdq);
return sb->s_qcop->set_dqblk(sb, qid, &fdq);
}

static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr)
Expand Down Expand Up @@ -213,23 +221,31 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct fs_disk_quota fdq;
struct kqid qid;

if (copy_from_user(&fdq, addr, sizeof(fdq)))
return -EFAULT;
if (!sb->s_qcop->set_dqblk)
return -ENOSYS;
return sb->s_qcop->set_dqblk(sb, type, id, &fdq);
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
return sb->s_qcop->set_dqblk(sb, qid, &fdq);
}

static int quota_getxquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct fs_disk_quota fdq;
struct kqid qid;
int ret;

if (!sb->s_qcop->get_dqblk)
return -ENOSYS;
ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq);
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
ret = sb->s_qcop->get_dqblk(sb, qid, &fdq);
if (!ret && copy_to_user(addr, &fdq, sizeof(fdq)))
return -EFAULT;
return ret;
Expand Down
12 changes: 6 additions & 6 deletions fs/xfs/xfs_quotaops.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ xfs_fs_set_xstate(
STATIC int
xfs_fs_get_dqblk(
struct super_block *sb,
int type,
qid_t id,
struct kqid qid,
struct fs_disk_quota *fdq)
{
struct xfs_mount *mp = XFS_M(sb);
Expand All @@ -108,14 +107,14 @@ xfs_fs_get_dqblk(
if (!XFS_IS_QUOTA_ON(mp))
return -ESRCH;

return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
xfs_quota_type(qid.type), fdq);
}

STATIC int
xfs_fs_set_dqblk(
struct super_block *sb,
int type,
qid_t id,
struct kqid qid,
struct fs_disk_quota *fdq)
{
struct xfs_mount *mp = XFS_M(sb);
Expand All @@ -127,7 +126,8 @@ xfs_fs_set_dqblk(
if (!XFS_IS_QUOTA_ON(mp))
return -ESRCH;

return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
xfs_quota_type(qid.type), fdq);
}

const struct quotactl_ops xfs_quotactl_operations = {
Expand Down
4 changes: 2 additions & 2 deletions include/linux/quota.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ struct quotactl_ops {
int (*quota_sync)(struct super_block *, int);
int (*get_info)(struct super_block *, int, struct if_dqinfo *);
int (*set_info)(struct super_block *, int, struct if_dqinfo *);
int (*get_dqblk)(struct super_block *, int, qid_t, struct fs_disk_quota *);
int (*set_dqblk)(struct super_block *, int, qid_t, struct fs_disk_quota *);
int (*get_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
int (*set_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
int (*set_xstate)(struct super_block *, unsigned int, int);
};
Expand Down
4 changes: 2 additions & 2 deletions include/linux/quotaops.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int dquot_writeback_dquots(struct super_block *sb, int type);
int dquot_quota_sync(struct super_block *sb, int type);
int dquot_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
int dquot_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
int dquot_get_dqblk(struct super_block *sb, int type, qid_t id,
int dquot_get_dqblk(struct super_block *sb, struct kqid id,
struct fs_disk_quota *di);
int dquot_set_dqblk(struct super_block *sb, int type, qid_t id,
int dquot_set_dqblk(struct super_block *sb, struct kqid id,
struct fs_disk_quota *di);

int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
Expand Down
2 changes: 1 addition & 1 deletion init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ config UIDGID_CONVERTED
depends on IMA = n
depends on EVM = n
depends on QUOTA = n
depends on QUOTACTL = n
depends on QUOTA_NETLINK_INTERFACE = n

# Networking
depends on NET_9P = n
Expand Down

0 comments on commit 74a8a10

Please sign in to comment.