Assorted cleanups and fixes (#41626)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-14 09:10:16 +02:00
committed by GitHub
7 changed files with 79 additions and 20 deletions
+4 -4
View File
@@ -1265,10 +1265,6 @@ static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_e
/* Anyone can call this method */
r = mac_selinux_access_check(message, "status", reterr_error);
if (r < 0)
return r;
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
return r;
@@ -1281,6 +1277,10 @@ static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_e
if (k != u->id)
continue;
r = mac_selinux_unit_access_check(u, message, "status", /* reterr_error= */ NULL);
if (r < 0)
continue; /* silently skip units the caller is not allowed to see */
if (!unit_passes_filter(u, states, patterns))
continue;
+4
View File
@@ -207,6 +207,10 @@ int vl_method_describe_manager(sd_varlink *link, sd_json_variant *parameters, sd
if (r != 0)
return r;
r = mac_selinux_access_check_varlink(link, "status");
if (r < 0)
return r;
r = sd_json_buildo(
&v,
SD_JSON_BUILD_PAIR_CALLBACK("context", manager_context_build_json, manager),
+4
View File
@@ -523,6 +523,10 @@ int vl_method_list_units(sd_varlink *link, sd_json_variant *parameters, sd_varli
if (k != unit->id)
continue;
r = mac_selinux_unit_access_check_varlink(unit, link, "status");
if (r < 0)
continue; /* silently skip units the caller is not allowed to see */
r = list_unit_one(link, unit);
if (r < 0)
return r;
+5 -2
View File
@@ -307,10 +307,13 @@ int start_upload(Uploader *u,
LOG_ERR, return -EXFULL);
}
if (STRPTR_IN_SET(arg_trust, "-", "all"))
if (STRPTR_IN_SET(arg_trust, "-", "all")) {
log_info("Server certificate verification disabled.");
easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L,
LOG_ERR, return -EUCLEAN);
else if (arg_trust || startswith(u->url, "https://"))
easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L,
LOG_ERR, return -EUCLEAN);
} else if (arg_trust || startswith(u->url, "https://"))
easy_setopt(curl, CURLOPT_CAINFO, arg_trust ?: TRUST_FILE,
LOG_ERR, return -EXFULL);
+45 -5
View File
@@ -59,6 +59,7 @@
#include "signal-util.h"
#include "sleep-config.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "tmpfile-util.h"
@@ -3582,6 +3583,46 @@ static int property_get_boot_loader_entries(
return sd_bus_message_close_container(reply);
}
static int wall_message_validate(const char *wall_message, sd_bus_error *error) {
if (strlen(wall_message) > WALL_MESSAGE_MAX)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
"Wall message too long, maximum permitted length is %u characters.",
WALL_MESSAGE_MAX);
if (string_has_cc(wall_message, /* ok= */ "\n\t"))
return sd_bus_error_set(error,
SD_BUS_ERROR_INVALID_ARGS,
"Wall message contains control characters, refusing.");
return 0;
}
static int property_set_wall_message(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *value,
void *userdata,
sd_bus_error *error) {
char **p = ASSERT_PTR(userdata);
const char *s;
int r;
assert(value);
r = sd_bus_message_read(value, "s", &s);
if (r < 0)
return r;
r = wall_message_validate(s, error);
if (r < 0)
return r;
return free_and_strdup_warn(p, empty_to_null(s));
}
static int method_set_wall_message(
sd_bus_message *message,
void *userdata,
@@ -3598,10 +3639,9 @@ static int method_set_wall_message(
if (r < 0)
return r;
if (strlen(wall_message) > WALL_MESSAGE_MAX)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
"Wall message too long, maximum permitted length is %u characters.",
WALL_MESSAGE_MAX);
r = wall_message_validate(wall_message, error);
if (r < 0)
return r;
/* Short-circuit the operation if the desired state is already in place, to
* avoid an unnecessary polkit permission check. */
@@ -3764,7 +3804,7 @@ static const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_WRITABLE_PROPERTY("EnableWallMessages", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, wall_messages), 0),
SD_BUS_WRITABLE_PROPERTY("WallMessage", "s", NULL, NULL, offsetof(Manager, wall_message), 0),
SD_BUS_WRITABLE_PROPERTY("WallMessage", "s", NULL, property_set_wall_message, offsetof(Manager, wall_message), 0),
SD_BUS_PROPERTY("NAutoVTs", "u", NULL, offsetof(Manager, n_autovts), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("KillOnlyUsers", "as", NULL, offsetof(Manager, kill_only_users), SD_BUS_VTABLE_PROPERTY_CONST),
+4
View File
@@ -26,6 +26,7 @@
#include "signal-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_class, machine_class, MachineClass);
static BUS_DEFINE_PROPERTY_GET2(property_get_state, "s", Machine, machine_get_state, machine_state_to_string);
@@ -366,6 +367,9 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
return r;
user = isempty(user) ? "root" : user;
if (!valid_user_group_name(user, VALID_USER_RELAX))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user name '%s'", user);
/* Ensure only root can shell into the root namespace. This is to avoid unprivileged users registering
* a process they own in the root user namespace, and then shelling in as root or another user. Note that
* the shell operation is privileged and requires 'auth_admin', so we do not need to check the caller's uid,
+13 -9
View File
@@ -1103,11 +1103,10 @@ int machine_start_shell(
char** machine_default_shell_args(const char *user) {
_cleanup_strv_free_ char **args = NULL;
int r;
assert(user);
args = new0(char*, 3 + 1);
args = new0(char*, 5 + 1);
if (!args)
return NULL;
@@ -1119,14 +1118,19 @@ char** machine_default_shell_args(const char *user) {
if (!args[1])
return NULL;
r = asprintf(&args[2],
"shell=$(getent passwd %s 2>/dev/null | { IFS=: read _ _ _ _ _ _ x; echo \"$x\"; })\n"\
"exec \"${shell:-/bin/sh}\" -l", /* -l is means --login */
user);
if (r < 0) {
args[2] = NULL;
args[2] = strdup(
"shell=$(getent passwd \"$1\" 2>/dev/null | { IFS=: read _ _ _ _ _ _ x; echo \"$x\"; })\n"
"exec \"${shell:-/bin/sh}\" -l"); /* -l means --login */
if (!args[2])
return NULL;
args[3] = strdup("sh"); /* $0 placeholder for sh -c */
if (!args[3])
return NULL;
args[4] = strdup(user); /* becomes $1 in the script */
if (!args[4])
return NULL;
}
return TAKE_PTR(args);
}