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

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