From: Mike Christie <michael.christie@oracle.com>
To: martin.petersen@oracle.com,
james.bottomley@hansenpartnership.com,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH 2/4] scsi: target: Fix WRITE_SAME NDOB handling in file
Date: Thu, 16 Jun 2022 22:04:37 -0500 [thread overview]
Message-ID: <20220617030440.116427-3-michael.christie@oracle.com> (raw)
In-Reply-To: <20220617030440.116427-1-michael.christie@oracle.com>
If NDOB is set we don't have a buffer. We will then crash when trying to
access the t_data_sg. This has us allocate a page to use for the data
buffer that gets passed to vfs_iter_write.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/target/target_core_file.c | 32 +++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index e68f1cc8ef98..2011836ab7f4 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -433,6 +433,9 @@ fd_execute_write_same(struct se_cmd *cmd)
struct fd_dev *fd_dev = FD_DEV(se_dev);
loff_t pos = cmd->t_task_lba * se_dev->dev_attrib.block_size;
sector_t nolb = sbc_get_write_same_sectors(cmd);
+ bool ndob = cmd->t_task_cdb[1] & 0x01;
+ struct scatterlist *sg, ndob_sg;
+ struct page *pg = NULL;
struct iov_iter iter;
struct bio_vec *bvec;
unsigned int len = 0, i;
@@ -447,13 +450,13 @@ fd_execute_write_same(struct se_cmd *cmd)
" backends not supported\n");
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
+ sg = &cmd->t_data_sg[0];
if (cmd->t_data_nents > 1 ||
- cmd->t_data_sg[0].length != cmd->se_dev->dev_attrib.block_size) {
+ (sg && sg->length != cmd->se_dev->dev_attrib.block_size)) {
pr_err("WRITE_SAME: Illegal SGL t_data_nents: %u length: %u"
" block_size: %u\n",
- cmd->t_data_nents,
- cmd->t_data_sg[0].length,
+ cmd->t_data_nents, sg->length,
cmd->se_dev->dev_attrib.block_size);
return TCM_INVALID_CDB_FIELD;
}
@@ -462,10 +465,23 @@ fd_execute_write_same(struct se_cmd *cmd)
if (!bvec)
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+ if (ndob) {
+ pg = alloc_page(GFP_KERNEL | __GFP_ZERO);
+ if (!pg) {
+ kfree(bvec);
+ return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+ }
+
+ sg_init_table(&ndob_sg, 1);
+ sg_set_page(&ndob_sg, pg, cmd->se_dev->dev_attrib.block_size,
+ 0);
+ sg = &ndob_sg;
+ }
+
for (i = 0; i < nolb; i++) {
- bvec[i].bv_page = sg_page(&cmd->t_data_sg[0]);
- bvec[i].bv_len = cmd->t_data_sg[0].length;
- bvec[i].bv_offset = cmd->t_data_sg[0].offset;
+ bvec[i].bv_page = sg_page(sg);
+ bvec[i].bv_len = sg->length;
+ bvec[i].bv_offset = sg->offset;
len += se_dev->dev_attrib.block_size;
}
@@ -474,6 +490,10 @@ fd_execute_write_same(struct se_cmd *cmd)
ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, 0);
kfree(bvec);
+
+ if (pg)
+ __free_page(pg);
+
if (ret < 0 || ret != len) {
pr_err("vfs_iter_write() returned %zd for write same\n", ret);
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
--
2.25.1
next prev parent reply other threads:[~2022-06-17 3:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-17 3:04 [PATCH 0/4] target unmap/writespace fixes and enhancements Mike Christie
2022-06-17 3:04 ` [PATCH 1/4] scsi: target: Fix WRITE_SAME NDOB size check Mike Christie
2022-06-19 6:22 ` Christoph Hellwig
2022-06-19 16:25 ` michael.christie
2022-06-20 6:45 ` Christoph Hellwig
2022-06-20 16:03 ` Mike Christie
2022-06-17 3:04 ` Mike Christie [this message]
2022-06-19 6:25 ` [PATCH 2/4] scsi: target: Fix WRITE_SAME NDOB handling in file Christoph Hellwig
2022-06-19 16:26 ` michael.christie
2022-06-19 16:38 ` michael.christie
2022-06-17 3:04 ` [PATCH 3/4] scsi: target: Fix WRITE_SAME NDOB handling in iblock Mike Christie
2022-06-19 6:28 ` Christoph Hellwig
2022-06-17 3:04 ` [PATCH 4/4] scsi: target: Detect unmap support post configuration Mike Christie
2022-06-19 6:29 ` Christoph Hellwig
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=20220617030440.116427-3-michael.christie@oracle.com \
--to=michael.christie@oracle.com \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.