Remove unneeded session_size check

As accommodating the session component object is already taken care of
be the root component implementation, remove the remaining redundant
checks.

Fixes #4521.
This commit is contained in:
Josef Söntgen 2022-05-31 13:53:03 +02:00 committed by Christian Helmuth
parent d3e53b3cca
commit 0ffc55a20a
19 changed files with 40 additions and 129 deletions

View File

@ -221,13 +221,10 @@ struct Audio_out::Root_policy
{
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota" ).ulong_value(0);
size_t session_size =
align_addr(sizeof(Audio_out::Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > ram_quota - session_size)) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota,
" need ", sizeof(Stream) + session_size);
" need ", sizeof(Stream));
throw Genode::Insufficient_ram_quota();
}
@ -412,13 +409,11 @@ struct Audio_in::Root_policy
void aquire(char const *args)
{
size_t ram_quota = Arg_string::find_arg(args, "ram_quota").ulong_value(0);
size_t session_size = align_addr(sizeof(Audio_in::Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > (ram_quota - session_size))) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota,
" need ", sizeof(Stream) + session_size,
", denying '",Genode::label_from_args(args),"'");
" need ", sizeof(Stream),
", denying '", Genode::label_from_args(args),"'");
throw Genode::Insufficient_ram_quota();
}

View File

