blob: c3f4fca51b627d8be5d13bb92ef3c35b5c1ffa47 [file] [log] [blame]
Andrew Jefferyc7d19472018-08-08 11:43:08 +09301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include "config.h"
4
5extern "C" {
Andrew Jeffery26558db2018-08-10 00:22:38 +09306#include "mboxd.h"
Andrew Jefferyc7d19472018-08-08 11:43:08 +09307#include "protocol.h"
8#include "vpnor/protocol.h"
9}
10
11#include "vpnor/pnor_partition_table.hpp"
12
13/* XXX: Maybe this should be a method on a class? */
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070014static bool vpnor_partition_is_readonly(const pnor_partition& part)
Andrew Jefferyc7d19472018-08-08 11:43:08 +093015{
16 return part.data.user.data[1] & PARTITION_READONLY;
17}
18
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070019typedef int (*create_window_fn)(struct mbox_context* context,
20 struct protocol_create_window* io);
Andrew Jefferyc7d19472018-08-08 11:43:08 +093021
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070022static int generic_vpnor_create_window(struct mbox_context* context,
23 struct protocol_create_window* io,
Andrew Jefferyc7d19472018-08-08 11:43:08 +093024 create_window_fn create_window)
25{
26 if (io->req.ro)
27 {
28 return create_window(context, io);
29 }
30
31 /* Only allow write windows on regions mapped by the ToC as writeable */
32 size_t offset = io->req.offset;
33 offset <<= context->block_size_shift;
34 try
35 {
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070036 const pnor_partition& part = context->vpnor->table->partition(offset);
Andrew Jefferyc7d19472018-08-08 11:43:08 +093037 if (vpnor_partition_is_readonly(part))
38 {
39 return -EPERM;
40 }
41 }
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070042 catch (const openpower::virtual_pnor::UnmappedOffset& e)
Andrew Jefferyc7d19472018-08-08 11:43:08 +093043 {
44 /*
45 * Writes to unmapped areas are not meaningful, so deny the request.
46 * This removes the ability for a compromised host to abuse unused
47 * space if any data was to be persisted (which it isn't).
48 */
49 return -EACCES;
50 }
51
52 return create_window(context, io);
53}
54
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070055int protocol_v1_vpnor_create_window(struct mbox_context* context,
56 struct protocol_create_window* io)
Andrew Jefferyc7d19472018-08-08 11:43:08 +093057{
58 return generic_vpnor_create_window(context, io, protocol_v1_create_window);
59}
60
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070061int protocol_v2_vpnor_create_window(struct mbox_context* context,
62 struct protocol_create_window* io)
Andrew Jefferyc7d19472018-08-08 11:43:08 +093063{
64 return generic_vpnor_create_window(context, io, protocol_v2_create_window);
65}