Whamcloud - gitweb
LU-7624 fld: copy userspace buffer
[fs/lustre-release.git] / lustre / fld / lproc_fld.c
index 3378956..4ae4f26 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) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -87,22 +87,29 @@ static ssize_t
 fld_proc_hash_seq_write(struct file *file, const char __user *buffer,
                        size_t count, loff_t *off)
 {
-       struct lu_client_fld *fld = ((struct seq_file *)file->private_data)->private;
-        struct lu_fld_hash *hash = NULL;
-        int i;
-       ENTRY;
+       struct lu_client_fld *fld;
+       struct lu_fld_hash *hash = NULL;
+       char fh_name[8];
+       int i;
 
-        LASSERT(fld != NULL);
+       if (count > sizeof(fh_name))
+               return -ENAMETOOLONG;
 
-        for (i = 0; fld_hash[i].fh_name != NULL; i++) {
-                if (count != strlen(fld_hash[i].fh_name))
-                        continue;
+       if (copy_from_user(fh_name, buffer, count) != 0)
+               return -EFAULT;
 
-                if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
-                        hash = &fld_hash[i];
-                        break;
-                }
-        }
+       fld = ((struct seq_file *)file->private_data)->private;
+       LASSERT(fld != NULL);
+
+       for (i = 0; fld_hash[i].fh_name != NULL; i++) {
+               if (count != strlen(fld_hash[i].fh_name))
+                       continue;
+
+               if (!strncmp(fld_hash[i].fh_name, fh_name, count)) {
+                       hash = &fld_hash[i];
+                       break;
+               }
+       }
 
        if (hash != NULL) {
                spin_lock(&fld->lcf_lock);
@@ -113,7 +120,7 @@ fld_proc_hash_seq_write(struct file *file, const char __user *buffer,
                       fld->lcf_name, hash->fh_name);
        }
 
-       RETURN(count);
+       return count;
 }
 
 static ssize_t
@@ -136,7 +143,7 @@ LPROC_SEQ_FOPS_RO(fld_proc_targets);
 LPROC_SEQ_FOPS(fld_proc_hash);
 LPROC_SEQ_FOPS_WO_TYPE(fld, cache_flush);
 
-struct lprocfs_seq_vars fld_client_proc_list[] = {
+struct lprocfs_vars fld_client_proc_list[] = {
        { .name =       "targets",
          .fops =       &fld_proc_targets_fops  },
        { .name =       "hash",
@@ -304,7 +311,7 @@ static int fldb_seq_open(struct inode *inode, struct file *file)
 
        env_init = 1;
        iops = &obj->do_index_ops->dio_it;
-       param->fsp_it = iops->init(&param->fsp_env, obj, 0, NULL);
+       param->fsp_it = iops->init(&param->fsp_env, obj, 0);
        if (IS_ERR(param->fsp_it))
                GOTO(out, rc = PTR_ERR(param->fsp_it));
 
@@ -359,7 +366,7 @@ const struct file_operations fld_proc_seq_fops = {
        .release = fldb_seq_release,
 };
 
-struct lprocfs_seq_vars fld_server_proc_list[] = {
+struct lprocfs_vars fld_server_proc_list[] = {
        { NULL }
 };