Skip to content

Commit

Permalink
issue-1794: fixed use-after-free in fs search by alias, not making a …
Browse files Browse the repository at this point in the history
…new THashMap upon each alias search, removed incorrect TABLET_VERIFY in TIndexTabletActor::CompleteTx_CreateSession (#1816)

* issue-1794: fixed use-after-free in fs search by alias, not making a new THashMap upon each alias search, removed incorrect TABLET_VERIFY in TIndexTabletActor::CompleteTx_CreateSession

* issue-1794: fixed use-after-free in fs search by alias, not making a new THashMap upon each alias search, removed incorrect TABLET_VERIFY in TIndexTabletActor::CompleteTx_CreateSession - fixed comment
  • Loading branch information
qkrorlqr authored Aug 18, 2024
1 parent 64c058d commit 449ede9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
54 changes: 35 additions & 19 deletions cloud/filestore/libs/storage/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ namespace {

////////////////////////////////////////////////////////////////////////////////

// Type alias is used here because using THashMap<TString, TString> inside macro
// will mess it up because of the comma in the type.
using TAliasMap = THashMap<TString, TString>;
using TAliases = NProto::TStorageConfig::TFilestoreAliases;

#define FILESTORE_STORAGE_CONFIG(xxx) \
xxx(SchemeShardDir, TString, "/Root" )\
Expand Down Expand Up @@ -182,11 +180,13 @@ using TAliasMap = THashMap<TString, TString>;
xxx(BlobCompressionRate, ui32, 0 )\
xxx(BlobCompressionCodec, TString, "lz4" )\
\
xxx(FilestoreAliases, TAliasMap, {} )\
\
xxx(MaxZeroCompactionRangesToDeletePerTx, ui32, 10000 )\
// FILESTORE_STORAGE_CONFIG

#define FILESTORE_STORAGE_CONFIG_REF(xxx) \
xxx(FilestoreAliases, TAliases, {} )\
// FILESTORE_STORAGE_CONFIG_REF

#define FILESTORE_DECLARE_CONFIG(name, type, value) \
Y_DECLARE_UNUSED static const type Default##name = value; \
// FILESTORE_DECLARE_CONFIG
Expand All @@ -210,7 +210,7 @@ bool IsEmpty(const NCloud::NProto::TCertificate& value)
}

template <>
bool IsEmpty(const NProto::TStorageConfig::TFilestoreAliases& value)
bool IsEmpty(const TAliases& value)
{
return value.GetEntries().empty();
}
Expand All @@ -227,16 +227,6 @@ TCertificate ConvertValue(const NCloud::NProto::TCertificate& value)
return {value.GetCertFile(), value.GetCertPrivateKeyFile()};
}

template <>
TAliasMap ConvertValue(const NProto::TStorageConfig::TFilestoreAliases& value)
{
TAliasMap result;
for (const auto& entry: value.GetEntries()) {
result[entry.GetAlias()] = entry.GetFsId();
}
return result;
}

template <>
TDuration ConvertValue<TDuration, ui32>(const ui32& value)
{
Expand Down Expand Up @@ -274,11 +264,11 @@ void DumpImpl(const TCertificate& value, IOutputStream& os)
}

