Skip to content

Commit

Permalink
[compiler] fix UAF on getBytecodeProducerString() (#183)
Browse files Browse the repository at this point in the history
* fix UAF: `BytecodeWriterConfig` accepts a `StringRef`.
* export torch_frontend.DebugType
  • Loading branch information
qingyunqu authored Apr 7, 2024
1 parent 0399e21 commit fcc858f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion compiler/lib/CAPI/Translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ bool byteirSerializeByre(MlirModule module, MlirStringRef targetVersion,
llvm::errs() << errorMessage << "\n";
return false;
}
BytecodeWriterConfig config(serialVersion.getBytecodeProducerString());
std::string producerString = serialVersion.getBytecodeProducerString();
BytecodeWriterConfig config(producerString);
config.setDesiredBytecodeVersion(serialVersion.getBytecodeVersion());
if (failed(writeBytecodeToFile(*newModule, resultMLIRBCFile->os(), config))) {
newModule->emitOpError() << "failed to write bytecode\n";
Expand Down
3 changes: 2 additions & 1 deletion compiler/lib/Dialect/Byre/Transforms/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ struct DumpByrePass : public DumpByreBase<DumpByrePass> {
return signalPassFailure();
}

BytecodeWriterConfig config(targetVersion->getBytecodeProducerString());
std::string producerString = targetVersion->getBytecodeProducerString();
BytecodeWriterConfig config(producerString);
config.setDesiredBytecodeVersion(targetVersion->getBytecodeVersion());
if (failed(writeBytecodeToFile(*newModule, ofile->os(), config))) {
newModule->emitOpError() << "failed to write bytecode\n";
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/lib/Transformation/TestByreSerialRoundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ struct TestByreSerialRoundtripPass

std::string buffer;
llvm::raw_string_ostream ostream(buffer);
BytecodeWriterConfig config(targetVersion.getBytecodeProducerString());
std::string producerString = targetVersion.getBytecodeProducerString();
BytecodeWriterConfig config(producerString);
config.setDesiredBytecodeVersion(targetVersion.getBytecodeVersion());
if (failed(writeBytecodeToFile(*newModule, ostream, config))) {
newModule->emitOpError() << "failed to write bytecode\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from ._mlir_libs._torchFrontend import *

from .compile import DebugType

from .fx_utils import list_decomposed_ops, preprocess_fx_graph, get_none_indices
from .compile import convert_to_mhlo_via_torch_mlir, compile, compile_dynamo_model
from .flash_attn_op import replace_flash_attn
Expand Down

0 comments on commit fcc858f

Please sign in to comment.