From: Bruno Faccini Date: Fri, 2 Jan 2015 12:37:37 +0000 (+0100) Subject: LU-6078 utils: fix copytool file bounds checking X-Git-Tag: 2.7.51~40 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f26cdd1c6e1d0570f2debc13b4165a0c710f6fe5;ds=sidebyside LU-6078 utils: fix copytool file bounds checking Strengthen copytool file bounds checking in either full or partial/extent mode. Signed-off-by: Bruno Faccini Change-Id: I36939f9a18362ca3131e39b8d390978dfc79405a Reviewed-on: http://review.whamcloud.com/13226 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Henri Doreau Reviewed-by: Hongchao Zhang Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/lhsmtool_posix.c b/lustre/utils/lhsmtool_posix.c index db0dd98..5a81e4f 100644 --- a/lustre/utils/lhsmtool_posix.c +++ b/lustre/utils/lhsmtool_posix.c @@ -543,6 +543,14 @@ static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src, return rc; } + if (hai->hai_extent.offset > (__u64)src_st.st_size) { + rc = -EINVAL; + CT_ERROR(rc, "Trying to start reading past end ("LPU64" > " + "%jd) of '%s' source file", hai->hai_extent.offset, + (intmax_t)src_st.st_size, src); + return rc; + } + if (fstat(dst_fd, &dst_st) < 0) { rc = -errno; CT_ERROR(rc, "cannot stat '%s'", dst); @@ -555,17 +563,9 @@ static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src, return rc; } - rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET); - if (rc < 0) { - rc = -errno; - CT_ERROR(rc, - "cannot seek for read to "LPU64" (len %jd) in '%s'", - hai->hai_extent.offset, (intmax_t)src_st.st_size, src); - return rc; - } - /* Don't read beyond a given extent */ - length = min(hai->hai_extent.length, src_st.st_size); + length = min(hai->hai_extent.length, + src_st.st_size - hai->hai_extent.offset); start_time = last_bw_print = last_report_time = time(NULL);