summaryrefslogtreecommitdiffstats
path: root/sys/cam
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-10-05 09:26:00 +0000
committermav <mav@FreeBSD.org>2015-10-05 09:26:00 +0000
commitc45abe20442cc1352a834efd7d05f664ce23c2d6 (patch)
tree58c092acad255217c070fe4bceed452bfff974a8 /sys/cam
parent2ddbc805cd7d34853759754a0c0dc1ce1694b1a8 (diff)
downloadFreeBSD-src-c45abe20442cc1352a834efd7d05f664ce23c2d6.zip
FreeBSD-src-c45abe20442cc1352a834efd7d05f664ce23c2d6.tar.gz
MFC r287875: Fix reading after end of file for file-backed LUNs.
If backing file is smaller then the LUN size, we have to explicitly clear the rest of the buffer to not leak some random data from previous I/Os.
Diffstat (limited to 'sys/cam')
-rw-r--r--sys/cam/ctl/ctl_backend_block.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c
index c80304e..aa794a6 100644
--- a/sys/cam/ctl/ctl_backend_block.c
+++ b/sys/cam/ctl/ctl_backend_block.c
@@ -635,8 +635,8 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun,
union ctl_io *io;
struct uio xuio;
struct iovec *xiovec;
- int flags;
- int error, i;
+ size_t s;
+ int error, flags, i;
DPRINTF("entered\n");
@@ -697,6 +697,22 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun,
VOP_UNLOCK(be_lun->vn, 0);
SDT_PROBE(cbb, kernel, read, file_done, 0, 0, 0, 0, 0);
+ if (error == 0 && xuio.uio_resid > 0) {
+ /*
+ * If we red less then requested (EOF), then
+ * we should clean the rest of the buffer.
+ */
+ s = beio->io_len - xuio.uio_resid;
+ for (i = 0; i < beio->num_segs; i++) {
+ if (s >= beio->sg_segs[i].len) {
+ s -= beio->sg_segs[i].len;
+ continue;
+ }
+ bzero((uint8_t *)beio->sg_segs[i].addr + s,
+ beio->sg_segs[i].len - s);
+ s = 0;
+ }
+ }
} else {
struct mount *mountpoint;
int lock_flags;
OpenPOWER on IntegriCloud