-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[flang][mlir] Fix-forward heap use-after-free in #155348 #164712
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
Conversation
mapInfoOp should not be accessed here because cloneModifyAndErase (line 255) erased it. Fix the issue by replacing mapInfoOp with the cloned op.
|
@llvm/pr-subscribers-mlir-openmp Author: Thurston Dang (thurstond) Changes
Full diff: https://github.com/llvm/llvm-project/pull/164712.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
index 735b905bffb85..dafc1cbacdac7 100644
--- a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
+++ b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
@@ -252,7 +252,8 @@ class PrepareForOMPOffloadPrivatizationPass
// variable, rewrite all the uses of the original variable with
// the heap-allocated variable.
rewriter.setInsertionPoint(targetOp);
- rewriter.setInsertionPoint(cloneModifyAndErase(mapInfoOp));
+ mapInfoOp = cloneModifyAndErase(mapInfoOp);
+ rewriter.setInsertionPoint(mapInfoOp);
// Fix any members that may use varPtr to now use heapMem
for (auto member : mapInfoOp.getMembers()) {
|
|
@llvm/pr-subscribers-mlir Author: Thurston Dang (thurstond) Changes
Full diff: https://github.com/llvm/llvm-project/pull/164712.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
index 735b905bffb85..dafc1cbacdac7 100644
--- a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
+++ b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
@@ -252,7 +252,8 @@ class PrepareForOMPOffloadPrivatizationPass
// variable, rewrite all the uses of the original variable with
// the heap-allocated variable.
rewriter.setInsertionPoint(targetOp);
- rewriter.setInsertionPoint(cloneModifyAndErase(mapInfoOp));
+ mapInfoOp = cloneModifyAndErase(mapInfoOp);
+ rewriter.setInsertionPoint(mapInfoOp);
// Fix any members that may use varPtr to now use heapMem
for (auto member : mapInfoOp.getMembers()) {
|
|
@llvm/pr-subscribers-flang-openmp Author: Thurston Dang (thurstond) Changes
Full diff: https://github.com/llvm/llvm-project/pull/164712.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
index 735b905bffb85..dafc1cbacdac7 100644
--- a/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
+++ b/mlir/lib/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.cpp
@@ -252,7 +252,8 @@ class PrepareForOMPOffloadPrivatizationPass
// variable, rewrite all the uses of the original variable with
// the heap-allocated variable.
rewriter.setInsertionPoint(targetOp);
- rewriter.setInsertionPoint(cloneModifyAndErase(mapInfoOp));
+ mapInfoOp = cloneModifyAndErase(mapInfoOp);
+ rewriter.setInsertionPoint(mapInfoOp);
// Fix any members that may use varPtr to now use heapMem
for (auto member : mapInfoOp.getMembers()) {
|
| // the heap-allocated variable. | ||
| rewriter.setInsertionPoint(targetOp); | ||
| rewriter.setInsertionPoint(cloneModifyAndErase(mapInfoOp)); | ||
| auto clonedOp = cast<omp::MapInfoOp>(cloneModifyAndErase(mapInfoOp)); |
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.
Why not just updating it:
| auto clonedOp = cast<omp::MapInfoOp>(cloneModifyAndErase(mapInfoOp)); | |
| mapInfoOp = cast<omp::MapInfoOp>(cloneModifyAndErase(mapInfoOp)); |
That way no risk of misusing mapInfoOp anymore?
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.
Good idea, thanks! Done: 7fdd34a
Also fix another use-after-free
|
@joker-eph I updated the patch to fix a second-use-after-free |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
…4712) `mapInfoOp.getMembers()` on line 258 is use-after-free, because cloneModifyAndErase (line 255) erased `mapInfoOp`. Fix the issue by replacing subsequent `mapInfoOp` usages with `clonedOp`. Similarly, update `memberMapInfoOp` to avoid subsequent use-after-free.
…4712) `mapInfoOp.getMembers()` on line 258 is use-after-free, because cloneModifyAndErase (line 255) erased `mapInfoOp`. Fix the issue by replacing subsequent `mapInfoOp` usages with `clonedOp`. Similarly, update `memberMapInfoOp` to avoid subsequent use-after-free.
…4712) `mapInfoOp.getMembers()` on line 258 is use-after-free, because cloneModifyAndErase (line 255) erased `mapInfoOp`. Fix the issue by replacing subsequent `mapInfoOp` usages with `clonedOp`. Similarly, update `memberMapInfoOp` to avoid subsequent use-after-free.
…4712) `mapInfoOp.getMembers()` on line 258 is use-after-free, because cloneModifyAndErase (line 255) erased `mapInfoOp`. Fix the issue by replacing subsequent `mapInfoOp` usages with `clonedOp`. Similarly, update `memberMapInfoOp` to avoid subsequent use-after-free.
mapInfoOp.getMembers()on line 258 is use-after-free, because cloneModifyAndErase (line 255) erasedmapInfoOp. Fix the issue by replacing subsequentmapInfoOpusages withclonedOp.Similarly, update
memberMapInfoOpto avoid subsequent use-after-free.