Make setSanitizerMetadata byval.
authorMitch Phillips <31459023+hctim@users.noreply.github.com>
Thu, 16 Jun 2022 21:27:38 +0000 (14:27 -0700)
committerMitch Phillips <31459023+hctim@users.noreply.github.com>
Thu, 16 Jun 2022 21:47:27 +0000 (14:47 -0700)
commited5a349b89e9ccc1c3dbe427de27d28e145f8203
treedb395f173b05c52e500a7963a492520161a0660b
parent72c1effb34aa9ae1994f6e1e6b6e6e67ef37b5c8
Make setSanitizerMetadata byval.

This fixes a UaF bug in llvm::GlobalObject::copyAttributesFrom, where a
sanitizer metadata object is captured by reference, and passed by
reference to llvm::GlobalValue::setSanitizerMetadata. The reference
comes from the same map that the new value is going to be inserted to,
and the map insertion triggers iterator invalidation - leading to a
use-after-free on the dangling reference.

This patch fixes that bug by making setSanitizerMetadata's argument
byval. This should also systematically prevent the problem from
happening in future, as it's a very easy pattern to have. This shouldn't
be any performance problem, the SanitizerMetadata struct is a bitfield
POD.
llvm/include/llvm/IR/GlobalValue.h
llvm/lib/IR/Globals.cpp