template <>
void DumpImpl(const TAliasMap& value, IOutputStream& os)
void DumpImpl(const TAliases& value, IOutputStream& os)
{
os << "{ ";
for (const auto& [alias, fsId]: value) {
os << alias << ": " << fsId << ", ";
for (const auto& x: value.GetEntries()) {
os << x.GetAlias() << ": " << x.GetFsId() << ", ";
}
os << " }";
}
Expand All @@ -299,6 +289,17 @@ FILESTORE_STORAGE_CONFIG(FILESTORE_CONFIG_GETTER)

#undef FILESTORE_CONFIG_GETTER

#define FILESTORE_CONFIG_GETTER_REF(name, type, ...) \
const type& TStorageConfig::Get##name() const \
{ \
return ProtoConfig.Get##name(); \
} \
// FILESTORE_CONFIG_GETTER_REF

FILESTORE_STORAGE_CONFIG_REF(FILESTORE_CONFIG_GETTER_REF)

#undef FILESTORE_CONFIG_GETTER_REF

void TStorageConfig::Dump(IOutputStream& out) const
{
#define FILESTORE_DUMP_CONFIG(name, ...) \
Expand All @@ -308,6 +309,7 @@ void TStorageConfig::Dump(IOutputStream& out) const
// FILESTORE_DUMP_CONFIG

FILESTORE_STORAGE_CONFIG(FILESTORE_DUMP_CONFIG);
FILESTORE_STORAGE_CONFIG_REF(FILESTORE_DUMP_CONFIG);

#undef FILESTORE_DUMP_CONFIG
}
Expand All @@ -325,6 +327,7 @@ void TStorageConfig::DumpHtml(IOutputStream& out) const
TABLE_CLASS("table table-condensed") {
TABLEBODY() {
FILESTORE_STORAGE_CONFIG(FILESTORE_DUMP_CONFIG);
FILESTORE_STORAGE_CONFIG_REF(FILESTORE_DUMP_CONFIG);
}
}
}
Expand All @@ -349,6 +352,7 @@ void TStorageConfig::DumpOverridesHtml(IOutputStream& out) const
TABLE_CLASS("table table-condensed") {
TABLEBODY() {
FILESTORE_STORAGE_CONFIG(FILESTORE_DUMP_CONFIG);
FILESTORE_STORAGE_CONFIG_REF(FILESTORE_DUMP_CONFIG);
}
}
}
Expand Down Expand Up @@ -394,4 +398,16 @@ const NProto::TStorageConfig& TStorageConfig::GetStorageConfigProto() const
return ProtoConfig;
}

const TString* TStorageConfig::FindFileSystemIdByAlias(
const TString& alias) const
{
const auto& entries = GetFilestoreAliases().GetEntries();
for (const auto& entry: entries) {
if (entry.GetAlias() == alias) {
return &entry.GetFsId();
}
}
return nullptr;
}

} // namespace NCloud::NFileStore::NStorage
3 changes: 2 additions & 1 deletion cloud/filestore/libs/storage/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class TStorageConfig

const NProto::TStorageConfig& GetStorageConfigProto() const;

THashMap<TString, TString> GetFilestoreAliases() const;
const NProto::TStorageConfig::TFilestoreAliases& GetFilestoreAliases() const;
const TString* FindFileSystemIdByAlias(const TString& alias) const;
};

} // namespace NCloud::NFileStore::NStorage
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,10 @@ void TStorageServiceActor::HandleCreateSession(

const auto& clientId = GetClientId(msg->Record);
TString fileSystemId = msg->Record.GetFileSystemId();
auto it = StorageConfig->GetFilestoreAliases().find(fileSystemId);
if (it != StorageConfig->GetFilestoreAliases().end()) {
fileSystemId = it->second;
if (const auto* realId =
StorageConfig->FindFileSystemIdByAlias(fileSystemId))
{
fileSystemId = *realId;
}
const auto& checkpointId = msg->Record.GetCheckpointId();
auto originFqdn = GetOriginFqdn(msg->Record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,19 @@ void TIndexTabletActor::CompleteTx_CreateSession(
}

auto* session = FindSession(args.SessionId);
TABLET_VERIFY(session);
if (!session) {
auto message = TStringBuilder() << "Session " << args.SessionId
<< " destroyed during creation";
LOG_WARN(ctx, TFileStoreComponents::TABLET,
"%s %s",
LogTag.c_str(),
message.c_str());

auto response =
std::make_unique<TResponse>(MakeError(E_REJECTED, message));
NCloud::Reply(ctx, *args.RequestInfo, std::move(response));
return;
}

auto response = std::make_unique<TResponse>(args.Error);
response->Record.SetSessionId(std::move(args.SessionId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ void TIndexTabletProxyActor::HandleRequest(

TString fileSystemId = GetFileSystemId(*msg);
// Some filestore names can point to another filestore, set by storage config
auto it = Config->GetFilestoreAliases().find(fileSystemId);
if (it != Config->GetFilestoreAliases().end()) {
fileSystemId = it->second;
if (const auto* realId = Config->FindFileSystemIdByAlias(fileSystemId)) {
fileSystemId = *realId;
}

TConnection& conn = CreateConnection(fileSystemId);
Expand Down

0 comments on commit 449ede9

Please sign in to comment.