- Version protection added
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Thu, 24 Jan 2008 11:52:01 +0000 (11:52 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Thu, 24 Jan 2008 11:52:01 +0000 (11:52 +0000)
 - Cleanups

git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@249 d57e44dd-8a1f-0410-8b47-8ef2f437770f

16 files changed:
iscsi-scst/kernel/iscsi.c
mpt/mpt_scst.c
qla2x00t/qla2x00-target/qla2x00t.c
scst/include/scsi_tgt.h
scst/include/scst_const.h
scst/include/scst_user.h
scst/src/dev_handlers/scst_cdrom.c
scst/src/dev_handlers/scst_changer.c
scst/src/dev_handlers/scst_disk.c
scst/src/dev_handlers/scst_modisk.c
scst/src/dev_handlers/scst_processor.c
scst/src/dev_handlers/scst_raid.c
scst/src/dev_handlers/scst_tape.c
scst/src/dev_handlers/scst_user.c
scst/src/scst_main.c
usr/fileio/fileio.c

index a60e546..3a6f3d0 100644 (file)
@@ -2768,10 +2768,10 @@ static int __init iscsi_init(void)
                goto out_event;
        }
 
-       if (scst_register_target_template(&iscsi_template) < 0) {
-               err = -ENODEV;
+       err = scst_register_target_template(&iscsi_template);
+       if (err < 0)
                goto out_kmem;
-       }
+
        iscsi_template_registered = 1;
 
        if ((err = iscsi_procfs_init()) < 0)
index b0ebdfc..9c85248 100644 (file)
@@ -5523,11 +5523,10 @@ static int __init mpt_target_init(void)
        int res = 0;
 
        TRACE_ENTRY();
-       
-       if (scst_register_target_template(&tgt_template) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_target_template(&tgt_template);
+       if (res < 0)
                goto out;
-       }
 
        res = mpt_proc_log_entry_build(&tgt_template);
        if (res < 0) {
index d7c4a5f..4fa5a94 100644 (file)
@@ -2211,11 +2211,10 @@ static int __init q2t_init(void)
                res = -ENOMEM;
                goto out;
        }
-       
-       if (scst_register_target_template(&tgt_template) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_target_template(&tgt_template);
+       if (res < 0)
                goto out;
-       }
 
        /* qla2xxx_tgt_register_driver() happens in q2t_target_detect 
         * called via scst_register_target_template()
index cfb56fc..91ded86 100644 (file)
@@ -41,9 +41,10 @@ typedef _Bool bool;
 #endif
 
 /* Version numbers, the same as for the kernel */
-#define SCST_VERSION_CODE 0x000906
-#define SCST_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+#define SCST_VERSION_CODE 0x00090601
+#define SCST_VERSION(a,b,c,d) (((a) << 24) + ((b) << 16) + ((c) << 8) + d)
 #define SCST_VERSION_STRING "0.9.6-rc1"
+#define SCST_INTERFACE_VERSION SCST_VERSION_STRING "$Revision$" SCST_CONST_VERSION
 
 /*************************************************************
  ** States of command processing state machine. At first, 
@@ -1539,7 +1540,12 @@ struct scst_tgt_dev_UA
  * Registers target template
  * Returns 0 on success or appropriate error code otherwise
  */
-int scst_register_target_template(struct scst_tgt_template *vtt);
+int __scst_register_target_template(struct scst_tgt_template *vtt,
+       const char *version);
+static inline int scst_register_target_template(struct scst_tgt_template *vtt)
+{
+       return __scst_register_target_template(vtt, SCST_INTERFACE_VERSION);
+}
 
 /* 
  * Unregisters target template
@@ -1646,7 +1652,12 @@ void scst_unregister_session(struct scst_session *sess, int wait,
  * Registers dev handler driver
  * Returns 0 on success or appropriate error code otherwise
  */
