Page MenuHomeFreeBSD

riscv: fix VM_MAXUSER_ADDRESS checks in asm routines
ClosedPublic

Authored by mhorne on Jul 17 2021, 7:50 PM.
Tags
None
Referenced Files
F102910294: D31209.diff
Mon, Nov 18, 3:32 PM
Unknown Object (File)
Thu, Nov 7, 8:27 PM
Unknown Object (File)
Sep 28 2024, 12:50 PM
Unknown Object (File)
Sep 27 2024, 7:02 AM
Unknown Object (File)
Sep 26 2024, 5:03 AM
Unknown Object (File)
Sep 24 2024, 5:33 PM
Unknown Object (File)
Sep 24 2024, 4:01 PM
Unknown Object (File)
Sep 24 2024, 9:08 AM
Subscribers

Details

Summary

There are two issues with the checks against VM_MAXUSER_ADDRESS. First,
the comparison should consider the values as unsigned, otherwise
addresses with the high bit set will fail to branch. Second, the value
of VM_MAXUSER_ADDRESS is, by convention, one larger than the maximum
mappable user address and invalid itself. Thus, use the bgeu instruction
for these comparisons.

PR: 257193
Reported by: Robert Morris <rtm@lcs.mit.edu>

Test Plan

With this change, the test cases in PR 257193 will terminate as expected.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 40513
Build 37402: arc lint + arc unit

Event Timeline

This bug is also repeated in support.S for all the fu/su/casu functions

This bug is also repeated in support.S for all the fu/su/casu functions

Indeed, thanks for catching this. I will include those in this review.

Is it straightforward to add at least a copyin() test for this case, in tests/sys/kern_copyin.c?

With this change, the test cases in PR 253706 will terminate as expected.

Wrong PR number, in case you were planning to include this sentence in the commit log.

Apply the change to routines in support.S as well.

Add a test case to kern_copyin.c. It seems the hang cannot be triggered with a call to write(2), so use fcntl(2) as is done in the PR.

mhorne retitled this revision from riscv: fix bounds checking in copyinout.S routines to riscv: fix VM_MAXUSER_ADDRESS checks in asm routines.Oct 5 2021, 6:10 PM

Add a test case to kern_copyin.c.

Thanks.

It seems the hang cannot be triggered with a call to write(2), so use fcntl(2) as is done in the PR.

Any idea why?

This revision is now accepted and ready to land.Oct 6 2021, 1:15 PM

Add a test case to kern_copyin.c.

Thanks.

It seems the hang cannot be triggered with a call to write(2), so use fcntl(2) as is done in the PR.

Any idea why?

I looked for a bit but could not pinpoint it by code inspection. The path through the write(2) syscall to where copyin() is invoked is much more involved.

I suppose we eventually make it to ffs_write(), where one of vn_io_fault_uiomove() or vn_io_fault_pgmove() is called for the relevant uio. I _think_ the latter would cause the behaviour we are seeing, but I am not sure. I would expect the former to trigger the copyin() bug.