From 5897c80c6be9981b7018f953b6a5aff25f1be3e1 Mon Sep 17 00:00:00 2001 From: anserper Date: Fri, 22 May 2009 19:26:55 +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 b142426..263c701 100644 --- a/lustre/quota/quota_master.c +++ b/lustre/quota/quota_master.c @@ -609,6 +609,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); @@ -654,6 +659,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); @@ -885,6 +895,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); @@ -920,6 +935,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); @@ -951,6 +971,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; @@ -976,6 +1000,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; @@ -1290,6 +1318,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); @@ -1484,6 +1516,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 590bfa5..f210515 100644 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -71,7 +71,7 @@ SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR" SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR" SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR" SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $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 @@ -2096,6 +2096,13 @@ test_26() { } run_test_with_stat 26 "test for false quota error(bz18491) ======================================" +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 0bcc4f7..370b0d1 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1723,6 +1723,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; @@ -2196,8 +2201,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; } @@ -2210,7 +2217,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