From: Pierre Chifflier Date: Sun, 30 Mar 2025 10:03:02 +0000 (+0200) Subject: CVE-2023-35852-1 X-Git-Tag: archive/raspbian/1%6.0.1-3+rpi1+deb11u1^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=45fa60b78ce7f69bae9cd54294ff329b64a419cb;p=suricata.git CVE-2023-35852-1 commit aee1523b4591430ebed1ded0bb95508e6717a335 Author: Jason Ish Date: Tue May 23 15:17:59 2023 -0600 datasets: don't allow absolute or paths with directory traversal For dataset filenames coming from rules, do not allow filenames that are absolute or contain a directory traversal with "..". This prevents datasets from escaping the define data-directory which may allow a bad rule to overwrite any file that Suricata has permission to write to. Add a new configuration option, "datasets.rules.allow-absolute-filenames" to allow absolute filenames in dataset rules. This will be a way to revert back to the pre 6.0.13 behavior where save/state rules could use any filename. Ticket: #6118 Gbp-Pq: Name CVE-2023-35852-1.patch --- diff --git a/src/detect-dataset.c b/src/detect-dataset.c index e3de8c00..de1a5b41 100644 --- a/src/detect-dataset.c +++ b/src/detect-dataset.c @@ -307,8 +307,20 @@ static int SetupSavePath(const DetectEngineCtx *de_ctx, { SCLogDebug("save %s", save); - if (PathIsAbsolute(save)) { - return 0; + int allow_absolute = 0; + (void)ConfGetBool("datasets.rules.allow-absolute-filenames", &allow_absolute); + if (allow_absolute) { + SCLogNotice("Allowing absolute filename for dataset rule: %s", save); + } else { + if (PathIsAbsolute(save)) { + SCLogError(SC_ERR_INVALID_ARGUMENT, "Absolute paths not allowed: %s", save); + return -1; + } + + if (SCPathContainsTraversal(save)) { + SCLogError(SC_ERR_INVALID_ARGUMENT, "Directory traversals not allowed: %s", save); + return -1; + } } // data dir diff --git a/src/util-path.c b/src/util-path.c index de2068dd..22d5e94e 100644 --- a/src/util-path.c +++ b/src/util-path.c @@ -247,3 +247,20 @@ const char *SCBasename(const char *path) return final + 1; } + +/** + * \brief Check for directory traversal + * + * \param path The path string to check for traversal + * + * \retval true if directory traversal is found, otherwise false + */ +bool SCPathContainsTraversal(const char *path) +{ +#ifdef OS_WIN32 + const char *pattern = "..\\"; +#else + const char *pattern = "../"; +#endif + return strstr(path, pattern) != NULL; +} diff --git a/src/util-path.h b/src/util-path.h index 8030b3ad..6f788a8f 100644 --- a/src/util-path.h +++ b/src/util-path.h @@ -41,5 +41,6 @@ bool SCIsRegularDirectory(const struct dirent *const dir_entry); bool SCIsRegularFile(const struct dirent *const dir_entry); char *SCRealPath(const char *path, char *resolved_path); const char *SCBasename(const char *path); +bool SCPathContainsTraversal(const char *path); #endif /* __UTIL_PATH_H__ */ diff --git a/suricata.yaml.in b/suricata.yaml.in index fc18cc7f..8dd81215 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -976,6 +976,12 @@ asn1-max-frames: 256 # defaults: # memcap: 100mb # hashsize: 2048 +# +# rules: +# # Set to true to allow absolute filenames and filenames that use +# # ".." components to reference parent directories in rules that specify +# # their filenames. +# #allow-absolute-filenames: false ############################################################################## ##