-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix] Add a nullptr check to tir.Buffer to fix the illegal memory access #8910
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @syang-ng . It would be great to add a unit test case to cover this bug. |
I have added a test case to cover this problem. Could you help review my new commit? Thanks! @tqchen @junrushao1994 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just curious why the data_
will be nullptr
@Hzfengsy in the example below: buf = tir.decl_buffer((1,), name='buf') which actually indicates: buf = tir.decl_buffer(data=None, shape=(1,), name='buf') I suppose it won't happen in our common workflow, but is an adversarial case when using our APIs in an arbitrary way |
Thanks @syang-ng for the enhancement! |
…access (apache#8910) * fix wrong log of tir pass VerifyMemory * fix a typo of convention * add a nullptr check to tir buffer * add test case to trigger buffer nullptr bug * update the style to fix ci error
…access (apache#8910) * fix wrong log of tir pass VerifyMemory * fix a typo of convention * add a nullptr check to tir buffer * add test case to trigger buffer nullptr bug * update the style to fix ci error
Bug Description
I found there will be a segfault when we try to load a buffer whose
data_
points tonullptr
.Here is the code to trigger the segmentation fault error.
Bug Analysis
If we call the function
tvm.build(buf_func)
, it will executeBuffer::vload()
in src/tir/ir/buffer.cc:Since
n
might benullptr
,n->dtype.element_of()
will actually access the illegal memory address, then a segfault occurs.So to prevent illegal memory access, it's necessary to add a checker to check whether
n
points to a valid object. And I also found the similar checkers had been added into TVM such as line 40 in include/tvm/ir/env_func.h:Thus, I add the checker in
src/tir/ir/buffer.cc
to prevent illegal memory access in this commit.As
tvm::tir::Buffer
extends fromtvm::runtime::Object
, it can also solve the problem by adding the checkers totvm::runtime::Object
.