From: <vl...@us...> - 2008-01-24 11:52:08
|
Revision: 249 http://scst.svn.sourceforge.net/scst/?rev=249&view=rev Author: vlnb Date: 2008-01-24 03:52:01 -0800 (Thu, 24 Jan 2008) Log Message: ----------- - Version protection added - Cleanups Modified Paths: -------------- trunk/iscsi-scst/kernel/iscsi.c trunk/mpt/mpt_scst.c trunk/qla2x00t/qla2x00-target/qla2x00t.c trunk/scst/include/scsi_tgt.h trunk/scst/include/scst_const.h trunk/scst/include/scst_user.h trunk/scst/src/dev_handlers/scst_cdrom.c trunk/scst/src/dev_handlers/scst_changer.c trunk/scst/src/dev_handlers/scst_disk.c trunk/scst/src/dev_handlers/scst_modisk.c trunk/scst/src/dev_handlers/scst_processor.c trunk/scst/src/dev_handlers/scst_raid.c trunk/scst/src/dev_handlers/scst_tape.c trunk/scst/src/dev_handlers/scst_user.c trunk/scst/src/scst_main.c trunk/usr/fileio/fileio.c Property Changed: ---------------- trunk/scst/include/scsi_tgt.h trunk/scst/include/scst_const.h trunk/scst/include/scst_user.h Modified: trunk/iscsi-scst/kernel/iscsi.c =================================================================== --- trunk/iscsi-scst/kernel/iscsi.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/iscsi-scst/kernel/iscsi.c 2008-01-24 11:52:01 UTC (rev 249) @@ -2768,10 +2768,10 @@ 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) Modified: trunk/mpt/mpt_scst.c =================================================================== --- trunk/mpt/mpt_scst.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/mpt/mpt_scst.c 2008-01-24 11:52:01 UTC (rev 249) @@ -5523,11 +5523,10 @@ 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) { Modified: trunk/qla2x00t/qla2x00-target/qla2x00t.c =================================================================== --- trunk/qla2x00t/qla2x00-target/qla2x00t.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/qla2x00t/qla2x00-target/qla2x00t.c 2008-01-24 11:52:01 UTC (rev 249) @@ -2211,11 +2211,10 @@ 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() Modified: trunk/scst/include/scsi_tgt.h =================================================================== --- trunk/scst/include/scsi_tgt.h 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/include/scsi_tgt.h 2008-01-24 11:52:01 UTC (rev 249) @@ -41,9 +41,10 @@ #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 @@ * 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 @@ * 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 @@ * 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 Property changes on: trunk/scst/include/scsi_tgt.h ___________________________________________________________________ Name: svn:keywords + Revision Modified: trunk/scst/include/scst_const.h =================================================================== --- trunk/scst/include/scst_const.h 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/include/scst_const.h 2008-01-24 11:52:01 UTC (rev 249) @@ -21,6 +21,8 @@ #include <scsi/scsi.h> +#define SCST_CONST_VERSION "$Revision$" + /*** Shared constants between user and kernel spaces ***/ /* Max size of CDB */ Property changes on: trunk/scst/include/scst_const.h ___________________________________________________________________ Name: svn:keywords + Revision Modified: trunk/scst/include/scst_user.h =================================================================== --- trunk/scst/include/scst_user.h 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/include/scst_user.h 2008-01-24 11:52:01 UTC (rev 249) @@ -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_dev_desc { - uint32_t version; + aligned_u64 version_str; uint8_t type; struct scst_user_opt opt; uint32_t block_size; Property changes on: trunk/scst/include/scst_user.h ___________________________________________________________________ Name: svn:keywords + Revision Modified: trunk/scst/src/dev_handlers/scst_cdrom.c =================================================================== --- trunk/scst/src/dev_handlers/scst_cdrom.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_cdrom.c 2008-01-24 11:52:01 UTC (rev 249) @@ -276,10 +276,10 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_changer.c =================================================================== --- trunk/scst/src/dev_handlers/scst_changer.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_changer.c 2008-01-24 11:52:01 UTC (rev 249) @@ -196,10 +196,10 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_disk.c =================================================================== --- trunk/scst/src/dev_handlers/scst_disk.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_disk.c 2008-01-24 11:52:01 UTC (rev 249) @@ -84,20 +84,20 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_modisk.c =================================================================== --- trunk/scst/src/dev_handlers/scst_modisk.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_modisk.c 2008-01-24 11:52:01 UTC (rev 249) @@ -84,20 +84,20 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_processor.c =================================================================== --- trunk/scst/src/dev_handlers/scst_processor.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_processor.c 2008-01-24 11:52:01 UTC (rev 249) @@ -195,10 +195,10 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_raid.c =================================================================== --- trunk/scst/src/dev_handlers/scst_raid.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_raid.c 2008-01-24 11:52:01 UTC (rev 249) @@ -195,10 +195,10 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_tape.c =================================================================== --- trunk/scst/src/dev_handlers/scst_tape.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_tape.c 2008-01-24 11:52:01 UTC (rev 249) @@ -89,20 +89,20 @@ 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) Modified: trunk/scst/src/dev_handlers/scst_user.c =================================================================== --- trunk/scst/src/dev_handlers/scst_user.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/dev_handlers/scst_user.c 2008-01-24 11:52:01 UTC (rev 249) @@ -1755,6 +1755,7 @@ 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 @@ 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 @@ 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 @@ } 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) Modified: trunk/scst/src/scst_main.c =================================================================== --- trunk/scst/src/scst_main.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/scst/src/scst_main.c 2008-01-24 11:52:01 UTC (rev 249) @@ -142,7 +142,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ /* * 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_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); Modified: trunk/usr/fileio/fileio.c =================================================================== --- trunk/usr/fileio/fileio.c 2008-01-24 10:56:35 UTC (rev 248) +++ trunk/usr/fileio/fileio.c 2008-01-24 11:52:01 UTC (rev 249) @@ -374,7 +374,7 @@ } 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; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |