Whamcloud - gitweb
LU-7623 Update obd iocontrol methods with __user attribute
[fs/lustre-release.git] / lustre / mgs / mgs_handler.c
index ff23c33..f1a643e 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2010, 2014, Intel Corporation.
+ * Copyright (c) 2010, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -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);
@@ -842,7 +863,7 @@ out_pool:
 
 /* from mdt_iocontrol */
 static int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
-                        void *karg, void *uarg)
+                        void *karg, void __user *uarg)
 {
        struct mgs_device *mgs = exp2mgs_dev(exp);
         struct obd_ioctl_data *data = karg;
@@ -1545,13 +1566,14 @@ static int __init mgs_init(void)
                                   LUSTRE_MGS_NAME, &mgs_device_type);
 }
 
-static void /*__exit*/ mgs_exit(void)
+static void __exit mgs_exit(void)
 {
        class_unregister_type(LUSTRE_MGS_NAME);
 }
 
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Lustre  Management Server (MGS)");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre Management Server (MGS)");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
 MODULE_LICENSE("GPL");
 
 module_init(mgs_init);