This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Mark before deref in PosixSpawnImpl
ClosedPublic

Authored by tamird on Nov 2 2021, 1:28 PM.

Details

Summary

Read each pointer in the argv and envp arrays before dereferencing it;
this correctly marks an error when these pointers point into memory that
has been freed.

Also accept nullptr argv and envp on Linux. Per the posix_spawn manual:

The argv and envp arguments specify the argument list and environment
for the program that is executed in the child process, as for execve(2).

and then the execve manual:

On Linux, argv and envp can be specified as NULL. In both cases, this
has the same effect as specifying the argument as a pointer to a list
containing a single null pointer.

Diff Detail

Event Timeline

tamird requested review of this revision.Nov 2 2021, 1:28 PM
tamird created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2021, 1:28 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
tamird updated this revision to Diff 384209.Nov 2 2021, 1:39 PM
  • Deref after marking pointer as read
  • Allow nullptr argv and envp on Linux per the man page
tamird updated this revision to Diff 384210.Nov 2 2021, 1:42 PM

Pass length rather than end

tamird updated this revision to Diff 384215.Nov 2 2021, 1:46 PM

Read sizeof rather than 1

vitalybuka added inline comments.Nov 2 2021, 2:09 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
2435

Hm, somehow I missed it, however I don't see envp == null in man page.
Lets keep them both.
And can you please remove #if, and do that for all platforms.

2438

I don't think order of the check is important. Main goal is to stop invalid call, and it should happens in both cases.

However I don't see why it was off by 1

vitalybuka added inline comments.Nov 2 2021, 2:15 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
2438

I don't think order of the check is important. Main goal is to stop invalid call, and it should happens in both cases.

Ignore this part, you patch is definitely improvement.

However I don't see why it was off by 1

Still I'd like to see answer to this.

tamird updated this revision to Diff 384232.Nov 2 2021, 2:23 PM

De-special case Linux; amend description

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
2435

From the posix_spawn man page:

The argv and envp arguments specify the argument list and environment for the program that is executed in the child process, as for execve(2).

From the execve man page:

On Linux, argv and envp can be specified as NULL.

Done (removed #if).

2438

Ah, I think you're right that it wasn't off by 1; I've updated the commit message.

phosek added a subscriber: phosek.Nov 2 2021, 2:27 PM
vitalybuka accepted this revision.Nov 2 2021, 3:03 PM
This revision is now accepted and ready to land.Nov 2 2021, 3:03 PM
tamird added a comment.Nov 2 2021, 3:44 PM

Could someone commit this for me? I don't have access.

tamird updated this revision to Diff 384274.Nov 2 2021, 4:31 PM
tamird retitled this revision from [sanitizer] Fix PosixSpawnImpl off-by-one to [sanitizer] Mark before deref in PosixSpawnImpl.
tamird edited the summary of this revision. (Show Details)

Update message

This revision was automatically updated to reflect the committed changes.