Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

sles 15.2
tmpfile weakness #43


Weakness Breakdown


A temporary file weakness occurs when a temporary file that is created and used by a high-privilege process is accidentally shared with a low-privilege process, on account of it being temporary and generated after all security controls have been applied. This allows the low-privilege process to read data from the high-privilege process (information leakage), or worse, influence the high-privilege process by modifying the shared temporary file.

Warning code(s):

Temporary file race condition.

File Name:



The highlighted line of code below is the trigger point of this particular Sles 15.2 tmpfile weakness.

   path_template_size = strlen(path_template) + 1;
  error = _mktemp_s(path_template, path_template_size);
  if (error != 0) {
    return -1;

  error = _sopen_s(&fd,
                   _O_RDWR | _O_CREAT | _O_EXCL | _O_BINARY,
                   _S_IREAD | _S_IWRITE);
  if (error != 0) {
    return -1;

  return fd;
#else /* WIN32 */
grn_mkstemp(char *path_template)
  return mkstemp(path_template);
# else /* HAVE_MKSTEMP */
  return open(path_template, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
# endif /* HAVE_MKSTEMP */
#endif /* WIN32 */

grn_path_exist(const char *path)
  struct stat status;
  return stat(path, &status) == 0;

/* todo : refine */
 * grn_tokenize splits a string into at most buf_size tokens and
 * returns the number of tokens. The ending address of each token is
 * written into tokbuf. Delimiters are ' ' and ','.
 * Then, the address to the remaining is set to rest.
grn_tokenize(const char *str, size_t str_len,
             const char **tokbuf, int buf_size,
             const char **rest)
  const char **tok = tokbuf, **tok_end = tokbuf + buf_size; 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.