Blame SOURCES/rhbz1643997.0027-PR23860-reduce-stack-pressure-from-format-strings.patch

e4e640
From 59ec363d7236d92f896135ef8fe85433d6f1995e Mon Sep 17 00:00:00 2001
e4e640
From: Serhei Makarov <smakarov@redhat.com>
e4e640
Date: Fri, 9 Nov 2018 16:24:09 -0500
e4e640
Subject: [PATCH 27/32] PR23860: reduce stack pressure from format strings
e4e640
e4e640
Reduce stack pressure created by the earlier commits by allocating
e4e640
format strings in a predictable location in the top half of the stack
e4e640
[-BPF_MAXSTRINGLEN*2..0) as long as they fit in there. This works
e4e640
since only one format string is active at a time and no ordinary
e4e640
strings are being allocated in that region of the stack now.
e4e640
e4e640
* bpf-opt.cxx (alloc_literal_str): Store format_str in top half.
e4e640
---
e4e640
 bpf-opt.cxx | 11 +++++++++++
e4e640
 1 file changed, 11 insertions(+)
e4e640
e4e640
diff --git a/bpf-opt.cxx b/bpf-opt.cxx
e4e640
index f3aa5c462..5c7acb6b9 100644
e4e640
--- a/bpf-opt.cxx
e4e640
+++ b/bpf-opt.cxx
e4e640
@@ -27,6 +27,16 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
e4e640
   str_bytes += 4 - str_bytes % 4; // write aligned words to avoid garbage data
e4e640
 
e4e640
   int ofs; size_t tmp_space;
e4e640
+  if (s->is_format() && str_bytes <= BPF_MAXSTRINGLEN * 2)
e4e640
+    {
e4e640
+      // PR23068 workaround mitigation to reduce stack pressure:
e4e640
+      //
e4e640
+      // Store format strings in the top of the stack, since at most
e4e640
+      // one printf() operation is prepared at a time and other string
e4e640
+      // values will not be stored in that area now.
e4e640
+      ofs = -str_bytes;
e4e640
+      goto write_string;
e4e640
+    }
e4e640
 
e4e640
   // Append the string to existing temporary data.
e4e640
   //
e4e640
@@ -65,6 +75,7 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
e4e640
   p.use_tmp_space(tmp_space);
e4e640
   ofs = -tmp_space;
e4e640
 
e4e640
+ write_string:
e4e640
   value *frame = p.lookup_reg(BPF_REG_10);
e4e640
   value *out = emit_simple_literal_str(p, ins, frame, ofs, str, false /* don't zero pad */);
e4e640
   return out;
e4e640
-- 
e4e640
2.14.5
e4e640