Whamcloud - gitweb
LU-7661 mgs: restrict MGS_SET_INFO to stripe parameters 82/17982/2
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 13 Jan 2016 17:16:28 +0000 (11:16 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 21 Jan 2016 03:52:34 +0000 (03:52 +0000)
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 <john.hammond@intel.com>
Change-Id: I5ac693f886fd035ab639e03628849e791e1e2e9a
Reviewed-on: http://review.whamcloud.com/17982
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Jeremy Filizetti <jeremy.filizetti@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mgs/mgs_handler.c

index 17cb290..316d963 100644 (file)
@@ -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);