Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: optionally load the system SELinux policy #400

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69d80f4
init: optionally load the system SELinux policy
WavyEbuilder Oct 15, 2024
0a5f876
mark selinux_transition as static
WavyEbuilder Oct 19, 2024
c465b81
BUILD_MESON: add selinux option documentation
WavyEbuilder Oct 19, 2024
6063686
init: selinux: add --disable-selinux
WavyEbuilder Oct 19, 2024
57b94a2
doc: manpages: mention --disable-selinux flag
WavyEbuilder Oct 19, 2024
6910b6d
init: selinux: fix header guards
WavyEbuilder Oct 19, 2024
67c3d8b
build: docs: add SUPPORT_SELINUX info
WavyEbuilder Oct 23, 2024
55b82d8
init: rename --disable-selinux option to --disable-selinux-policy
WavyEbuilder Oct 23, 2024
15e2f6e
selinux: add explanatory comments for selinux related functions
WavyEbuilder Oct 26, 2024
ca63b57
configure: update help text for selinux options
WavyEbuilder Oct 26, 2024
159ffac
printVersion: add selinux information to output
WavyEbuilder Oct 26, 2024
0e959a7
selinux: update comments
WavyEbuilder Oct 27, 2024
a40f43a
meson.build: clean up selinux related options
WavyEbuilder Oct 27, 2024
7d88201
meson.build: rename libselinux dependency to libselinux_dep
WavyEbuilder Oct 27, 2024
157a78a
meson: refractor mconfig logic for selinux
WavyEbuilder Oct 27, 2024
01640d8
configure: update --enable-selinux help text
WavyEbuilder Oct 31, 2024
a8ecd7d
doc: manpages: update --disable-selinux flag to --disable-selinux-policy
WavyEbuilder Oct 31, 2024
10c8198
dinit.cc: fix line wrapping for comments per CODE-STYLE
WavyEbuilder Oct 31, 2024
e4b5b3e
dinit.cc: selinux_transition: clarify comment regarding the log
WavyEbuilder Oct 31, 2024
02b93a8
selinux_transition: clean up comment per CODE-STYLE
WavyEbuilder Nov 2, 2024
66be73d
selinux_transition: log error and return early for permissive
WavyEbuilder Nov 2, 2024
e06e054
selinux_transition: check that getcon_raw(3) doesn't return nullptr
WavyEbuilder Nov 8, 2024
4bf712a
selinux_transition: clarify kernel context in comment
WavyEbuilder Nov 8, 2024
eadc90c
selinux_transition: be more specific in comment
WavyEbuilder Nov 8, 2024
86a9f0c
selinux_transition: fix line wrapping for comments
WavyEbuilder Nov 8, 2024
8737eef
selinux_transition: correct check for getcon_raw(3) return value
WavyEbuilder Nov 11, 2024
f093426
selinux_transition: don't exit if we are unable to transition
WavyEbuilder Nov 11, 2024
e40b38e
selinux_transition: always error exit if we fail to load the policy
WavyEbuilder Nov 11, 2024
a6af309
selinux_transition: update comments to reflect the current control flow
WavyEbuilder Nov 11, 2024
25eb167
selinux_transition: fix grammar in comment
WavyEbuilder Nov 11, 2024
d90b013
selinux_transition: improve wording for comment
WavyEbuilder Nov 11, 2024
1f2f7cf
selinux_transition: document the mounting of /sys
WavyEbuilder Nov 11, 2024
ab15586
selinux_transition: reformat if statement per CODE-STYLE
WavyEbuilder Nov 11, 2024
90b789b
selinux_transition: clarify policy choice for inital domain in comment
WavyEbuilder Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ DEFAULT_STOP_TIMEOUT=XXX
this, its process group is sent a SIGKILL signal which should cause it to terminate immediately.
The default if unspecified is 10 seconds. (The value can be overridden for individual services
via the service description).
SUPPORT_SELINUX=1|0
Whether to build support for loading the system SELinux policy at boot.


