!390 fix CVE-2023-26604
From: @huyubiao Reviewed-by: @licunlong Signed-off-by: @licunlong
This commit is contained in:
commit
aa3faacc20
@ -0,0 +1,47 @@
|
||||
From 3d58bfc01c9283eded77736990ea09b0ee4f6e23 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Sun, 24 Nov 2019 13:59:32 +0100
|
||||
Subject: [PATCH] man: document all pager variables for systemctl and systemd
|
||||
|
||||
In those two pages, we need to include individual entries with xi:include to
|
||||
merge the list less-variables.xml with the other entries, which is obviously
|
||||
error prone. All variables are supported in both tools so add them.
|
||||
---
|
||||
man/systemctl.xml | 2 ++
|
||||
man/systemd.xml | 7 +++++--
|
||||
2 files changed, 7 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/man/systemctl.xml b/man/systemctl.xml
|
||||
index fb0ca46620..3d86f7dffa 100644
|
||||
--- a/man/systemctl.xml
|
||||
+++ b/man/systemctl.xml
|
||||
@@ -2161,6 +2161,8 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
|
||||
<xi:include href="less-variables.xml" xpointer="pager"/>
|
||||
<xi:include href="less-variables.xml" xpointer="less"/>
|
||||
<xi:include href="less-variables.xml" xpointer="lesscharset"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="colors"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="urlify"/>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
diff --git a/man/systemd.xml b/man/systemd.xml
|
||||
index 9b2d5ac280..bde79d56fd 100644
|
||||
--- a/man/systemd.xml
|
||||
+++ b/man/systemd.xml
|
||||
@@ -669,8 +669,11 @@
|
||||
script runlevel link farms.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
- <xi:include href="less-variables.xml" xpointer="colors" />
|
||||
- <xi:include href="less-variables.xml" xpointer="urlify" />
|
||||
+ <xi:include href="less-variables.xml" xpointer="pager"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="less"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="lesscharset"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="colors"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="urlify"/>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>$LISTEN_PID</varname></term>
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
From 339bf2076b3294e5f7b59e84c59ba8c55ded3c25 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Fri, 15 Nov 2019 11:59:34 +0100
|
||||
Subject: [PATCH] man: share description of $SYSTEMD_COLORS in other tools
|
||||
|
||||
It was only described in systemd(1), making it hard to discover.
|
||||
Fixes #13561.
|
||||
|
||||
The same for $SYSTEMD_URLIFY.
|
||||
|
||||
I think all the tools whose man pages include less-variables.xml support
|
||||
those variables.
|
||||
---
|
||||
man/less-variables.xml | 20 +++++++++++++++++++-
|
||||
man/systemd.xml | 19 ++-----------------
|
||||
2 files changed, 21 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/man/less-variables.xml b/man/less-variables.xml
|
||||
index 38cb18be2e..8a701277b6 100644
|
||||
--- a/man/less-variables.xml
|
||||
+++ b/man/less-variables.xml
|
||||
@@ -64,5 +64,23 @@
|
||||
the invoking terminal is determined to be UTF-8 compatible).</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
- </variablelist>
|
||||
+ <varlistentry id='colors'>
|
||||
+ <term><varname>$SYSTEMD_COLORS</varname></term>
|
||||
+
|
||||
+ <listitem><para>The value must be a boolean. Controls whether colorized output should be
|
||||
+ generated. This can be specified to override the decision that <command>systemd</command> makes based
|
||||
+ on <varname>$TERM</varname> and what the console is connected to.</para>
|
||||
+ </listitem>
|
||||
+ </varlistentry>
|
||||
+
|
||||
+ <varlistentry id='urlify'>
|
||||
+ <term><varname>$SYSTEMD_URLIFY</varname></term>
|
||||
+
|
||||
+ <listitem><para>The value must be a boolean. Controls whether clickable links should be generated in
|
||||
+ the output for terminal emulators supporting this. This can be specified to override the decision that
|
||||
+ <command>systemd</command> makes based on <varname>$TERM</varname> and other conditions.</para>
|
||||
+ </listitem>
|
||||
+ </varlistentry>
|
||||
+
|
||||
+ </variablelist>
|
||||
</refsect1>
|
||||
diff --git a/man/systemd.xml b/man/systemd.xml
|
||||
index 957d37dcd9..5caf54b330 100644
|
||||
--- a/man/systemd.xml
|
||||
+++ b/man/systemd.xml
|
||||
@@ -870,23 +870,8 @@
|
||||
script runlevel link farms.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
- <varlistentry>
|
||||
- <term><varname>$SYSTEMD_COLORS</varname></term>
|
||||
-
|
||||
- <listitem><para>The value must be a boolean. Controls whether colorized output should be
|
||||
- generated. This can be specified to override the decision that <command>systemd</command>
|
||||
- makes based on <varname>$TERM</varname> and what the console is connected to.</para>
|
||||
- </listitem>
|
||||
- </varlistentry>
|
||||
-
|
||||
- <varlistentry>
|
||||
- <term><varname>$SYSTEMD_URLIFY</varname></term>
|
||||
-
|
||||
- <listitem><para>The value must be a boolean. Controls whether clickable links should be generated in the output
|
||||
- for terminal emulators supporting this. This can be specified to override the decision that
|
||||
- <command>systemd</command> makes based on <varname>$TERM</varname> and other conditions.</para>
|
||||
- </listitem>
|
||||
- </varlistentry>
|
||||
+ <xi:include href="less-variables.xml" xpointer="colors" />
|
||||
+ <xi:include href="less-variables.xml" xpointer="urlify" />
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>$LISTEN_PID</varname></term>
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,180 @@
|
||||
From 0a42426d797406b4b01a0d9c13bb759c2629d108 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Wed, 7 Oct 2020 11:15:05 +0200
|
||||
Subject: [PATCH 3/3] pager: make pager secure when under euid is changed or
|
||||
explicitly requested
|
||||
|
||||
The variable is renamed to SYSTEMD_PAGERSECURE (because it's not just about
|
||||
less now), and we automatically enable secure mode in certain cases, but not
|
||||
otherwise.
|
||||
|
||||
This approach is more nuanced, but should provide a better experience for
|
||||
users:
|
||||
|
||||
- Previusly we would set LESSSECURE=1 and trust the pager to make use of
|
||||
it. But this has an effect only on less. We need to not start pagers which
|
||||
are insecure when in secure mode. In particular more is like that and is a
|
||||
very popular pager.
|
||||
|
||||
- We don't enable secure mode always, which means that those other pagers can
|
||||
reasonably used.
|
||||
|
||||
- We do the right thing by default, but the user has ultimate control by
|
||||
setting SYSTEMD_PAGERSECURE.
|
||||
|
||||
Fixes #5666.
|
||||
|
||||
v2:
|
||||
- also check $PKEXEC_UID
|
||||
|
||||
v3:
|
||||
- use 'sd_pid_get_owner_uid() != geteuid()' as the condition
|
||||
---
|
||||
man/less-variables.xml | 30 ++++++++++++++++----
|
||||
src/shared/pager.c | 63 ++++++++++++++++++++++++++++--------------
|
||||
2 files changed, 66 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/man/less-variables.xml b/man/less-variables.xml
|
||||
index c52511ca8e..049e9f75d7 100644
|
||||
--- a/man/less-variables.xml
|
||||
+++ b/man/less-variables.xml
|
||||
@@ -65,12 +65,30 @@
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id='lesssecure'>
|
||||
- <term><varname>$SYSTEMD_LESSSECURE</varname></term>
|
||||
-
|
||||
- <listitem><para>Takes a boolean argument. Overrides the <varname>$LESSSECURE</varname> environment
|
||||
- variable when invoking the pager, which controls the "secure" mode of less (which disables commands
|
||||
- such as <literal>|</literal> which allow to easily shell out to external command lines). By default
|
||||
- less secure mode is enabled, with this setting it may be disabled.</para></listitem>
|
||||
+ <term><varname>$SYSTEMD_PAGERSECURE</varname></term>
|
||||
+
|
||||
+ <listitem><para>Takes a boolean argument. When true, the "secure" mode of the pager is enabled; if
|
||||
+ false, disabled. If <varname>$SYSTEMD_PAGERSECURE</varname> is not set at all, secure mode is enabled
|
||||
+ if the effective UID is not the same as the owner of the login session, see <citerefentry
|
||||
+ project='man-pages'><refentrytitle>geteuid</refentrytitle><manvolnum>2</manvolnum></citerefentry> and
|
||||
+ <citerefentry><refentrytitle>sd_pid_get_owner_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
|
||||
+ In secure mode, <option>LESSSECURE=1</option> will be set when invoking the pager, and the pager shall
|
||||
+ disable commands that open or create new files or start new subprocesses. When
|
||||
+ <varname>$SYSTEMD_PAGERSECURE</varname> is not set at all, pagers which are not known to implement
|
||||
+ secure mode will not be used. (Currently only
|
||||
+ <citerefentry><refentrytitle>less</refentrytitle><manvolnum>1</manvolnum></citerefentry> implements
|
||||
+ secure mode.)</para>
|
||||
+
|
||||
+ <para>Note: when commands are invoked with elevated privileges, for example under <citerefentry
|
||||
+ project='man-pages'><refentrytitle>sudo</refentrytitle><manvolnum>8</manvolnum></citerefentry> or
|
||||
+ <citerefentry
|
||||
+ project='die-net'><refentrytitle>pkexec</refentrytitle><manvolnum>1</manvolnum></citerefentry>, care
|
||||
+ must be taken to ensure that unintended interactive features are not enabled. "Secure" mode for the
|
||||
+ pager may be enabled automatically as describe above. Setting <varname>SYSTEMD_PAGERSECURE=0</varname>
|
||||
+ or not removing it from the inherited environment allows the user to invoke arbitrary commands. Note
|
||||
+ that if the <varname>$SYSTEMD_PAGER</varname> or <varname>$PAGER</varname> variables are to be
|
||||
+ honoured, <varname>$SYSTEMD_PAGERSECURE</varname> must be set too. It might be reasonable to completly
|
||||
+ disable the pager using <option>--no-pager</option> instead.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id='colors'>
|
||||
diff --git a/src/shared/pager.c b/src/shared/pager.c
|
||||
index 9c21881241..9a14d44d69 100644
|
||||
--- a/src/shared/pager.c
|
||||
+++ b/src/shared/pager.c
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
+#include "sd-login.h"
|
||||
+
|
||||
#include "copy.h"
|
||||
#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
@@ -165,25 +167,42 @@ int pager_open(PagerFlags flags) {
|
||||
}
|
||||
|
||||
/* People might invoke us from sudo, don't needlessly allow less to be a way to shell out
|
||||
- * privileged stuff. */
|
||||
- r = getenv_bool("SYSTEMD_LESSSECURE");
|
||||
- if (r == 0) { /* Remove env var if off */
|
||||
- if (unsetenv("LESSSECURE") < 0) {
|
||||
- log_error_errno(errno, "Failed to uset environment variable LESSSECURE: %m");
|
||||
- _exit(EXIT_FAILURE);
|
||||
- }
|
||||
- } else {
|
||||
- /* Set env var otherwise */
|
||||
+ * privileged stuff. If the user set $SYSTEMD_PAGERSECURE, trust their configuration of the
|
||||
+ * pager. If they didn't, use secure mode when under euid is changed. If $SYSTEMD_PAGERSECURE
|
||||
+ * wasn't explicitly set, and we autodetect the need for secure mode, only use the pager we
|
||||
+ * know to be good. */
|
||||
+ int use_secure_mode = getenv_bool("SYSTEMD_PAGERSECURE");
|
||||
+ bool trust_pager = use_secure_mode >= 0;
|
||||
+ if (use_secure_mode == -ENXIO) {
|
||||
+ uid_t uid;
|
||||
+
|
||||
+ r = sd_pid_get_owner_uid(0, &uid);
|
||||
if (r < 0)
|
||||
- log_warning_errno(r, "Unable to parse $SYSTEMD_LESSSECURE, ignoring: %m");
|
||||
+ log_debug_errno(r, "sd_pid_get_owner_uid() failed, enabling pager secure mode: %m");
|
||||
|
||||
- if (setenv("LESSSECURE", "1", 1) < 0) {
|
||||
- log_error_errno(errno, "Failed to set environment variable LESSSECURE: %m");
|
||||
- _exit(EXIT_FAILURE);
|
||||
- }
|
||||
+ use_secure_mode = r < 0 || uid != geteuid();
|
||||
+
|
||||
+ } else if (use_secure_mode < 0) {
|
||||
+ log_warning_errno(use_secure_mode, "Unable to parse $SYSTEMD_PAGERSECURE, assuming true: %m");
|
||||
+ use_secure_mode = true;
|
||||
}
|
||||
|
||||
- if (pager_args) {
|
||||
+ /* We generally always set variables used by less, even if we end up using a different pager.
|
||||
+ * They shouldn't hurt in any case, and ideally other pagers would look at them too. */
|
||||
+ if (use_secure_mode)
|
||||
+ r = setenv("LESSSECURE", "1", 1);
|
||||
+ else
|
||||
+ r = unsetenv("LESSSECURE");
|
||||
+ if (r < 0) {
|
||||
+ log_error_errno(errno, "Failed to adjust environment variable LESSSECURE: %m");
|
||||
+ _exit(EXIT_FAILURE);
|
||||
+ }
|
||||
+
|
||||
+ if (trust_pager && pager_args) { /* The pager config might be set globally, and we cannot
|
||||
+ * know if the user adjusted it to be appropriate for the
|
||||
+ * secure mode. Thus, start the pager specified through
|
||||
+ * envvars only when $SYSTEMD_PAGERSECURE was explicitly set
|
||||
+ * as well. */
|
||||
r = loop_write(exe_name_pipe[1], pager_args[0], strlen(pager_args[0]) + 1, false);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to write pager name to socket: %m");
|
||||
@@ -195,13 +214,14 @@ int pager_open(PagerFlags flags) {
|
||||
"Failed to execute '%s', using fallback pagers: %m", pager_args[0]);
|
||||
}
|
||||
|
||||
- /* Debian's alternatives command for pagers is
|
||||
- * called 'pager'. Note that we do not call
|
||||
- * sensible-pagers here, since that is just a
|
||||
- * shell script that implements a logic that
|
||||
- * is similar to this one anyway, but is
|
||||
- * Debian-specific. */
|
||||
+ /* Debian's alternatives command for pagers is called 'pager'. Note that we do not call
|
||||
+ * sensible-pagers here, since that is just a shell script that implements a logic that is
|
||||
+ * similar to this one anyway, but is Debian-specific. */
|
||||
FOREACH_STRING(exe, "pager", "less", "more") {
|
||||
+ /* Only less implements secure mode right now. */
|
||||
+ if (use_secure_mode && !streq(exe, "less"))
|
||||
+ continue;
|
||||
+
|
||||
r = loop_write(exe_name_pipe[1], exe, strlen(exe) + 1, false);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to write pager name to socket: %m");
|
||||
@@ -212,6 +232,7 @@ int pager_open(PagerFlags flags) {
|
||||
"Failed to execute '%s', using next fallback pager: %m", exe);
|
||||
}
|
||||
|
||||
+ /* Our builtin is also very secure. */
|
||||
r = loop_write(exe_name_pipe[1], "(built-in)", strlen("(built-in)") + 1, false);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to write pager name to socket: %m");
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
From 612ebf6c913dd0e4197c44909cb3157f5c51a2f0 Mon Sep 17 00:00:00 2001
|
||||
From: Lennart Poettering <lennart@poettering.net>
|
||||
Date: Mon, 31 Aug 2020 19:37:13 +0200
|
||||
Subject: [PATCH 1/3] pager: set $LESSSECURE whenver we invoke a pager
|
||||
|
||||
Some extra safety when invoked via "sudo". With this we address a
|
||||
genuine design flaw of sudo, and we shouldn't need to deal with this.
|
||||
But it's still a good idea to disable this surface given how exotic it
|
||||
is.
|
||||
|
||||
Prompted by #5666
|
||||
---
|
||||
man/less-variables.xml | 9 +++++++++
|
||||
man/systemctl.xml | 1 +
|
||||
man/systemd.xml | 1 +
|
||||
src/shared/pager.c | 23 +++++++++++++++++++++--
|
||||
4 files changed, 32 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/man/less-variables.xml b/man/less-variables.xml
|
||||
index 08e513c99f..c52511ca8e 100644
|
||||
--- a/man/less-variables.xml
|
||||
+++ b/man/less-variables.xml
|
||||
@@ -64,6 +64,15 @@
|
||||
the invoking terminal is determined to be UTF-8 compatible).</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
+ <varlistentry id='lesssecure'>
|
||||
+ <term><varname>$SYSTEMD_LESSSECURE</varname></term>
|
||||
+
|
||||
+ <listitem><para>Takes a boolean argument. Overrides the <varname>$LESSSECURE</varname> environment
|
||||
+ variable when invoking the pager, which controls the "secure" mode of less (which disables commands
|
||||
+ such as <literal>|</literal> which allow to easily shell out to external command lines). By default
|
||||
+ less secure mode is enabled, with this setting it may be disabled.</para></listitem>
|
||||
+ </varlistentry>
|
||||
+
|
||||
<varlistentry id='colors'>
|
||||
<term><varname>$SYSTEMD_COLORS</varname></term>
|
||||
|
||||
diff --git a/man/systemctl.xml b/man/systemctl.xml
|
||||
index 1c55028837..a3f0c3041a 100644
|
||||
--- a/man/systemctl.xml
|
||||
+++ b/man/systemctl.xml
|
||||
@@ -2240,6 +2240,7 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
|
||||
<xi:include href="less-variables.xml" xpointer="pager"/>
|
||||
<xi:include href="less-variables.xml" xpointer="less"/>
|
||||
<xi:include href="less-variables.xml" xpointer="lesscharset"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="lesssecure"/>
|
||||
<xi:include href="less-variables.xml" xpointer="colors"/>
|
||||
<xi:include href="less-variables.xml" xpointer="urlify"/>
|
||||
</refsect1>
|
||||
diff --git a/man/systemd.xml b/man/systemd.xml
|
||||
index a9040545c2..c92cfef776 100644
|
||||
--- a/man/systemd.xml
|
||||
+++ b/man/systemd.xml
|
||||
@@ -692,6 +692,7 @@
|
||||
<xi:include href="less-variables.xml" xpointer="pager"/>
|
||||
<xi:include href="less-variables.xml" xpointer="less"/>
|
||||
<xi:include href="less-variables.xml" xpointer="lesscharset"/>
|
||||
+ <xi:include href="less-variables.xml" xpointer="lesssecure"/>
|
||||
<xi:include href="less-variables.xml" xpointer="colors"/>
|
||||
<xi:include href="less-variables.xml" xpointer="urlify"/>
|
||||
|
||||
diff --git a/src/shared/pager.c b/src/shared/pager.c
|
||||
index e03be6d23b..9c21881241 100644
|
||||
--- a/src/shared/pager.c
|
||||
+++ b/src/shared/pager.c
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "copy.h"
|
||||
+#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "io-util.h"
|
||||
@@ -152,8 +153,7 @@ int pager_open(PagerFlags flags) {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
- /* Initialize a good charset for less. This is
|
||||
- * particularly important if we output UTF-8
|
||||
+ /* Initialize a good charset for less. This is particularly important if we output UTF-8
|
||||
* characters. */
|
||||
less_charset = getenv("SYSTEMD_LESSCHARSET");
|
||||
if (!less_charset && is_locale_utf8())
|
||||
@@ -164,6 +164,25 @@ int pager_open(PagerFlags flags) {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
+ /* People might invoke us from sudo, don't needlessly allow less to be a way to shell out
|
||||
+ * privileged stuff. */
|
||||
+ r = getenv_bool("SYSTEMD_LESSSECURE");
|
||||
+ if (r == 0) { /* Remove env var if off */
|
||||
+ if (unsetenv("LESSSECURE") < 0) {
|
||||
+ log_error_errno(errno, "Failed to uset environment variable LESSSECURE: %m");
|
||||
+ _exit(EXIT_FAILURE);
|
||||
+ }
|
||||
+ } else {
|
||||
+ /* Set env var otherwise */
|
||||
+ if (r < 0)
|
||||
+ log_warning_errno(r, "Unable to parse $SYSTEMD_LESSSECURE, ignoring: %m");
|
||||
+
|
||||
+ if (setenv("LESSSECURE", "1", 1) < 0) {
|
||||
+ log_error_errno(errno, "Failed to set environment variable LESSSECURE: %m");
|
||||
+ _exit(EXIT_FAILURE);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
if (pager_args) {
|
||||
r = loop_write(exe_name_pipe[1], pager_args[0], strlen(pager_args[0]) + 1, false);
|
||||
if (r < 0) {
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
From 352ab9d74049b4ac694fdba1a6e67339f12ded93 Mon Sep 17 00:00:00 2001
|
||||
From: Dan Streetman <ddstreet@canonical.com>
|
||||
Date: Fri, 23 Oct 2020 15:50:28 -0400
|
||||
Subject: [PATCH] test: ignore ENOMEDIUM error from sd_pid_get_cgroup()
|
||||
|
||||
Ubuntu builds on the Launchpad infrastructure run inside a chroot that does
|
||||
not have the sysfs cgroup dirs mounted, so this call will return ENOMEDIUM
|
||||
from cg_unified_cached() during the build-time testing, for example when
|
||||
building the package in a Launchpad PPA.
|
||||
---
|
||||
src/libsystemd/sd-login/test-login.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c
|
||||
index 0494fc77ba..5f61a8f8b6 100644
|
||||
--- a/src/libsystemd/sd-login/test-login.c
|
||||
+++ b/src/libsystemd/sd-login/test-login.c
|
||||
@@ -68,7 +68,7 @@ static void test_login(void) {
|
||||
|
||||
r = sd_pid_get_cgroup(0, &cgroup);
|
||||
log_info("sd_pid_get_cgroup(0, …) → %s / \"%s\"", e(r), strnull(cgroup));
|
||||
- assert_se(r == 0);
|
||||
+ assert_se(IN_SET(r, 0, -ENOMEDIUM));
|
||||
|
||||
r = sd_uid_get_display(u2, &display_session);
|
||||
log_info("sd_uid_get_display("UID_FMT", …) → %s / \"%s\"", u2, e(r), strnull(display_session));
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,263 @@
|
||||
From 1b5b507cd2d1d7a2b053151abb548475ad9c5c3b Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Mon, 12 Oct 2020 18:57:32 +0200
|
||||
Subject: [PATCH 2/3] test-login: always test sd_pid_get_owner_uid(), modernize
|
||||
|
||||
A long time some function only worked when in a session, and the test
|
||||
didn't execute them when sd_pid_get_session() failed. Let's always call
|
||||
them to increase coverage.
|
||||
|
||||
While at it, let's test for ==0 not >=0 where we don't expect the function
|
||||
to return anything except 0 or error.
|
||||
---
|
||||
src/libsystemd/sd-login/test-login.c | 131 ++++++++++++++-------------
|
||||
1 file changed, 70 insertions(+), 61 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c
|
||||
index c0c77e0471..0494fc77ba 100644
|
||||
--- a/src/libsystemd/sd-login/test-login.c
|
||||
+++ b/src/libsystemd/sd-login/test-login.c
|
||||
@@ -5,21 +5,22 @@
|
||||
#include "sd-login.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
+#include "errno-list.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
-#include "util.h"
|
||||
+#include "user-util.h"
|
||||
|
||||
static char* format_uids(char **buf, uid_t* uids, int count) {
|
||||
- int pos = 0, k, inc;
|
||||
+ int pos = 0, inc;
|
||||
size_t size = (DECIMAL_STR_MAX(uid_t) + 1) * count + 1;
|
||||
|
||||
assert_se(*buf = malloc(size));
|
||||
|
||||
- for (k = 0; k < count; k++) {
|
||||
+ for (int k = 0; k < count; k++) {
|
||||
sprintf(*buf + pos, "%s"UID_FMT"%n", k > 0 ? " " : "", uids[k], &inc);
|
||||
pos += inc;
|
||||
}
|
||||
@@ -30,6 +31,10 @@ static char* format_uids(char **buf, uid_t* uids, int count) {
|
||||
return *buf;
|
||||
}
|
||||
|
||||
+static const char *e(int r) {
|
||||
+ return r == 0 ? "OK" : errno_to_name(r);
|
||||
+}
|
||||
+
|
||||
static void test_login(void) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
_cleanup_free_ char *pp = NULL, *qq = NULL,
|
||||
@@ -39,65 +44,71 @@ static void test_login(void) {
|
||||
*seat = NULL, *session = NULL,
|
||||
*unit = NULL, *user_unit = NULL, *slice = NULL;
|
||||
int r;
|
||||
- uid_t u, u2;
|
||||
- char *t, **seats, **sessions;
|
||||
+ uid_t u, u2 = UID_INVALID;
|
||||
+ char *t, **seats = NULL, **sessions = NULL;
|
||||
|
||||
r = sd_pid_get_unit(0, &unit);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
- log_info("sd_pid_get_unit(0, …) → \"%s\"", strna(unit));
|
||||
+ log_info("sd_pid_get_unit(0, …) → %s / \"%s\"", e(r), strnull(unit));
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
|
||||
r = sd_pid_get_user_unit(0, &user_unit);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
- log_info("sd_pid_get_user_unit(0, …) → \"%s\"", strna(user_unit));
|
||||
+ log_info("sd_pid_get_user_unit(0, …) → %s / \"%s\"", e(r), strnull(user_unit));
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
|
||||
r = sd_pid_get_slice(0, &slice);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
- log_info("sd_pid_get_slice(0, …) → \"%s\"", strna(slice));
|
||||
+ log_info("sd_pid_get_slice(0, …) → %s / \"%s\"", e(r), strnull(slice));
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
+
|
||||
+ r = sd_pid_get_owner_uid(0, &u2);
|
||||
+ log_info("sd_pid_get_owner_uid(0, …) → %s / "UID_FMT, e(r), u2);
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
|
||||
r = sd_pid_get_session(0, &session);
|
||||
- if (r < 0) {
|
||||
- log_warning_errno(r, "sd_pid_get_session(0, …): %m");
|
||||
- if (r == -ENODATA)
|
||||
- log_info("Seems we are not running in a session, skipping some tests.");
|
||||
- } else {
|
||||
- log_info("sd_pid_get_session(0, …) → \"%s\"", session);
|
||||
-
|
||||
- assert_se(sd_pid_get_owner_uid(0, &u2) == 0);
|
||||
- log_info("sd_pid_get_owner_uid(0, …) → "UID_FMT, u2);
|
||||
-
|
||||
- assert_se(sd_pid_get_cgroup(0, &cgroup) == 0);
|
||||
- log_info("sd_pid_get_cgroup(0, …) → \"%s\"", cgroup);
|
||||
-
|
||||
- r = sd_uid_get_display(u2, &display_session);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
- log_info("sd_uid_get_display("UID_FMT", …) → \"%s\"",
|
||||
- u2, strnull(display_session));
|
||||
-
|
||||
- assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == 0);
|
||||
- sd_peer_get_session(pair[0], &pp);
|
||||
- sd_peer_get_session(pair[1], &qq);
|
||||
- assert_se(streq_ptr(pp, qq));
|
||||
-
|
||||
- r = sd_uid_get_sessions(u2, false, &sessions);
|
||||
+ log_info("sd_pid_get_session(0, …) → %s / \"%s\"", e(r), strnull(session));
|
||||
+
|
||||
+ r = sd_pid_get_cgroup(0, &cgroup);
|
||||
+ log_info("sd_pid_get_cgroup(0, …) → %s / \"%s\"", e(r), strnull(cgroup));
|
||||
+ assert_se(r == 0);
|
||||
+
|
||||
+ r = sd_uid_get_display(u2, &display_session);
|
||||
+ log_info("sd_uid_get_display("UID_FMT", …) → %s / \"%s\"", u2, e(r), strnull(display_session));
|
||||
+ if (u2 == UID_INVALID)
|
||||
+ assert_se(r == -EINVAL);
|
||||
+ else
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
+
|
||||
+ assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == 0);
|
||||
+ sd_peer_get_session(pair[0], &pp);
|
||||
+ sd_peer_get_session(pair[1], &qq);
|
||||
+ assert_se(streq_ptr(pp, qq));
|
||||
+
|
||||
+ r = sd_uid_get_sessions(u2, false, &sessions);
|
||||
+ assert_se(t = strv_join(sessions, " "));
|
||||
+ log_info("sd_uid_get_sessions("UID_FMT", …) → %s \"%s\"", u2, e(r), t);
|
||||
+ if (u2 == UID_INVALID)
|
||||
+ assert_se(r == -EINVAL);
|
||||
+ else {
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == (int) strv_length(sessions));
|
||||
- assert_se(t = strv_join(sessions, " "));
|
||||
- strv_free(sessions);
|
||||
- log_info("sd_uid_get_sessions("UID_FMT", …) → [%i] \"%s\"", u2, r, t);
|
||||
- free(t);
|
||||
+ }
|
||||
+ sessions = strv_free(sessions);
|
||||
+ free(t);
|
||||
|
||||
- assert_se(r == sd_uid_get_sessions(u2, false, NULL));
|
||||
+ assert_se(r == sd_uid_get_sessions(u2, false, NULL));
|
||||
|
||||
- r = sd_uid_get_seats(u2, false, &seats);
|
||||
+ r = sd_uid_get_seats(u2, false, &seats);
|
||||
+ assert_se(t = strv_join(seats, " "));
|
||||
+ log_info("sd_uid_get_seats("UID_FMT", …) → %s \"%s\"", u2, e(r), t);
|
||||
+ if (u2 == UID_INVALID)
|
||||
+ assert_se(r == -EINVAL);
|
||||
+ else {
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == (int) strv_length(seats));
|
||||
- assert_se(t = strv_join(seats, " "));
|
||||
- strv_free(seats);
|
||||
- log_info("sd_uid_get_seats("UID_FMT", …) → [%i] \"%s\"", u2, r, t);
|
||||
- free(t);
|
||||
-
|
||||
- assert_se(r == sd_uid_get_seats(u2, false, NULL));
|
||||
}
|
||||
+ seats = strv_free(seats);
|
||||
+ free(t);
|
||||
+
|
||||
+ assert_se(r == sd_uid_get_seats(u2, false, NULL));
|
||||
|
||||
if (session) {
|
||||
r = sd_session_is_active(session);
|
||||
@@ -109,7 +120,7 @@ static void test_login(void) {
|
||||
log_info("sd_session_is_remote(\"%s\") → %s", session, yes_no(r));
|
||||
|
||||
r = sd_session_get_state(session, &state);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(r == 0);
|
||||
log_info("sd_session_get_state(\"%s\") → \"%s\"", session, state);
|
||||
|
||||
assert_se(sd_session_get_uid(session, &u) >= 0);
|
||||
@@ -123,16 +134,16 @@ static void test_login(void) {
|
||||
log_info("sd_session_get_class(\"%s\") → \"%s\"", session, class);
|
||||
|
||||
r = sd_session_get_display(session, &display);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
log_info("sd_session_get_display(\"%s\") → \"%s\"", session, strna(display));
|
||||
|
||||
r = sd_session_get_remote_user(session, &remote_user);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
log_info("sd_session_get_remote_user(\"%s\") → \"%s\"",
|
||||
session, strna(remote_user));
|
||||
|
||||
r = sd_session_get_remote_host(session, &remote_host);
|
||||
- assert_se(r >= 0 || r == -ENODATA);
|
||||
+ assert_se(IN_SET(r, 0, -ENODATA));
|
||||
log_info("sd_session_get_remote_host(\"%s\") → \"%s\"",
|
||||
session, strna(remote_host));
|
||||
|
||||
@@ -161,7 +172,7 @@ static void test_login(void) {
|
||||
assert_se(r == -ENODATA);
|
||||
}
|
||||
|
||||
- assert_se(sd_uid_get_state(u, &state2) >= 0);
|
||||
+ assert_se(sd_uid_get_state(u, &state2) == 0);
|
||||
log_info("sd_uid_get_state("UID_FMT", …) → %s", u, state2);
|
||||
}
|
||||
|
||||
@@ -173,11 +184,11 @@ static void test_login(void) {
|
||||
assert_se(sd_uid_is_on_seat(u, 0, seat) > 0);
|
||||
|
||||
r = sd_seat_get_active(seat, &session2, &u2);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(r == 0);
|
||||
log_info("sd_seat_get_active(\"%s\", …) → \"%s\", "UID_FMT, seat, session2, u2);
|
||||
|
||||
r = sd_uid_is_on_seat(u, 1, seat);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(IN_SET(r, 0, 1));
|
||||
assert_se(!!r == streq(session, session2));
|
||||
|
||||
r = sd_seat_get_sessions(seat, &sessions, &uids, &n);
|
||||
@@ -185,8 +196,8 @@ static void test_login(void) {
|
||||
assert_se(r == (int) strv_length(sessions));
|
||||
assert_se(t = strv_join(sessions, " "));
|
||||
strv_free(sessions);
|
||||
- log_info("sd_seat_get_sessions(\"%s\", …) → %i, \"%s\", [%i] {%s}",
|
||||
- seat, r, t, n, format_uids(&buf, uids, n));
|
||||
+ log_info("sd_seat_get_sessions(\"%s\", …) → %s, \"%s\", [%u] {%s}",
|
||||
+ seat, e(r), t, n, format_uids(&buf, uids, n));
|
||||
free(t);
|
||||
|
||||
assert_se(sd_seat_get_sessions(seat, NULL, NULL, NULL) == r);
|
||||
@@ -204,7 +215,7 @@ static void test_login(void) {
|
||||
|
||||
r = sd_seat_get_active(NULL, &t, NULL);
|
||||
assert_se(IN_SET(r, 0, -ENODATA));
|
||||
- log_info("sd_seat_get_active(NULL, …) (active session on current seat) → %s", strnull(t));
|
||||
+ log_info("sd_seat_get_active(NULL, …) (active session on current seat) → %s / \"%s\"", e(r), strnull(t));
|
||||
free(t);
|
||||
|
||||
r = sd_get_sessions(&sessions);
|
||||
@@ -244,13 +255,11 @@ static void test_login(void) {
|
||||
|
||||
static void test_monitor(void) {
|
||||
sd_login_monitor *m = NULL;
|
||||
- unsigned n;
|
||||
int r;
|
||||
|
||||
- r = sd_login_monitor_new("session", &m);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_login_monitor_new("session", &m) == 0);
|
||||
|
||||
- for (n = 0; n < 5; n++) {
|
||||
+ for (unsigned n = 0; n < 5; n++) {
|
||||
struct pollfd pollfd = {};
|
||||
usec_t timeout, nw;
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
11
systemd.spec
11
systemd.spec
@ -16,7 +16,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 243
|
||||
Release: 59
|
||||
Release: 60
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -189,6 +189,12 @@ Patch0141: backport-sd-device-use-right-type-for-usec_initialized.patch
|
||||
Patch0142: backport-fix-CVE-2022-3821.patch
|
||||
Patch0143: backport-cap-list-parse-numerical-capabilities.patch
|
||||
Patch0144: backport-test-use-cap_last_cap-for-max-supported.patch
|
||||
Patch0145: backport-CVE-2023-26604-man-share-description-of-SYSTEMD_COLORS.patch
|
||||
Patch0146: backport-CVE-2023-26604-man-document-all-pager-variables-for-systemctl.patch
|
||||
Patch0147: backport-CVE-2023-26604-pager-set-LESSSECURE-whenver-we-invoke-a-pager.patch
|
||||
Patch0148: backport-CVE-2023-26604-test-login-always-test-sd_pid_get_owner_uid.patch
|
||||
Patch0149: backport-CVE-2023-26604-pager-make-pager-secure-when-under-euid-is-changed.patch
|
||||
Patch0150: backport-CVE-2023-26604-test-ignore-ENOMEDIUM-error-from-sd_pid_get_cgroup.patch
|
||||
|
||||
#openEuler
|
||||
Patch9002: 1509-fix-journal-file-descriptors-leak-problems.patch
|
||||
@ -1596,6 +1602,9 @@ fi
|
||||
%exclude /usr/share/man/man3/*
|
||||
|
||||
%changelog
|
||||
* Tue Mar 14 2023 huyubiao <huyubiao@huawei.com> - 243-60
|
||||
- fix CVE-2023-26604
|
||||
|
||||
* Mon Nov 7 2022 yangmingtai <yangmingtai@huawei.com> - 243-59
|
||||
- fix CVE-2022-3821 and backport patch to fix ci failed
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user