[LU-6078] Posix copytool file bounds checking is flawed Created: 02/Jan/15  Updated: 14/Jun/18  Resolved: 24/Mar/15

Status: Resolved
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: Lustre 2.8.0

Type: Bug Priority: Minor
Reporter: Bruno Faccini (Inactive) Assignee: Bruno Faccini (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Environment:

All


Issue Links:
Related
Severity: 3
Rank (Obsolete): 16910

 Description   

Original text/report from J.Nemeth (SGI) :

The ct_copy_data() routine has the following code:

	rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET);
	if (rc < 0) {
		CT_ERROR(errno,
			 "cannot seek for read to "LPU64" (len %jd) in '%s'",
			 hai->hai_extent.offset, (intmax_t)src_st.st_size, src);
		rc = -errno;
		goto out;
	}

This appears to be checking to ensure that the hai_extent.offset value is not outside the bounds of the file. However, this call will never fail, because it is not illegal to seek outside the bounds of the file: an attempt to write at an offset beyond the file bounds will extend the file (potentially leaving a "hole" in the data), and an attempt to read at that location will cause an EOD error. But the lseek() won't fail.

This occurs after fstat() has already been called on the open src file, so the file size is already known. This should simply check the offset against the file size.

Similarly, the following occurs shortly afterward:

	length = min(hai->hai_extent.length, src_st.st_size);

This seems simply wrong -- it should be:

        length = min(hai->hai_extent.length, src_st.st_size
                                                                   - hai->hai_extent.offset);

I don't know if the coordinator ever issues a request for part of a source file, but these error checks are wrong, and should be removed, or corrected.


 Comments   
Comment by Gerrit Updater [ 02/Jan/15 ]

Faccini Bruno (bruno.faccini@intel.com) uploaded a new patch: http://review.whamcloud.com/13226
Subject: LU-6078 utils: fix copytool file bounds checking
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: d72c4eebaf64440724f618087a3924af790b9060

Comment by Gerrit Updater [ 18/Mar/15 ]

Oleg Drokin (oleg.drokin@intel.com) merged in patch http://review.whamcloud.com/13226/
Subject: LU-6078 utils: fix copytool file bounds checking
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: f26cdd1c6e1d0570f2debc13b4165a0c710f6fe5

Generated at Sat Feb 10 01:57:01 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.