Running the test suite
Expand Down
4 changes: 4 additions & 0 deletions BUILD_MESON
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ Custom options:
build-shutdown : Whether to build the shutdown/reboot/halt utilities.
Available values : enabled, disabled, auto
Default value : auto

support-selinux : Enable SELinux support.
Available values : enabled, disabled, auto
Default value : auto


Running the test suite
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ The following people (in alphabetical order) have contributed:
* Oliver Amann - Code, testing, documentation
* Locria Cyber - Code, documentation
* q66 - Code, testing, documentation.
* Rahul Sandhu - Code
3 changes: 2 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ includes/mconfig.h: ../mconfig tools/mconfig-gen.cc version.conf
DEFAULT_STOP_TIMEOUT=$(DEFAULT_STOP_TIMEOUT) \
$(if $(SUPPORT_CGROUPS),SUPPORT_CGROUPS=$(SUPPORT_CGROUPS),) \
$(if $(USE_UTMPX),USE_UTMPX=$(USE_UTMPX),) \
$(if $(USE_INITGROUPS),USE_INITGROUPS=$(USE_INITGROUPS),) > includes/mconfig.h
$(if $(USE_INITGROUPS),USE_INITGROUPS=$(USE_INITGROUPS),) \
$(if $(SUPPORT_SELINUX),SUPPORT_SELINUX=$(SUPPORT_SELINUX),) > includes/mconfig.h

clean:
rm -f includes/mconfig.h
Expand Down
1 change: 1 addition & 0 deletions build/mconfig.mesontemplate
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#mesondefine USE_UTMPX
#mesondefine USE_INITGROUPS
#mesondefine SUPPORT_CGROUPS
#mesondefine SUPPORT_SELINUX
#mesondefine DEFAULT_AUTO_RESTART
#mesondefine DEFAULT_START_TIMEOUT
#mesondefine DEFAULT_STOP_TIMEOUT
Expand Down
3 changes: 3 additions & 0 deletions build/tools/mconfig-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int main(int argc, char **argv)
if (vars.find("DEFAULT_AUTO_RESTART") != vars.end()) {
cout << "#define DEFAULT_AUTO_RESTART " << vars["DEFAULT_AUTO_RESTART"] << "\n";
}
if (vars.find("SUPPORT_SELINUX") != vars.end()) {
cout << "#define SUPPORT_SELINUX " << vars["SUPPORT_SELINUX"] << "\n";
}

cout << "\n// Constants\n";
cout << "\nconstexpr static char DINIT_VERSION[] = " << stringify(vars["VERSION"]) << ";\n";
Expand Down
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Optional options:
--disable-utmpx Disable manipulating the utmp/utmpx database via the related POSIX functions
--enable-initgroups Enable initialization of supplementary groups for run-as [Enabled]
--disable-initgroups Disable initialization of supplementary groups for run-as
--enable-selinux Enable SELinux support [Only avilable on Linux based systems with SELinux support]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As was mentioned:

Defaults for the options are specified in brackets.

Now it is:

[Only avilable on Linux based systems with SELinux support]

That is not specifying the default, it's just a statement of availability.

Also "avilable" has a typo.