-int scst_register_dev_driver(struct scst_dev_type *dev_type);
+int __scst_register_dev_driver(struct scst_dev_type *dev_type,
+       const char *version);
+static inline int scst_register_dev_driver(struct scst_dev_type *dev_type)
+{
+       return __scst_register_dev_driver(dev_type, SCST_INTERFACE_VERSION);
+}
 
 /* 
  * Unregisters dev handler driver
@@ -1657,7 +1668,14 @@ void scst_unregister_dev_driver(struct scst_dev_type *dev_type);
  * Registers dev handler driver for virtual devices (eg VDISK)
  * Returns 0 on success or appropriate error code otherwise
  */
-int scst_register_virtual_dev_driver(struct scst_dev_type *dev_type);
+int __scst_register_virtual_dev_driver(struct scst_dev_type *dev_type,
+       const char *version);
+static inline int scst_register_virtual_dev_driver(
+       struct scst_dev_type *dev_type)
+{
+       return __scst_register_virtual_dev_driver(dev_type,
+               SCST_INTERFACE_VERSION);
+}
 
 /* 
  * Unregisters dev handler driver for virtual devices
index 24288c6..7121c7b 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <scsi/scsi.h>
 
+#define SCST_CONST_VERSION "$Revision$"
+
 /*** Shared constants between user and kernel spaces ***/
 
 /* Max size of CDB */
index 98792fd..90614be 100644 (file)
@@ -25,7 +25,8 @@
 
 #define DEV_USER_NAME                  "scst_user"
 #define DEV_USER_PATH                  "/dev/"
