Skip to content

Commit 0ff8754

Browse files
author
Nicholas Bellinger
committed
target: Add link_magic for fabric allow_link destination target_items
This patch adds [dev,lun]_link_magic value assignment + checks within generic target_fabric_port_link() and target_fabric_mappedlun_link() code to ensure destination config_item *target_item sent from configfs_symlink() -> config_item_operations->allow_link() is the underlying se_device->dev_group and se_lun->lun_group that we expect to symlink. Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: stable@vger.kernel.org Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 3e4f574 commit 0ff8754

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎drivers/target/target_core_device.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
13521352
if (!dev)
13531353
return NULL;
13541354

1355+
dev->dev_link_magic = SE_DEV_LINK_MAGIC;
13551356
dev->se_hba = hba;
13561357
dev->transport = hba->transport;
13571358

‎drivers/target/target_core_fabric_configfs.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static int target_fabric_mappedlun_link(
7070
struct se_portal_group *se_tpg;
7171
struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
7272
int ret = 0, lun_access;
73+
74+
if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) {
75+
pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:"
76+
" %p to struct lun: %p\n", lun_ci, lun);
77+
return -EFAULT;
78+
}
7379
/*
7480
* Ensure that the source port exists
7581
*/
@@ -742,6 +748,12 @@ static int target_fabric_port_link(
742748
struct target_fabric_configfs *tf;
743749
int ret;
744750

751+
if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) {
752+
pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:"
753+
" %p to struct se_device: %p\n", se_dev_ci, dev);
754+
return -EFAULT;
755+
}
756+
745757
tpg_ci = &lun_ci->ci_parent->ci_group->cg_item;
746758
se_tpg = container_of(to_config_group(tpg_ci),
747759
struct se_portal_group, tpg_group);

‎drivers/target/target_core_tpg.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ int core_tpg_register(
669669
for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
670670
lun = se_tpg->tpg_lun_list[i];
671671
lun->unpacked_lun = i;
672+
lun->lun_link_magic = SE_LUN_LINK_MAGIC;
672673
lun->lun_status = TRANSPORT_LUN_STATUS_FREE;
673674
atomic_set(&lun->lun_acl_count, 0);
674675
init_completion(&lun->lun_shutdown_comp);

‎include/target/target_core_base.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ struct se_dev_stat_grps {
624624
};
625625

626626
struct se_device {
627+
#define SE_DEV_LINK_MAGIC 0xfeeddeef
628+
u32 dev_link_magic;
627629
/* RELATIVE TARGET PORT IDENTIFER Counter */
628630
u16 dev_rpti_counter;
629631
/* Used for SAM Task Attribute ordering */
@@ -722,6 +724,8 @@ struct se_port_stat_grps {
722724
};
723725

724726
struct se_lun {
727+
#define SE_LUN_LINK_MAGIC 0xffff7771
728+
u32 lun_link_magic;
725729
/* See transport_lun_status_table */
726730
enum transport_lun_status_table lun_status;
727731
u32 lun_access;

0 commit comments

Comments
 (0)