--disable-selinux Disable SELinux support
--enable-auto-restart Enable auto-restart for services by default [Deprecated]
--disable-auto-restart Disable auto-restart for services by default [Deprecated]
--default-start-timeout=sec Default start-timeout for services [60]
Expand Down Expand Up @@ -210,6 +212,7 @@ for var in PREFIX \
SUPPORT_CGROUPS \
USE_UTMPX \
USE_INITGROUPS \
SUPPORT_SELINUX \
SYSCONTROLSOCKET \
STRIPOPTS
do
Expand Down Expand Up @@ -243,6 +246,8 @@ for arg in "$@"; do
--disable-utmpx|--enable-utmpx=no) USE_UTMPX=0 ;;
--enable-initgroups|--enable-initgroups=yes) USE_INITGROUPS=1 ;;
--disable-initgroups|--enable-initgroups=no) USE_INITGROUPS=0 ;;
--enable-selinux|--enable-selinux=yes) SUPPORT_SELINUX=1 ;;
--disable-selinux|--enable-selinux=no) SUPPORT_SELINUX=0 ;;
--enable-auto-restart|--enable-auto-restart=yes) DEFAULT_AUTO_RESTART=ALWAYS ;; # Deprecated
--disable-auto-restart|--enable-auto-restart=no) DEFAULT_AUTO_RESTART=NEVER ;; # Deprecated
--enable-strip|--enable-strip=yes) STRIPOPTS="-s" ;;
Expand Down Expand Up @@ -275,6 +280,7 @@ done
: "${DEFAULT_START_TIMEOUT:="60"}"
: "${DEFAULT_STOP_TIMEOUT:="10"}"
: "${USE_INITGROUPS:="1"}"
: "${SUPPORT_SELINUX:="0"}"
if [ "$PLATFORM" = "Linux" ]; then
: "${BUILD_SHUTDOWN:="yes"}"
: "${SUPPORT_CGROUPS:="1"}"
Expand Down Expand Up @@ -380,6 +386,9 @@ fi
if [ "$AUTO_LDFLAGS_BASE" = true ] && [ "$PLATFORM" = FreeBSD ]; then
try_ld_argument LDFLAGS_BASE -lrt
fi
if [ "$AUTO_LDFLAGS_BASE" = true ] && [ "$SUPPORT_SELINUX" = "1" ]; then
try_ld_argument LDFLAGS_BASE -lselinux
fi
if [ "$AUTO_TEST_LDFLAGS_BASE" = true ]; then
TEST_LDFLAGS_BASE="\$(LDFLAGS_BASE)"
established_TEST_LDFLAGS="$LDFLAGS_BASE"
Expand Down Expand Up @@ -467,6 +476,7 @@ STRIPOPTS=$STRIPOPTS
# Feature settings
SUPPORT_CGROUPS=$SUPPORT_CGROUPS
USE_INITGROUPS=$USE_INITGROUPS
SUPPORT_SELINUX=$SUPPORT_SELINUX

# Optional settings
SHUTDOWN_PREFIX=${SHUTDOWN_PREFIX:-}
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/dinit.8.m4
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ If service description settings contain relative cgroup paths, they will be reso
this path.
This option is only available if \fBdinit\fR is built with cgroups support.
.TP
\fB\-\-disable\-selinux\fR
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option was changed to --disable-selinux-policy, you need to update the documentation to match.

Disable loading of the system SELinux policy.
This option is only available if \fBdinit\fR is built with SELinux support.
.TP
\fB\-\-help\fR
Display brief help text and then exit.
.TP
Expand Down
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ man_pages = get_option('man-pages')
support_cgroups = get_option('support-cgroups')
use_utmpx = get_option('use-utmpx')
use_initgroups = get_option('use-initgroups')
support_selinux = get_option('support-selinux')
default_auto_restart = get_option('default-auto-restart')
default_start_timeout = get_option('default-start-timeout').to_string()
default_stop_timeout = get_option('default-stop-timeout').to_string()
Expand All @@ -56,6 +57,9 @@ if platform == 'freebsd' and compiler.has_link_argument('-lrt')
add_project_link_arguments('-lrt', language : 'cpp')
endif

## Dependencies
libselinux_dep = dependency('libselinux', version : '>= 2.1.9', required : support_selinux)

