From: Hannes Reinecke <hare@suse.de>
To: Nic Bellinger <nab@daterainc.com>
Cc: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH 1/2] target_core_alua: check for buffer overflow
Date: Thu, 19 Dec 2013 14:36:11 +0100 [thread overview]
Message-ID: <1387460172-27396-2-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1387460172-27396-1-git-send-email-hare@suse.de>
When a writing to a command-provided buffer we need to ensure
that we're not writing past the end of it.
At the same time we need to continue processing as typically
the final data length (ie the required size of the buffer)
need to be returned.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/target/target_core_alua.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 104847e..9b1856d 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -96,22 +96,33 @@ target_emulate_report_referrals(struct se_cmd *cmd)
int pg_num;
off += 4;
- put_unaligned_be64(map->lba_map_first_lba, &buf[off]);
+ if (cmd->data_length > off)
+ put_unaligned_be64(map->lba_map_first_lba, &buf[off]);
off += 8;
- put_unaligned_be64(map->lba_map_last_lba, &buf[off]);
+ if (cmd->data_length > off)
+ put_unaligned_be64(map->lba_map_last_lba, &buf[off]);
off += 8;
rd_len += 20;
pg_num = 0;
list_for_each_entry(map_mem, &map->lba_map_mem_list,
lba_map_mem_list) {
- buf[off++] = map_mem->lba_map_mem_alua_state & 0x0f;
+ int alua_state = map_mem->lba_map_mem_alua_state;
+ int alua_pg_id = map_mem->lba_map_mem_alua_pg_id;
+
+ if (cmd->data_length > off)
+ buf[off] = alua_state & 0x0f;
+ off += 2;
+ if (cmd->data_length > off)
+ buf[off] = (alua_pg_id >> 8) & 0xff;
+ off++;
+ if (cmd->data_length > off)
+ buf[off] = (alua_pg_id & 0xff);
off++;
- buf[off++] = (map_mem->lba_map_mem_alua_pg_id >> 8) & 0xff;
- buf[off++] = (map_mem->lba_map_mem_alua_pg_id & 0xff);
rd_len += 4;
pg_num++;
}
- buf[desc_num] = pg_num;
+ if (cmd->data_length > desc_num)
+ buf[desc_num] = pg_num;
}
spin_unlock(&dev->t10_alua.lba_map_lock);
--
1.7.12.4
next prev parent reply other threads:[~2013-12-19 13:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-19 13:36 [PATCH 0/2] Handle data underflow Hannes Reinecke
2013-12-19 13:36 ` Hannes Reinecke [this message]
2013-12-19 21:43 ` [PATCH 1/2] target_core_alua: check for buffer overflow Nicholas A. Bellinger
2013-12-19 13:36 ` [PATCH 2/2] target_core_spc: bounds check for spc_emulate_inquiry() Hannes Reinecke
2013-12-19 22:11 ` Nicholas A. Bellinger
2013-12-20 6:47 ` Hannes Reinecke
2013-12-20 22:53 ` Paolo Bonzini
2013-12-22 2:53 ` Nicholas A. Bellinger
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=1387460172-27396-2-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@daterainc.com \
--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;
as well as URLs for NNTP newsgroup(s).