From: John L. Hammond Date: Wed, 13 Jan 2016 17:16:28 +0000 (-0600) Subject: LU-7661 mgs: restrict MGS_SET_INFO to stripe parameters X-Git-Tag: 2.7.66~31 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=ff577af11b3eb96fbdb2de7af0cdf78ad6c8ec56 LU-7661 mgs: restrict MGS_SET_INFO to stripe parameters The MGS_SET_INFO RPC is only needed for setting the default striping on a filesystem, so in mgs_set_info() reject attempts to set a parameter that is not of the form *.lov.stripe{count,size,offset}=*. Signed-off-by: John L. Hammond Change-Id: I5ac693f886fd035ab639e03628849e791e1e2e9a Reviewed-on: http://review.whamcloud.com/17982 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Jeremy Filizetti Reviewed-by: Oleg Drokin --- diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 17cb290..316d963 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -94,11 +94,18 @@ static int mgs_exception(struct tgt_session_info *tsi) RETURN(0); } +static inline bool str_starts_with(const char *str, const char *prefix) +{ + return strncmp(str, prefix, strlen(prefix)) == 0; +} + static int mgs_set_info(struct tgt_session_info *tsi) { struct mgs_thread_info *mgi; struct mgs_send_param *msp, *rep_msp; struct lustre_cfg *lcfg; + size_t param_len; + char *s; int rc; ENTRY; @@ -111,6 +118,20 @@ static int mgs_set_info(struct tgt_session_info *tsi) if (msp == NULL) RETURN(err_serious(-EFAULT)); + param_len = strnlen(msp->mgs_param, sizeof(msp->mgs_param)); + if (param_len == 0 || param_len == sizeof(msp->mgs_param)) + RETURN(-EINVAL); + + /* We only allow '*.lov.stripe{size,count,offset}=*' from an RPC. */ + s = strchr(msp->mgs_param, '.'); + if (s == NULL) + RETURN(-EINVAL); + + if (!str_starts_with(s + 1, "lov.stripesize=") && + !str_starts_with(s + 1, "lov.stripecount=") && + !str_starts_with(s + 1, "lov.stripeoffset=")) + RETURN(-EINVAL); + /* Construct lustre_cfg structure to pass to function mgs_setparam */ lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL); lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param);