From: David Disseldorp <ddiss@suse.de>
To: target-devel@vger.kernel.org
Subject: [RFC PATCH] target: sanitize ALUA and PR state file paths before use
Date: Thu, 22 Nov 2018 13:38:00 +0000 [thread overview]
Message-ID: <20181122133800.1251-1-ddiss@suse.de> (raw)
Block ALUA and PR state storage if any of the dynamic subdirectory
components include a path separator.
Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
Note:
Submitted as an RFC, as I've not properly tested the alua code path.
I'm also not sure whether it's reasonable to break existing setups
with a '/' in the configured unit_serial. Where "break" means fail
APTPL PR requests; ALUA state-save failures are ignored internally.
drivers/target/target_core_alua.c | 27 ++++++++++++++++++++-------
drivers/target/target_core_pr.c | 5 +++++
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 4f134b0c3e29..517945f881e0 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -918,9 +918,16 @@ static int core_alua_update_tpg_primary_metadata(
{
unsigned char *md_buf;
struct t10_wwn *wwn = &tg_pt_gp->tg_pt_gp_dev->t10_wwn;
+ const char *tpgs_name;
char *path;
int len, rc;
+ tpgs_name = config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item);
+ if (strchr(wwn->unit_serial, '/') || strchr(tpgs_name, '/')) {
+ pr_err("Unable to construct valid ALUA metadata path\n");
+ return -EINVAL;
+ }
+
md_buf = kzalloc(ALUA_MD_BUF_LEN, GFP_KERNEL);
if (!md_buf) {
pr_err("Unable to allocate buf for ALUA metadata\n");
@@ -937,8 +944,7 @@ static int core_alua_update_tpg_primary_metadata(
rc = -ENOMEM;
path = kasprintf(GFP_KERNEL, "%s/alua/tpgs_%s/%s", db_root,
- &wwn->unit_serial[0],
- config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item));
+ &wwn->unit_serial[0], tpgs_name);
if (path) {
rc = core_alua_write_tpg_metadata(path, md_buf, len);
kfree(path);
@@ -1210,6 +1216,8 @@ static int core_alua_update_tpg_secondary_metadata(struct se_lun *lun)
{
struct se_portal_group *se_tpg = lun->lun_tpg;
unsigned char *md_buf;
+ const char *fabric_name;
+ const char *wwn;
char *path;
int len, rc;
@@ -1227,17 +1235,22 @@ static int core_alua_update_tpg_secondary_metadata(struct se_lun *lun)
atomic_read(&lun->lun_tg_pt_secondary_offline),
lun->lun_tg_pt_secondary_stat);
+ fabric_name = se_tpg->se_tpg_tfo->get_fabric_name();
+ wwn = se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg);
+ if (strchr(fabric_name, '/') || strchr(wwn, '/')) {
+ pr_err("Unable to construct valid ALUA metadata path\n");
+ rc = -EINVAL;
+ goto out_free;
+ }
+
if (se_tpg->se_tpg_tfo->tpg_get_tag != NULL) {
path = kasprintf(GFP_KERNEL, "%s/alua/%s/%s+%hu/lun_%llu",
- db_root, se_tpg->se_tpg_tfo->get_fabric_name(),
- se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg),
+ db_root, fabric_name, wwn,
se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg),
lun->unpacked_lun);
} else {
path = kasprintf(GFP_KERNEL, "%s/alua/%s/%s/lun_%llu",
- db_root, se_tpg->se_tpg_tfo->get_fabric_name(),
- se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg),
- lun->unpacked_lun);
+ db_root, fabric_name, wwn, lun->unpacked_lun);
}
if (!path) {
rc = -ENOMEM;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 10db5656fd5d..48397cf919d4 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1980,6 +1980,11 @@ static int __core_scsi3_write_aptpl_to_file(
int ret;
loff_t pos = 0;
+ if (strchr(wwn->unit_serial, '/')) {
+ pr_err("Unable to construct valid APTPL metadata path\n");
+ return -EINVAL;
+ }
+
path = kasprintf(GFP_KERNEL, "%s/pr/aptpl_%s", db_root,
&wwn->unit_serial[0]);
if (!path)
--
2.13.7
next reply other threads:[~2018-11-22 13:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-22 13:38 David Disseldorp [this message]
2018-12-10 13:36 ` [RFC PATCH] target: sanitize ALUA and PR state file paths before use David Disseldorp
2018-12-10 19:19 ` Bart Van Assche
2018-12-10 19:35 ` David Disseldorp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181122133800.1251-1-ddiss@suse.de \
--to=ddiss@suse.de \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox