Repository navigation
squid: mgr/PyFormatter: prevent segfault on non-printable characters - #71565
Conversation
30b1e3a to
eb9246f
Compare
|
This PR has been added to wip-bharath11-testing-20260908.043338-squid. |
|
@NitzanMordhai maybe a word about why you dropped the test in the Squid backport may placate the release engineering audit gods :P |
Yes, sorry. NitzanMordhai@535ae6d never backported. The changes are not in squid. And it is based on other functions that were added in that related PR #66432 |
If PyFormatter::dump_string attempting to format non-printable characters can result in a nullptr being passed to dump_pyobject, causing a segfault. It occured in the following case - crash module tried to load the crash entries containing matedata with non-printable characters. when these were passed to PyFormatter, the resulting crash prevented ceph-mgr from starting. Fix this by attempting to create a python object using PyUnicode_FromString. If it returns nullptr (indicating a decoding failure), the code now falls back to decoding using Latin1. Additionally, add a guard in dump_pyobject to prevent processing nullptr objects, providing a secondary layer of protection against segfaults. Fixes: https://tracker.ceph.com/issues/74379 Signed-off-by: Nitzan Mordechai <[email protected]> (cherry picked from commit 7c68a00) Conflicts: - src/mgr/PyFormatter.h Original: 7c68a00#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b Backport: 30b1e3a#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b - TTL Cache was never backported to squid, change remove "protected" - src/test/mgr/test_pyformatter.cc Original: 7c68a00#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c Backport: 30b1e3a#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c Test suite didn't backported to squid, delete the file
eb9246f to
dfbb4a9
Compare
|
/audit retest |
|
🔄 Audit Retest Triggered by @NitzanMordhai. |
There was a problem hiding this comment.
Ceph Release Engineering Audit Report
Commit Parity Visualizer
| BACKPORT PR #71565 | SOURCE PR |
SOURCE STATUS |
|---|---|---|
| dfbb4a9 mgr/PyFormatter: prevent segfault on non-printable characters | PR #67022 | 7c68a00 mgr/PyFormatter: prevent segfault on non-printable characters |
Automated Backport Parity Review - Cherry-Pick Conflicts / Deviations
A conflict or deviation was detected during the simulation of this backport. The code in this PR does not match a clean cherry-pick of the upstream commits.
This does not necessarily indicate an issue but a maintainer should review.
**Click to expand conflict summaries.**
Deviation in Backport dfbb4a9 (cherry-pick of 7c68a00)
Affected File(s)
src/mgr/PyFormatter.hsrc/test/mgr/test_pyformatter.cc
Range Diff
Click to expand
--- Original (7c68a00c)
+++ Backport (dfbb4a9b)
@@ -16,3 +16,15 @@
Fixes: https://tracker.ceph.com/issues/74379
Signed-off-by: Nitzan Mordechai <[email protected]>
+(cherry picked from commit 7c68a00cce5b7769c2e34fb7611d14825283fcda)
+
+Conflicts:
+ - src/mgr/PyFormatter.h
+ Original: 7c68a00#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b
+ Backport: 30b1e3a#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b
+ - TTL Cache was never backported to squid, change remove "protected"
+
+ - src/test/mgr/test_pyformatter.cc
+ Original: 7c68a00#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c
+ Backport: 30b1e3a#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c
+ Test suite didn't backported to squid, delete the file
================================================================================
RANGE DIFF
================================================================================
1: 7c68a00cce5 ! 1: dfbb4a9b0d0 mgr/PyFormatter: prevent segfault on non-printable characters
@@ Commit message
Fixes: https://tracker.ceph.com/issues/74379
Signed-off-by: Nitzan Mordechai <[email protected]>
+ (cherry picked from commit 7c68a00cce5b7769c2e34fb7611d14825283fcda)
+
+ Conflicts:
+ - src/mgr/PyFormatter.h
+ Original: 7c68a00#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b
+ Backport: 30b1e3a#diff-ac7d387d13545f28de056e1a55bc5f73ec7b3e1bafd077355a3a2349b741489b
+ - TTL Cache was never backported to squid, change remove "protected"
+
+ - src/test/mgr/test_pyformatter.cc
+ Original: 7c68a00#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c
+ Backport: 30b1e3a#diff-d5583b1cec8167f6ad854612d3c99940b73b8c2a4e61008a1699dc2fb86bbc4c
+ Test suite didn't backported to squid, delete the file
## src/mgr/ActivePyModules.cc ##
@@ src/mgr/ActivePyModules.cc: PyObject *ActivePyModules::get_store_prefix(const std::string &module_name,
@@ src/mgr/PyFormatter.h: public:
+ void dump_pyobject(std::string_view name, PyObject *p);
+
- protected:
+ private:
PyObject *root;
PyObject *cursor;
std::stack<PyObject *> stack;
+
- void dump_pyobject(std::string_view name, PyObject *p);
- private:
+-
class PendingStream {
public:
-
- ## src/test/mgr/test_pyformatter.cc ##
-@@ src/test/mgr/test_pyformatter.cc: TEST(PyFormatter, EmptySectionName)
-
- /* End Negative Tests */
-
-+TEST(PyFormatter, DumpPyObject_StoresPrebuiltObject)
-+{
-+ // Verify that dump_pyobject inserts a caller-owned PyObject into the dict
-+ // without re-encoding, which is the pattern used in get_store_prefix.
-+ PyFormatter py_f;
-+ PyObject *value = PyUnicode_FromString("hello");
-+ ASSERT_NE(value, nullptr);
-+ py_f.dump_pyobject("key", value);
-+
-+ PyObject *result = py_f.get();
-+ ASSERT_NE(result, nullptr);
-+ ASSERT_TRUE(PyDict_Check(result));
-+
-+ PyObject *item = PyDict_GetItemString(result, "key");
-+ ASSERT_NE(item, nullptr);
-+ ASSERT_TRUE(PyUnicode_Check(item));
-+ ASSERT_STREQ(PyUnicode_AsUTF8(item), "hello");
-+
-+ Py_DECREF(result);
-+}
-+
-+TEST(PyFormatter, DumpString_SkipsNonUtf8Value)
-+{
-+ // dump_string uses PyUnicode_FromStringAndSize which fails on invalid UTF-8.
-+ // The method must not crash and must simply skip the key.
-+ PyFormatter py_f;
-+ // "\x80\xff" is invalid UTF-8
-+ std::string bad_utf8("\x80\xff", 2);
-+ py_f.dump_string("bad_key", bad_utf8);
-+
-+ PyObject *result = py_f.get();
-+ ASSERT_NE(result, nullptr);
-+ ASSERT_TRUE(PyDict_Check(result));
-+
-+ // Key must be absent — dump_string skips on encoding failure
-+ PyObject *item = PyDict_GetItemString(result, "bad_key");
-+ ASSERT_EQ(item, nullptr);
-+
-+ Py_DECREF(result);
-+}
-+
-+TEST(PyFormatter, DumpPyObject_NonUtf8ViLatin1Fallback)
-+{
-+ // This is the pattern used in get_store_prefix to handle crash metadata
-+ // containing non-printable / non-UTF-8 bytes: try UTF-8, fall back to
-+ // Latin-1, then call dump_pyobject directly with the validated PyObject*.
-+ PyFormatter py_f;
-+ std::string bad_utf8("\x80\xff", 2);
-+
-+ PyObject *value = PyUnicode_FromStringAndSize(bad_utf8.c_str(), bad_utf8.size());
-+ if (!value) {
-+ PyErr_Clear();
-+ value = PyUnicode_DecodeLatin1(bad_utf8.c_str(), bad_utf8.size(), nullptr);
-+ }
-+ ASSERT_NE(value, nullptr); // Latin-1 must always succeed
-+ py_f.dump_pyobject("latin1_key", value);
-+
-+ PyObject *result = py_f.get();
-+ ASSERT_NE(result, nullptr);
-+ ASSERT_TRUE(PyDict_Check(result));
-+
-+ // Key must be present — Latin-1 fallback succeeded
-+ PyObject *item = PyDict_GetItemString(result, "latin1_key");
-+ ASSERT_NE(item, nullptr);
-+ ASSERT_TRUE(PyUnicode_Check(item));
-+
-+ Py_DECREF(result);
-+}
-+
-+
- /*
- * Tests for PyFormatterRO (read-only-on-the-fly builder):
- * - lists -> tuples, sets -> frozensets
+ PyObject *cursor;How to proceed:
- Authors (Genuine Conflicts): If this is a genuine conflict requiring manual resolution, ensure your resolution is correct. You must explain the conflict resolution in the commit message (e.g., leave the standard Git
Conflicts:block intact) and include an explanation for changes. - Authors (Need Help?): Reach out to the Component Lead for technical guidance on complex code conflicts.
- Component Leads (Review): Please review the Range Diff(s) above to verify the author's manual conflict resolution is correct for this release branch. If the deviation is intentional, documented, and approved then the component lead or @ceph/ceph-release-manager can bypass this check by commenting
/audit override.
Be familiar with the rules and guidelines for writing backports.
🛟 Need Help?
If you need technical help resolving these issues, please consult with the Component Lead. If you need administrative overrides, please see the #ceph-upstream-releases channel on Slack and request a review from the @ceph/ceph-release-manager.
📋 Component Lead / Release Manager
To override the audit failure, apply releng-audit-override label or comment /audit override.
When you are ready for a new audit, please remove the releng-audit-fail label or comment /audit retest.
|
✅ Audit Override Applied by @ljflores. |
Overrode the audit based on this comment. |
backport tracker: https://tracker.ceph.com/issues/80036
backport of #67022
parent tracker: https://tracker.ceph.com/issues/74379
this backport was staged using ceph-backport.sh version 16.0.0.6848
find the latest version at https://github.com/ceph/ceph/blob/main/src/script/ceph-backport.sh