Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Oct 2015 09:26:00 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r288764 - stable/10/sys/cam/ctl
Message-ID:  <201510050926.t959Q04r043166@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Oct  5 09:26:00 2015
New Revision: 288764
URL: https://svnweb.freebsd.org/changeset/base/288764

Log:
  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.

Modified:
  stable/10/sys/cam/ctl/ctl_backend_block.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_backend_block.c	Mon Oct  5 09:25:04 2015	(r288763)
+++ stable/10/sys/cam/ctl/ctl_backend_block.c	Mon Oct  5 09:26:00 2015	(r288764)
@@ -635,8 +635,8 @@ ctl_be_block_dispatch_file(struct ctl_be
 	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
 
 		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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510050926.t959Q04r043166>