summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/flash/phosphor-software-manager/0010-Add-error-reporting-to-pfr_image_manager.patch
blob: e72398efd8ce558f27ffd606f950b6c106c0ac1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From ffa3642e436b559d8062f777f00458cc7b5ecb01 Mon Sep 17 00:00:00 2001
From: James Feist <james.feist@linux.intel.com>
Date: Thu, 11 Jun 2020 13:30:02 -0700
Subject: [PATCH 1/1] Add error reporting to pfr_image_manager

This uses report functionality to update error
return status for redfish updates.

Tested: Got 400 error with different messages based
on failure type

{
    "error": {
        "@Message.ExtendedInfo": [
            {
                "@odata.type": "/redfish/v1/$metadata#Message.v1_0_0.Message",
                "Message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid archive.",
                "MessageArgs": [
                    "/redfish/v1/UpdateService",
                    "invalid archive"
                ],
                "MessageId": "OpenBMC.0.1.0.InvalidFile",
                "Resolution": "None.",
                "Severity": "Warning"
            }
        ],
        "code": "OpenBMC.0.1.0.InvalidFile",
        "message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid archive."
    }
}

{
    "error": {
        "@Message.ExtendedInfo": [
            {
                "@odata.type": "/redfish/v1/$metadata#Message.v1_0_0.Message",
                "Message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid image format.",
                "MessageArgs": [
                    "/redfish/v1/UpdateService",
                    "invalid image format"
                ],
                "MessageId": "OpenBMC.0.1.0.InvalidFile",
                "Resolution": "None.",
                "Severity": "Warning"
            }
        ],
        "code": "OpenBMC.0.1.0.InvalidFile",
        "message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid image format."
    }
}

{
    "error": {
        "@Message.ExtendedInfo": [
            {
                "@odata.type": "#Message.v1_0_0.Message",
                "Message": "The resource /redfish/v1/UpdateService was unable to satisfy the request due to unavailability of resources.",
                "MessageArgs": [
                    "/redfish/v1/UpdateService"
                ],
                "MessageId": "Base.1.4.0.ResourceExhaustion",
                "Resolution": "Ensure that the resources are available and resubmit the request.",
                "Severity": "Critical"
            }
        ],
        "code": "Base.1.4.0.ResourceExhaustion",
        "message": "The resource /redfish/v1/UpdateService was unable to satisfy the request due to unavailability of resources."
    }
}

Signed-off-by: James Feist <james.feist@linux.intel.com>
---
 dbus_helpers.hpp      | 30 ++++++++++++++++++++++++++++++
 pfr_image_manager.cpp | 18 ++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 dbus_helpers.hpp

diff --git a/dbus_helpers.hpp b/dbus_helpers.hpp
new file mode 100644
index 0000000..b9ffa36
--- /dev/null
+++ b/dbus_helpers.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "config.h"
+
+#include <sdbusplus/bus.hpp>
+inline bool isFwupdScriptRunning(sdbusplus::bus::bus& bus)
+{
+    using ObjectPath = sdbusplus::message::object_path;
+    // type is ssssssouso
+    using ListUnitsType =
+        std::tuple<std::string, std::string, std::string, std::string,
+                   std::string, std::string, ObjectPath, uint32_t, std::string,
+                   ObjectPath>;
+    auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+                                      SYSTEMD_INTERFACE, "ListUnits");
+
+    auto reply = bus.call(method);
+    std::vector<ListUnitsType> resp;
+    reply.read(resp);
+
+    for (const auto& unit : resp)
+    {
+        if (std::get<0>(unit).find("fwupd@") != std::string::npos &&
+            std::get<3>(unit) != "failed")
+        {
+            return true;
+        }
+    }
+    return false;
+}
diff --git a/pfr_image_manager.cpp b/pfr_image_manager.cpp
index 1a41cbe..fe1e6f9 100644
--- a/pfr_image_manager.cpp
+++ b/pfr_image_manager.cpp
@@ -2,6 +2,7 @@
 
 #include "pfr_image_manager.hpp"
 
+#include "dbus_helpers.hpp"
 #include "version.hpp"
 #include "watch.hpp"
 
@@ -33,6 +34,9 @@ namespace manager
 
 using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error;
 namespace Software = phosphor::logging::xyz::openbmc_project::Software;
+using UnTarFail = Software::Image::UnTarFailure;
+using ImageFail = Software::Image::ImageFailure;
+using BusyFail = Software::Image::BusyFailure;
 
 static constexpr const uint32_t pfmPos = 2054;
 static constexpr const uint32_t block0Magic = 0xB6EAFD19;
@@ -76,6 +80,8 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath,
                 phosphor::logging::log<phosphor::logging::level::ERR>(
                     "Image magic number match failed",
                     phosphor::logging::entry("IMAGEMAGIC=0x%x", imgMagic));
+                phosphor::logging::report<UnTarFailure>(
+                    UnTarFail::PATH(imgPath.c_str()));
                 return -1;
             }
 
@@ -110,6 +116,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath,
 
                 phosphor::logging::log<phosphor::logging::level::ERR>(
                     "Unknown image type");
+                phosphor::logging::report<ImageFailure>(
+                    ImageFail::FAIL("Unknown image type"),
+                    ImageFail::PATH(imgPath.c_str()));
                 return -1;
             }
 
@@ -153,6 +162,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath,
                                 "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s",
                                 redfishMsgID.c_str(), "REDFISH_MESSAGE_ARGS=%s",
                                 "Image HASH check fail", NULL);
+                phosphor::logging::report<ImageFailure>(
+                    ImageFail::FAIL("Security violation: hash mismatch"),
+                    ImageFail::PATH(imgPath.c_str()));
                 return -1;
             }
 
@@ -167,6 +179,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath,
         catch (std::exception& e)
         {
             phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+            phosphor::logging::report<ImageFailure>(
+                ImageFail::FAIL("Unhandled exception"),
+                ImageFail::PATH(imgPath.c_str()));
             return -1;
         }
     }
@@ -182,6 +197,12 @@ int Manager::processImage(const std::string& imgFilePath)
     if (!std::filesystem::exists(imgPath))
         return -1;
 
+    if (isFwupdScriptRunning(bus))
+    {
+        phosphor::logging::report<BusyFailure>(BusyFail::PATH(imgPath.c_str()));
+        return -1;
+    }
+
     int retry = 3;
     std::string ver;
     std::string purposeString;
-- 
2.17.1