@ -1240,14 +1240,9 @@ class Usb::Root : public Genode::Root_component<Session_component>
unsigned long dev = policy.attribute_value<unsigned long>("dev", 0);
unsigned long class_ = policy.attribute_value<unsigned long>("class", 0);
/* check session quota */
size_t session_size = max<size_t>(4096, sizeof(Session_component));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
if (tx_buf_size > ram_quota - session_size) {
if (tx_buf_size > ram_quota) {
warning("Insufficient RAM quota, got ", ram_quota, " need ",
tx_buf_size + session_size);
tx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -292,21 +292,14 @@ class Block::Root : public Genode::Root_component<Block::Session_component,
size_t tx_buf_size =
Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
/* delete ram quota by the memory needed for the session */
size_t session_size = max((size_t)4096,
sizeof(Session_component)
+ sizeof(Allocator_avl));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
/*
* Check if donated ram quota suffices for both
* communication buffers. Also check both sizes separately
* to handle a possible overflow of the sum of both sizes.
*/
if (tx_buf_size > ram_quota - session_size) {
if (tx_buf_size > ram_quota) {
error("insufficient 'ram_quota', got ", ram_quota, ", need ",
tx_buf_size + session_size);
tx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -121,10 +121,7 @@ struct Report::Root : Genode::Root_component<Session_component>
size_t const buffer_size =
Arg_string::find_arg(args, "buffer_size").aligned_size();
size_t const session_size =
max(sizeof(Session_component), 4096U) + buffer_size;
if (ram_quota < session_size) {
if (ram_quota < buffer_size) {
Genode::error("insufficient ram donation from ", label.string());
throw Insufficient_ram_quota();
}

View File

@ -205,13 +205,10 @@ struct Audio_out::Root_policy
{
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota" ).ulong_value(0);
size_t session_size =
align_addr(sizeof(Audio_out::Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > ram_quota - session_size)) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota,
" need ", sizeof(Stream) + session_size);
" need ", sizeof(Stream));
throw Genode::Insufficient_ram_quota();
}

View File

@ -555,14 +555,9 @@ genode_usb_session * ::Root::_create_session(const char * args,
if (!tx_buf_size)
throw Service_denied();
/* check session quota */
size_t session_size = max<size_t>(4096, sizeof(genode_usb_session));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
if (tx_buf_size > ram_quota - session_size) {
if (tx_buf_size > ram_quota) {
warning("Insufficient RAM quota, got ", ram_quota, " need ",
tx_buf_size + session_size);
tx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -127,12 +127,9 @@ class Audio_in::Root : public Audio_in::Root_component
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
size_t session_size = align_addr(sizeof(Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > ram_quota - session_size)) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", sizeof(Stream) + session_size);
"need ", sizeof(Stream));
throw Insufficient_ram_quota();
}

View File

@ -130,12 +130,9 @@ class Audio_out::Root : public Audio_out::Root_component
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
size_t session_size = align_addr(sizeof(Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > ram_quota - session_size)) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", sizeof(Stream) + session_size);
"need ", sizeof(Stream));
throw Insufficient_ram_quota();
}

View File

@ -107,17 +107,6 @@ class Capture::Root : public Capture::Root_component
{
using namespace Genode;
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
size_t session_size = align_addr(sizeof(Session_component), 12);
if ((ram_quota < session_size)) {
Genode::error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", session_size);
throw Insufficient_ram_quota();
}
Session_component *session = new (md_alloc())
Session_component(_env,
session_resources_from_args(args),
@ -125,7 +114,6 @@ class Capture::Root : public Capture::Root_component
session_diag_from_args(args));
return session;
}
void _upgrade_session(Session_component *s, const char *args) override

View File

@ -83,19 +83,14 @@ class Black_hole::Nic_root : public Root_component<Nic_session>
size_t tx_buf_size = Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
size_t rx_buf_size = Arg_string::find_arg(args, "rx_buf_size").ulong_value(0);
/* deplete ram quota by the memory needed for the session structure */
size_t session_size = max(4096UL, (size_t)sizeof(Nic_session));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
/*
* Check if donated ram quota suffices for both communication
* buffers and check for overflow
*/
if (tx_buf_size + rx_buf_size < tx_buf_size ||
tx_buf_size + rx_buf_size > ram_quota - session_size) {
tx_buf_size + rx_buf_size > ram_quota) {
error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", tx_buf_size + rx_buf_size + session_size);
"need ", tx_buf_size + rx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -138,19 +138,14 @@ class Black_hole::Uplink_root : public Root_component<Uplink_session>
size_t tx_buf_size = Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
size_t rx_buf_size = Arg_string::find_arg(args, "rx_buf_size").ulong_value(0);
/* deplete ram quota by the memory needed for the session structure */
size_t session_size = max(4096UL, (size_t)sizeof(Uplink_session));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
/*
* Check if donated ram quota suffices for both communication
* buffers and check for overflow
*/
if (tx_buf_size + rx_buf_size < tx_buf_size ||
tx_buf_size + rx_buf_size > ram_quota - session_size) {
tx_buf_size + rx_buf_size > ram_quota) {
error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", tx_buf_size + rx_buf_size + session_size);
"need ", tx_buf_size + rx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -85,10 +85,7 @@ class Black_hole::Usb_root : public Root_component<Usb_session>
size_t const tx_buf_size {
Arg_string::find_arg(args, "tx_buf_size").ulong_value(0) };
size_t const session_size {
max<size_t>(4096, sizeof(Usb_session)) };
if (ram_quota < session_size + tx_buf_size) {
if (ram_quota < tx_buf_size) {
throw Insufficient_ram_quota { };
}
Ram_dataspace_capability tx_ds { _env.ram().alloc(tx_buf_size) };

View File

@ -230,13 +230,9 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
size_t const buffer_size =
Arg_string::find_arg(args, "buffer_size").aligned_size();
size_t session_size =
max((size_t)4096, sizeof(Session_component)) +
buffer_size;
if (session_size > ram_quota) {
if (buffer_size > ram_quota) {
error("insufficient 'ram_quota' from '", label, "' "
"got ", ram_quota, ", need ", session_size);
"got ", ram_quota, ", need ", buffer_size);
throw Insufficient_ram_quota();
}

View File

@ -618,13 +618,11 @@ class Lx_fs::Root : public Root_component<Session_component>
}
/*
* Check if donated ram quota suffices for session data,
* and communication buffer.
* Check if donated ram quota suffices for communication buffer.
*/
size_t session_size = sizeof(Session_component) + tx_buf_size;
if (max((size_t)4096, session_size) > ram_quota) {
if (tx_buf_size > ram_quota) {
Genode::error("insufficient 'ram_quota', "
"got ", ram_quota, ", need ", session_size);
"got ", ram_quota, ", need ", tx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -706,12 +706,9 @@ class Audio_out::Root : public Audio_out::Root_component
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
size_t session_size = align_addr(sizeof(Session_component), 12);
if ((ram_quota < session_size) ||
(sizeof(Stream) > ram_quota - session_size)) {
if (sizeof(Stream) > ram_quota) {
Genode::error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", sizeof(Stream) + session_size);
"need ", sizeof(Stream));
throw Insufficient_ram_quota();
}

View File

@ -134,21 +134,15 @@ Session_component *Net::Root::_create_session(char const *args)
size_t const rx_buf_size =
Arg_string::find_arg(args, "rx_buf_size").ulong_value(0);
size_t const session_size =
max((size_t)4096, sizeof(Session_component));
if (ram_quota.value < session_size) {
throw Insufficient_ram_quota(); }
if (tx_buf_size > ram_quota.value - session_size ||
rx_buf_size > ram_quota.value - session_size ||
tx_buf_size + rx_buf_size > ram_quota.value - session_size)
if (tx_buf_size > ram_quota.value ||
rx_buf_size > ram_quota.value ||
tx_buf_size + rx_buf_size > ram_quota.value)
{
error("insufficient 'ram_quota' for session creation");
throw Insufficient_ram_quota();
}
return new (md_alloc())
Session_component(Ram_quota{ram_quota.value - session_size},
Session_component(Ram_quota{ram_quota.value},
cap_quota, tx_buf_size, rx_buf_size, _config, _timer,
_curr_time, _env);
}

View File

@ -149,19 +149,14 @@ class Nic_loopback::Root : public Root_component<Session_component>
size_t tx_buf_size = Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
size_t rx_buf_size = Arg_string::find_arg(args, "rx_buf_size").ulong_value(0);
/* deplete ram quota by the memory needed for the session structure */
size_t session_size = max(4096UL, (size_t)sizeof(Session_component));
if (ram_quota < session_size)
throw Insufficient_ram_quota();
/*
* Check if donated ram quota suffices for both communication
* buffers and check for overflow
*/
if (tx_buf_size + rx_buf_size < tx_buf_size ||
tx_buf_size + rx_buf_size > ram_quota - session_size) {
tx_buf_size + rx_buf_size > ram_quota) {
error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", tx_buf_size + rx_buf_size + session_size);
"need ", tx_buf_size + rx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -347,20 +347,14 @@ class Block::Main : Rpc_object<Typed_root<Session>>,
if (!tx_buf_size)
throw Service_denied();
/* delete ram quota by the memory needed for the session */
size_t session_size = max((size_t)4096,
sizeof(Session_component));
if (ram_quota.value < session_size)
throw Insufficient_ram_quota();
/*
* Check if donated ram quota suffices for both
* communication buffers. Also check both sizes separately
* to handle a possible overflow of the sum of both sizes.
*/
if (tx_buf_size > ram_quota.value - session_size) {
if (tx_buf_size > ram_quota.value) {
error("insufficient 'ram_quota', got ", ram_quota, ", need ",
tx_buf_size + session_size);
tx_buf_size);
throw Insufficient_ram_quota();
}

View File

@ -876,13 +876,9 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>,
if (!tx_buf_size)
throw Service_denied();
size_t session_size =
max((size_t)4096, sizeof(Session_component)) +
tx_buf_size;
if (session_size > ram_quota) {
if (tx_buf_size > ram_quota) {
error("insufficient 'ram_quota' from '", label, "' "
"got ", ram_quota, ", need ", session_size);
"got ", ram_quota, ", need ", tx_buf_size);
throw Insufficient_ram_quota();
}