From 34c4eae2eb493d4de97f5f9e784d4efc73b9f886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Fri, 7 Jan 2011 13:53:13 +0100 Subject: [PATCH] Check set limits fit into the range supported by RPC transport E.g. setquota -r root $((2**32)) 1000 10 10 /mnt/nfs/12tb clamped the values into 32 bits and RPC server got 0 soft block limit. This fixes simalar bug spotted in 8a4dc3612c6c170c05e5eef68dd3555baeb341c1 (Check whether set limits fit into the range supported by quota format.) --- quotaio.c | 2 ++ quotaio_rpc.c | 18 ++++++++++++++++++ rquota_client.c | 5 +++++ 3 files changed, 25 insertions(+), 0 deletions(-) diff --git a/quotaio.c b/quotaio.c index 21881fc..3b74680 100644 --- a/quotaio.c +++ b/quotaio.c @@ -69,6 +69,8 @@ struct quota_handle *init_io(struct mntent *mnt, int type, int fmt, int flags) h->qh_fd = -1; h->qh_fmt = QF_RPC; h->qh_ops = "afile_ops_rpc; + memset(&h->qh_info, 0, sizeof(h->qh_info)); + h->qh_ops->init_io(h); return h; #else errstr(_("RPC quota format not compiled.\n")); diff --git a/quotaio_rpc.c b/quotaio_rpc.c index 14fe410..2e0b493 100644 --- a/quotaio_rpc.c +++ b/quotaio_rpc.c @@ -15,14 +15,32 @@ #include "rquota_client.h" #include "pot.h" +static int rpc_init_io(struct quota_handle *h); static struct dquot *rpc_read_dquot(struct quota_handle *h, qid_t id); static int rpc_commit_dquot(struct dquot *dquot, int flags); struct quotafile_ops quotafile_ops_rpc = { +init_io: rpc_init_io, read_dquot: rpc_read_dquot, commit_dquot: rpc_commit_dquot }; +/* + * Define maximal values RPC client can transmit to server. + */ +static int rpc_init_io(struct quota_handle *h) +{ +#ifdef RPC + h->qh_info.dqi_max_b_limit = ~(uint32_t)0; + h->qh_info.dqi_max_i_limit = ~(uint32_t)0; + h->qh_info.dqi_max_b_usage = (~(uint32_t)0) << QUOTABLOCK_BITS; + h->qh_info.dqi_max_i_usage = ~(uint32_t)0; + return 0; +#else + return -1; +#endif +} + /* * Read a dqblk struct from RPC server - just wrapper function. */ diff --git a/rquota_client.c b/rquota_client.c index cc1d623..4aad4b9 100644 --- a/rquota_client.c +++ b/rquota_client.c @@ -242,6 +242,11 @@ int rpc_rquota_set(int qcmd, struct dquot *dquot) char *fsname_tmp, *host, *pathname; struct timeval timeout = { 2, 0 }; + /* RPC limits values to 32b variables. Prevent value wrapping. */ + if (check_dquot_range(dquot) < 0) { + return -ERANGE; + } + /* * Convert host:pathname to seperate host and pathname. */ -- 1.7.3.4