## Prepare mconfig.h
mconfig_data.set_quoted('DINIT_VERSION', version)
mconfig_data.set_quoted('SYSCONTROLSOCKET', dinit_control_socket_path)
Expand All @@ -65,6 +69,7 @@ mconfig_data.set('DEFAULT_AUTO_RESTART', default_auto_restart)
mconfig_data.set('DEFAULT_START_TIMEOUT', default_start_timeout)
mconfig_data.set('DEFAULT_STOP_TIMEOUT', default_stop_timeout)
mconfig_data.set10('USE_INITGROUPS', use_initgroups)
mconfig_data.set10('SUPPORT_SELINUX', libselinux_dep.found())
if support_cgroups.auto() and platform == 'linux' or support_cgroups.enabled()
mconfig_data.set('SUPPORT_CGROUPS', '1')
endif
Expand Down
6 changes: 6 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ option(
value : 'auto',
description : 'Building shutdown/reboot/soft-reboot/halt or not.'
)
option(
'support-selinux',
type : 'feature',
value : 'auto',
description : 'SELinux support'
)
117 changes: 117 additions & 0 deletions src/dinit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@

#include "mconfig.h"

#if SUPPORT_SELINUX
#include <selinux/avc.h>
#include <selinux/label.h>
#include <selinux/selinux.h>
#endif

