From b11fba5fc4561ba2980330ce320adf18fae2eb62 Mon Sep 17 00:00:00 2001 From: anserper Date: Fri, 22 May 2009 20:20:53 +0000 Subject: [PATCH] b=19612 i=Johann Lombardi i=ZhiYong Tian additional parameter checking for lfs quota and lustre ioctls --- lustre/quota/quota_master.c | 36 ++++++++++++++++++++++++++++++++++++ lustre/tests/sanity-quota.sh | 9 ++++++++- lustre/utils/lfs.c | 11 +++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c index 08d0a58..4bdf41c 100644 --- a/lustre/quota/quota_master.c +++ b/lustre/quota/quota_master.c @@ -614,6 +614,11 @@ int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl) char name[64]; struct lvfs_run_ctxt saved; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + return -EINVAL; + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); @@ -659,6 +664,11 @@ int mds_quota_finvalidate(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; struct lvfs_run_ctxt saved; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); @@ -890,6 +900,11 @@ int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + if (!atomic_dec_and_test(&obt->obt_quotachecking)) { CDEBUG(D_INFO, "other people are doing quotacheck\n"); atomic_inc(&obt->obt_quotachecking); @@ -925,6 +940,11 @@ int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl) int rc, rc2; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + if (!atomic_dec_and_test(&obt->obt_quotachecking)) { CDEBUG(D_INFO, "other people are doing quotacheck\n"); atomic_inc(&obt->obt_quotachecking); @@ -956,6 +976,10 @@ int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); if (qinfo->qi_files[oqctl->qc_type] == NULL) { rc = -ESRCH; @@ -981,6 +1005,10 @@ int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl) int rc = 0; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); if (qinfo->qi_files[oqctl->qc_type] == NULL) { rc = -ESRCH; @@ -1266,6 +1294,10 @@ int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl) int rc, rc2 = 0, flag = 0; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + OBD_ALLOC_PTR(oqaq); if (!oqaq) RETURN(-ENOMEM); @@ -1460,6 +1492,10 @@ int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); dqblk->dqb_valid = 0; if (qinfo->qi_files[oqctl->qc_type] == NULL) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index c9c9492..b4cbcde 100644 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -69,7 +69,7 @@ OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd` SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR" SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR" -SHOW_QUOTA_INFO="$LFS quota -t $DIR" +SHOW_QUOTA_INFO="$LFS quota -t -u $DIR; $LFS quota -t -g $DIR" # control the time of tests cycle=30 @@ -1824,6 +1824,13 @@ test_24() { } run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ===========" +test_27() { + $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed" + $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed" + return 0 +} +run_test_with_stat 27 "lfs quota/setquota should handle wrong arguments (19612) =================" + # turn off quota test_99() { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index bf2fb8b..5f061bb 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1721,6 +1721,11 @@ int lfs_setquota_times(int argc, char **argv) return CMD_HELP; } + if (limit_mask == 0) { + fprintf(stderr, "error: at least one limit must be specified\n"); + return CMD_HELP; + } + if (optind != argc - 1) { fprintf(stderr, "error: unexpected parameters encountered\n"); return CMD_HELP; @@ -2194,8 +2199,10 @@ ug_output: (qctl.qc_type == USRQUOTA) ? USER : GROUP); if (rc) name = ""; + /* lfs quota -u username /path/to/lustre/mount */ } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) { - if (optind + 2 != argc) { + /* options should be followed by u/g-name and mntpoint */ + if (optind + 2 != argc || qctl.qc_type == UGQUOTA) { fprintf(stderr, "error: missing quota argument(s)\n"); return CMD_HELP; } @@ -2208,7 +2215,7 @@ ug_output: name, strerror(errno)); return CMD_HELP; } - } else if (optind + 1 != argc) { + } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) { fprintf(stderr, "error: missing quota info argument(s)\n"); return CMD_HELP; } -- 1.8.3.1