Page MenuHomeFreeBSD

vm_fault_copy_entry: accept invalid source pages.
ClosedPublic

Authored by kib on Mar 17 2019, 8:21 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 17 2024, 9:25 AM
Unknown Object (File)
Feb 12 2024, 12:32 AM
Unknown Object (File)
Jan 23 2024, 8:51 AM
Unknown Object (File)
Jan 17 2024, 4:04 AM
Unknown Object (File)
Dec 22 2023, 10:02 PM
Unknown Object (File)
Dec 17 2023, 9:19 AM
Unknown Object (File)
Oct 26 2023, 1:41 PM
Unknown Object (File)
Oct 22 2023, 4:30 AM
Subscribers

Details

Summary

Either msync(MS_INVALIDATE) or the object unlock during vnode truncation can expose invalid pages backing wired entries. Accept them, but do not install them into destrination pmap. We must create copied pages in the copy case, because e.g. vm_object_unwire() expects that the entry is fully backed.

Reported by: syzkaller, via emaste
Reported by: syzbot+514d40ce757a3f8b15bc@syzkaller.appspotmail.com

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Assuming it was this report panic: invalid dst page 0xfffff8007f14af98 https://syzkaller.appspot.com/bug?id=de0b1fa4863a64133877eb032d3ef876cb70d00a, eventual commit message should contain Reported-by: syzbot+514d40ce757a3f8b15bc@syzkaller.appspotmail.com

sys/vm/vm_fault.c
1759 ↗(On Diff #55174)

Should we zero the invalid region? Otherwise I don't see the purpose of zeroing a completely invalid page.

1785 ↗(On Diff #55174)

"truncated the backing vnode or shared memory object"

kib marked an inline comment as done.Mar 18 2019, 2:39 PM
kib added inline comments.
sys/vm/vm_fault.c
1759 ↗(On Diff #55174)

I believe this already have been done for src_m, otherwise it is problematic as is. I mean that dst_m is not worse than src_m.

Assuming it was this report panic: invalid dst page 0xfffff8007f14af98 https://syzkaller.appspot.com/bug?id=de0b1fa4863a64133877eb032d3ef876cb70d00a, eventual commit message should contain Reported-by: syzbot+514d40ce757a3f8b15bc@syzkaller.appspotmail.com

Dmitry noted that you shouldn't need the dash, i.e., "Reported by: syzbot+514d40ce757a3f8b15bc@syzkaller.appspotmail.com" is fine.

sys/vm/vm_fault.c
1759 ↗(On Diff #55174)

I don't see the point in checking src_m->valid != 0 then.

This revision is now accepted and ready to land.Mar 18 2019, 2:47 PM
sys/vm/vm_fault.c
1759 ↗(On Diff #55174)

I mean, I understand that partially valid pages have zero invalid regions, but we are not mapping the page unless it is completely valid.

Dmitry noted that you shouldn't need the dash, i.e., "Reported by: syzbot+514d40ce757a3f8b15bc@syzkaller.appspotmail.com" is fine.

Indeed, I just cut and pasted the string from the report.

Unconditionally copy src_m to dst_m (ignore valid bits).
Update comment.

This revision now requires review to proceed.Mar 18 2019, 5:25 PM

Reported by: emaste using syzcaller

Perhaps more correct as "Reported by: syzkaller, via emaste" - this was reported by Google's public syzkaller while "emaste using syzkaller" implies it's something I directly did myself.

I'm writing a few test cases for mlock as part of the user wiring work. I added one which does the following:

  1. truncate an empty file to 4KB
  2. map the file and mlock the mapping
  3. write some non-zero bytes to the mapping
  4. truncate the file to 0
  5. truncate the file to 4KB
  6. verify that the mapping is zero-filled

Step 5 does not preemptively fault in pages, which is technically a violation of mlock()'s contract.

This revision is now accepted and ready to land.Mar 18 2019, 7:05 PM
kib added a subscriber: pho.

Peter, could you, please, test this change ?

In D19615#420270, @kib wrote:

Peter, could you, please, test this change ?

I ran all of the stress2 tests + a buildworld on amd64. No problems seen.

This revision was automatically updated to reflect the committed changes.