/*
* When running as the system init process, Dinit processes the following signals:
*
Expand Down Expand Up @@ -210,6 +216,10 @@ struct options {

// list of services to start
std::list<const char *> services_to_start;

#ifdef SUPPORT_SELINUX
bool load_selinux_policy = true;
#endif
};

// Process a command line argument (and possibly its follow-up value)
Expand Down Expand Up @@ -365,6 +375,11 @@ static int process_commandline_arg(char **argv, int argc, int &i, options &opts)
}
}
#endif
#ifdef SUPPORT_SELINUX
else if (strcmp(argv[i], "--disable-selinux-policy") == 0) {
opts.load_selinux_policy = false;
}
#endif
else if (strcmp(argv[i], "--service") == 0 || strcmp(argv[i], "-t") == 0) {
if (++i < argc && argv[i][0] != '\0') {
services_to_start.push_back(argv[i]);
Expand Down Expand Up @@ -399,6 +414,9 @@ static int process_commandline_arg(char **argv, int argc, int &i, options &opts)
" --cgroup-path <path>, -b <path>\n"
" cgroup base path (for resolving relative paths)\n"
#endif
#ifdef SUPPORT_SELINUX
" --disable-selinux-policy don't load the system SELinux policy\n"
#endif
" --log-file <file>, -l <file> log to the specified file\n"
" --quiet, -q disable output to standard output\n"
" <service-name>, --service <service-name>, -t <service-name>\n"
Expand Down Expand Up @@ -453,6 +471,90 @@ static int process_commandline_arg(char **argv, int argc, int &i, options &opts)
return 0;
}

#if SUPPORT_SELINUX
// Load the system SELinux policy and transition ourselves to it. When successful,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line width should extend to (just under) 100 characters, please see CODE-STYLE. This comment wraps at just over 80 characters.

// this will cause SELinux labels as per the policy to be attached to processes (and
// file descriptors owned by those processes). The SELinux framework will begin to
// enforce restrictions on access based on these labels and the loaded policy.
//
// We might lose access to any file descriptors we have open when this is called (since
// they will still be labelled with the kernel context), so it is best done early (i.e.
// before we start opening file descriptors).
//
// Parameters:
// exe - the path that we are invoked with (to calculate our new security
// context to tranition into.)
WavyEbuilder marked this conversation as resolved.
Show resolved Hide resolved
//
// Returns:
// If we fail to load the system SELinux policy, return false, otherwise,
// return true.
static bool selinux_transition(const char *exe) {
davmac314 marked this conversation as resolved.
Show resolved Hide resolved
// Let's use std::cerr instead of the log for logging messages here.
// If we output anything, we return failure, which indicates dinit should
// terminate before the log is initalised and flushed.
davmac314 marked this conversation as resolved.
Show resolved Hide resolved
using std::cerr;
using std::endl;

davmac314 marked this conversation as resolved.
Show resolved Hide resolved
char *current_context = nullptr;
char *file_context = nullptr;
security_class_t security_class;
char *new_context = nullptr;

if (is_selinux_enabled() == 1) {
return true;
}

int enforce = 0;
// We don't need to worry about the enforcing=0 kernel cmdline option or
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend comments to the correct line width before wrapping them. See CODE-STYLE.

// parsing /etc/selinux/config, selinux_init_load_policy(3) will handle
// all cases for us.
if (selinux_init_load_policy(&enforce) != 0) {
if (enforce > 0) {
cerr << "Failed to load SELinux policy." << endl;
return false;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the load fails (selinux_init_load_policy returns 0) but enforce is 0, what is supposed to happen here? It seems like it just ploughs ahead with trying to set the context, but surely that isn't right?

Copy link
Author

@WavyEbuilder WavyEbuilder Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the enforcing variable, there are 2 states:

  • = 0 is permissive mode
  • > 0 is enforcing mode

In the case of enforcing, the system is expected to boot in a secure state, i.e. with the system's SELinux policy enforcing. If we fail to load it, we should halt the boot as that is an untrusted state.

In the case of permissive, it's generally better to be more lenient. In permissive mode, actions are expected to be logged, but any failures revolving around the policy aren't expected to have an impact on the system's operation. Other SELinux aware applications, such as load_policy(1) from policycoreutils also reflect this behavior:
https://github.com/SELinuxProject/selinux/blob/main/policycoreutils/load_policy/load_policy.c#L68-L77

Let me know your thoughts, I can add a comment explaining this too if desired

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not answering the question I asked. If the policy fails to load (selinux_init_load_policy returns 0) but enforce is 0, what is this function supposed to do?

The comment says:

If we fail to load the system SELinux policy, return false

But it's not even returning at this point, it's just going on through to the following call to (getcon_raw(&current_context). Isn't that wrong?

Other SELinux aware applications, such as load_policy(1) from policycoreutils also reflect this behavior

That code checks whether loading the policy failed, and if so, prints an error message and retuns an exit code:

https://github.com/SELinuxProject/selinux/blob/main/policycoreutils/load_policy/load_policy.c#L82-L85

That's different to what is here, which just continues as if no error had happened.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when I say "continues as if no error had happened", I mean that it goes on to try and set a new context (getcon_raw, getfilecon_raw, security_compute_create_raw, etc). I assume that those will fail, since the policy load failed, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that those will fail, since the policy load failed, right?

Those won't fail as it'll just continue on with the kernel context.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know your thoughts

I know that you have done some work on this and are probably trying hard, but in all honesty I am very close to pulling the plug. I need you to clearly answer the questions that I'm asking, not just push more code.

The question I asked was:

So if the load fails (selinux_init_load_policy returns 0) but enforce is 0, what is supposed to happen here? It seems like it just ploughs ahead with trying to set the context, but surely that isn't right?

I still don't have a satisfactory answer to that. I can't accept this PR without understanding what it is doing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those won't fail as it'll just continue on with the kernel context

Are you saying that setcon_raw will do nothing but still return success?

I decided to clarify this a bit further, so getcon_raw seems to be fine (which makes logical sense), and setcon_raw will be fine, but the issue lies in security_compute_create_raw as that actually attempts to read the policy to calculate something, so that should fail. I tested it by disabling the load temporarily on my machine, and writing a small program to see what would/wouldn't fail regarding those functions. So logically based off all of this, I think the early return makes sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know your thoughts

I know that you have done some work on this and are probably trying hard, but in all honesty I am very close to pulling the plug. I need you to clearly answer the questions that I'm asking, not just push more code.

The question I asked was:

So if the load fails (selinux_init_load_policy returns 0) but enforce is 0, what is supposed to happen here? It seems like it just ploughs ahead with trying to set the context, but surely that isn't right?

I still don't have a satisfactory answer to that. I can't accept this PR without understanding what it is doing.

Understood. So:

So if the load fails (selinux_init_load_policy returns 0) but enforce is 0, what is supposed to happen here? It seems like it just ploughs ahead with trying to set the context, but surely that isn't right?

This is accurate, i.e. that wasn't right. I don't think we should fail (as in exit) there, and I incorrectly gathered that it would just fall through (because it'll attempt to set the same context). I overlooked the fact security_compute_create_raw specifically reads from the policy store, so that'd fail. So an early return of true would make sense. Sincere apologies

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sincere apologies

Ok, but: you need to slow down and read my questions/comments properly, and answer them comprehensively. I'm spending far more time on this that I would like, and it seems like it's mostly because I have to repeatedly ask questions until I get a straight answer.

So an early return of true would make sense

"An early return of true" will currently fail the boot. So is that what is supposed to happen?

so getcon_raw seems to be fine (which makes logical sense),

Where does this information come from? (I'm having trouble even finding the source for getcon_raw).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry: an early return of true won't fail the boot, I was thinking an early return of false.
However, an early return of true would break the contract described in the function comment:

// Returns:
//   If we fail to load the system SELinux policy, return false, otherwise, return true.

So that might need to be updated, or expanded on in the descriptive part of the comment.

}

bool ret = true;
if (getcon_raw(&current_context) < 0) {
ret = false;
cerr << "Failed to get current context: " << strerror(errno) << endl;
goto cleanup;
}

if (getfilecon_raw(exe, &file_context) < 0) {
ret = false;
cerr << "Failed to get file context for " << exe << ": " << strerror(errno) << endl;
goto cleanup;
}

security_class = string_to_security_class("process");
if (security_class == 0) {
ret = false;
cerr << "Failed to get security class for process" << endl;
goto cleanup;
}

if (security_compute_create_raw(current_context, file_context, security_class, &new_context) < 0) {
ret = false;
cerr << "Failed to compute create context: " << strerror(errno) << endl;
goto cleanup;
}

if (setcon_raw(new_context) < 0) {
ret = false;
cerr << "Failed to set transition context to " << new_context << ": " << strerror(errno) << endl;
goto cleanup;
}

cleanup:
if (current_context) freecon(current_context);
if (file_context) freecon(file_context);
if (new_context) freecon(new_context);
return ret;
}
#endif

// Main entry point
int dinit_main(int argc, char **argv)
{
Expand Down Expand Up @@ -486,6 +588,18 @@ int dinit_main(int argc, char **argv)
}
}

#if SUPPORT_SELINUX
// Error exit if we are PID 1 and fail to load the selinux policy and transition.
//
// This should be done directly after argument parsing, it's best to do this as early as possible to get
Copy link
Owner

@davmac314 davmac314 Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment line, in contrast, is too long. And so are some of the others. Please check all comments and make sure the line widths are correct.

Basically: they should be as close to (but less than) 100 characters as is possible, but may extend to 110 in cases where that means the entire comment will fit on a single line.

// init in the domain specified in the policy, and hence confine it, quickly.
//
// If selinux_transition fails, the system is not in the state requested by the user, and there is nothing
// we can do about it. Instead of continuing to boot the rest of the system without loading the user's policy,
// let's bail now to avoid an insecure and untrusted state.
if (am_system_mgr && am_system_init && opts.load_selinux_policy && !selinux_transition(argv[0])) return 1;
davmac314 marked this conversation as resolved.
Show resolved Hide resolved
#endif

if (am_system_mgr) {
// setup STDIN, STDOUT, STDERR so that we can use them
int onefd = open("/dev/console", O_RDONLY, 0);
Expand Down Expand Up @@ -1207,6 +1321,9 @@ static void printVersion()
#endif
#if USE_INITGROUPS
" supplemental-groups"
#endif
#if SUPPORT_SELINUX
" selinux"
#endif
"\n";
}
Expand Down
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ endif
executable(
'dinit',
dinit_source_files,
kwargs: misc_args
kwargs: misc_args,
dependencies: [libselinux_dep],
)
executable(
'dinitctl',
Expand Down