-#define DEV_USER_VERSION               963
+#define DEV_USER_VERSION_NAME          "0.9.6"
+#define DEV_USER_VERSION               DEV_USER_VERSION_NAME "$Revision$" SCST_CONST_VERSION
 
 /* 
  * Chosen so sizeof(scst_user_sess) <= sizeof(scst_user_scsi_cmd_exec) 
@@ -105,7 +106,7 @@ struct scst_user_opt
 
 struct scst_user_dev_desc
 {
-       uint32_t version;
+       aligned_u64 version_str;
        uint8_t type;
        struct scst_user_opt opt;
        uint32_t block_size;
index 57acb04..89eae1b 100644 (file)
@@ -276,10 +276,10 @@ static int __init cdrom_init(void)
        TRACE_ENTRY();
        
        cdrom_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&cdrom_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&cdrom_devtype);
+       if (res < 0)
                goto out;
-       }
 
        res = scst_dev_handler_build_std_proc(&cdrom_devtype);
        if (res != 0)
index 1931ce9..0e78167 100644 (file)
@@ -196,10 +196,10 @@ static int __init changer_init(void)
        TRACE_ENTRY();
        
        changer_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&changer_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&changer_devtype);
+       if (res < 0)
                goto out;
-       }
        
        res = scst_dev_handler_build_std_proc(&changer_devtype);
        if (res != 0)
index 2afb096..7d2754d 100644 (file)
@@ -84,20 +84,20 @@ static int __init init_scst_disk_driver(void)
        TRACE_ENTRY();
 
        disk_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&disk_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&disk_devtype);
+       if (res < 0)
                goto out;
-       }
 
        res = scst_dev_handler_build_std_proc(&disk_devtype);
        if (res != 0)
                goto out_unreg1;
 
        disk_devtype_perf.module = THIS_MODULE;
-       if (scst_register_dev_driver(&disk_devtype_perf) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&disk_devtype_perf);
+       if (res < 0)
                goto out_unreg1_err1;
-       }
 
        res = scst_dev_handler_build_std_proc(&disk_devtype_perf);
        if (res != 0)
index 3391954..c7edea3 100644 (file)
@@ -84,20 +84,20 @@ static int __init init_scst_modisk_driver(void)
        TRACE_ENTRY();
 
        modisk_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&modisk_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&modisk_devtype);
+       if (res < 0)
                goto out;
-       }
 
        res = scst_dev_handler_build_std_proc(&modisk_devtype);
        if (res != 0)
                goto out_unreg1;
 
        modisk_devtype_perf.module = THIS_MODULE;         
-       if (scst_register_dev_driver(&modisk_devtype_perf) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&modisk_devtype_perf);
+       if (res < 0)
                goto out_unreg1_err1;
-       }
 
        res = scst_dev_handler_build_std_proc(&modisk_devtype_perf);
        if (res != 0)
index a30088d..764c6c0 100644 (file)
@@ -195,10 +195,10 @@ static int __init processor_init(void)
        TRACE_ENTRY();
 
        processor_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&processor_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&processor_devtype);
+       if (res < 0)
                goto out;
-       }
        
        res = scst_dev_handler_build_std_proc(&processor_devtype);
        if (res != 0)
index acd097d..82a8c2e 100644 (file)
@@ -195,10 +195,10 @@ static int __init raid_init(void)
        TRACE_ENTRY();
 
        raid_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&raid_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&raid_devtype);
+       if (res < 0)
                goto out;
-       }
        
        res = scst_dev_handler_build_std_proc(&raid_devtype);
        if (res != 0)
index 7b111b4..9d7a96f 100644 (file)
@@ -89,20 +89,20 @@ static int __init init_scst_tape_driver(void)
        TRACE_ENTRY();
 
        tape_devtype.module = THIS_MODULE;
-       if (scst_register_dev_driver(&tape_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&tape_devtype);
+       if (res < 0)
                goto out;
-       }
 
        res = scst_dev_handler_build_std_proc(&tape_devtype);
        if (res != 0)
                goto out_unreg1;
 
        tape_devtype_perf.module = THIS_MODULE;
-       if (scst_register_dev_driver(&tape_devtype_perf) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_dev_driver(&tape_devtype_perf);
+       if (res < 0)
                goto out_unreg1_err1;
-       }
 
        res = scst_dev_handler_build_std_proc(&tape_devtype_perf);
        if (res != 0)
index ed85d97..1ab385f 100644 (file)
@@ -1755,6 +1755,7 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd,
                        goto out;
                }
                TRACE_BUFFER("dev_desc", dev_desc, sizeof(*dev_desc));
+               dev_desc->name[sizeof(dev_desc->name)-1] = '\0';
                res = dev_user_register_dev(file, dev_desc);
                kfree(dev_desc);
                break;
@@ -2551,6 +2552,31 @@ static void dev_user_setup_functions(struct scst_user_dev *dev)
        return;
 }
 
+static int dev_user_check_version(const struct scst_user_dev_desc *dev_desc)
+{
+       char ver[sizeof(DEV_USER_VERSION)+1];
+       int res;
+
+       res = copy_from_user(ver, (void*)(unsigned long)dev_desc->version_str,
+                               sizeof(ver));
+       if (res < 0) {
+               PRINT_ERROR("%s", "Unable to get version string");
+               goto out;
+       }
+       ver[sizeof(ver)-1] = '\0';
+
+       if (strcmp(ver, DEV_USER_VERSION) != 0) {
+               /* ->name already 0-terminated in dev_user_ioctl() */
+               PRINT_ERROR("Incorrect version of user device %s (%s)",
+                       dev_desc->name, ver);
+               res = -EINVAL;
+               goto out;
+       }
+
+out:
+       return res;
+}
+
 static int dev_user_register_dev(struct file *file,
        const struct scst_user_dev_desc *dev_desc)
 {
@@ -2560,12 +2586,9 @@ static int dev_user_register_dev(struct file *file,
 
        TRACE_ENTRY();
 
-       if (dev_desc->version != DEV_USER_VERSION) {
-               PRINT_ERROR("Version mismatch (requested %d, required %d)",
-                       dev_desc->version, DEV_USER_VERSION);
-               res = -EINVAL;
+       res = dev_user_check_version(dev_desc);
+       if (res != 0)
                goto out;
-       }
 
        switch(dev_desc->type) {
        case TYPE_DISK:
@@ -3062,10 +3085,10 @@ static int __init init_scst_user(void)
        }
 
        dev_user_devtype.module = THIS_MODULE;
-       if (scst_register_virtual_dev_driver(&dev_user_devtype) < 0) {
-               res = -ENODEV;
+
+       res = scst_register_virtual_dev_driver(&dev_user_devtype);
+       if (res < 0)
                goto out_cache;
-       }
 
        res = scst_dev_handler_build_std_proc(&dev_user_devtype);
        if (res != 0)
index 6248d87..9365d02 100644 (file)
@@ -142,7 +142,8 @@ struct scst_dev_type scst_null_devtype =
   name:     "none",
 };
 
-int scst_register_target_template(struct scst_tgt_template *vtt)
+int __scst_register_target_template(struct scst_tgt_template *vtt,
+       const char *version)
 {
        int res = 0;
        struct scst_tgt_template *t;
@@ -152,6 +153,12 @@ int scst_register_target_template(struct scst_tgt_template *vtt)
 
        INIT_LIST_HEAD(&vtt->tgt_list);
 
+       if (strcmp(version, SCST_INTERFACE_VERSION) != 0) {
+               PRINT_ERROR("Incorrect version of target %s", vtt->name);
+               res = -EINVAL;
+               goto out_err;
+       }
+
        if (!vtt->detect) {
                PRINT_ERROR("Target driver %s doesn't have a "
                        "detect() method.", vtt->name);
@@ -742,7 +749,8 @@ out_unblock:
        return;
 }
 
-int scst_register_dev_driver(struct scst_dev_type *dev_type)
+int __scst_register_dev_driver(struct scst_dev_type *dev_type,
+       const char *version)
 {
        struct scst_dev_type *dt;
        struct scst_device *dev;
@@ -751,6 +759,13 @@ int scst_register_dev_driver(struct scst_dev_type *dev_type)
 
        TRACE_ENTRY();
 
+       if (strcmp(version, SCST_INTERFACE_VERSION) != 0) {
+               PRINT_ERROR("Incorrect version of dev handler %s",
+                       dev_type->name);
+               res = -EINVAL;
+               goto out_error;
+       }
+
        res = scst_dev_handler_check(dev_type);
        if (res != 0)
                goto out_error;
@@ -872,12 +887,20 @@ out_up:
        goto out;
 }
 
-int scst_register_virtual_dev_driver(struct scst_dev_type *dev_type)
+int __scst_register_virtual_dev_driver(struct scst_dev_type *dev_type,
+       const char *version)
 {
        int res;
 
        TRACE_ENTRY();
 
+       if (strcmp(version, SCST_INTERFACE_VERSION) != 0) {
+               PRINT_ERROR("Incorrect version of virtual dev handler %s",
+                       dev_type->name);
+               res = -EINVAL;
+               goto out_err;
+       }
+
        res = scst_dev_handler_check(dev_type);
        if (res != 0)
                goto out_err;
@@ -1658,14 +1681,14 @@ static void __exit exit_scst(void)
 /*
  * Device Handler Side (i.e. scst_vdisk)
  */
-EXPORT_SYMBOL(scst_register_dev_driver);
+EXPORT_SYMBOL(__scst_register_dev_driver);
 EXPORT_SYMBOL(scst_unregister_dev_driver);
 EXPORT_SYMBOL(scst_register);
 EXPORT_SYMBOL(scst_unregister);
 
 EXPORT_SYMBOL(scst_register_virtual_device);
 EXPORT_SYMBOL(scst_unregister_virtual_device);
-EXPORT_SYMBOL(scst_register_virtual_dev_driver);
+EXPORT_SYMBOL(__scst_register_virtual_dev_driver);
 EXPORT_SYMBOL(scst_unregister_virtual_dev_driver);
 
 EXPORT_SYMBOL(scst_set_busy);
@@ -1683,7 +1706,7 @@ EXPORT_SYMBOL(scst_process_active_cmd);
 EXPORT_SYMBOL(scst_register_session);
 EXPORT_SYMBOL(scst_unregister_session);
 
-EXPORT_SYMBOL(scst_register_target_template);
+EXPORT_SYMBOL(__scst_register_target_template);
 EXPORT_SYMBOL(scst_unregister_target_template);
 
 EXPORT_SYMBOL(scst_cmd_init_done);
index a210113..6ed7b5c 100644 (file)
@@ -374,7 +374,7 @@ int main(int argc, char **argv)
        }
 
        memset(&desc, 0, sizeof(desc));
-       desc.version = DEV_USER_VERSION;
+       desc.version_str = (unsigned long)DEV_USER_VERSION;
        strncpy(desc.name, dev.name, sizeof(desc.name)-1);
        desc.name[sizeof(desc.name)-1] = '\0';
        desc.type = dev.type;