18140 Commits

Author SHA1 Message Date
Matthias Clasen
93d7037dde settings: Register the keyfile backend as extension
This was not done previously because the backend
could not be instantiated without parameters.
2021-06-23 10:05:44 -05:00
Matthias Clasen
a172d82d9a settings: Make the keyfile backend parameterless
Make it possible to instantiate a keyfile settings backend
without specifying parameters, by turning the arguments to
the new() function into construct-only properties. If no
filename is specified, default to
$XDG_CONFIG_HOME/glib-2.0/settings/keyfile
2021-06-23 10:05:44 -05:00
Simon McVittie
d4f0cf25ba credentials: Invalid Linux struct ucred means "no information"
On Linux, if getsockopt SO_PEERCRED is used on a TCP socket, one
might expect it to fail with an appropriate error like ENOTSUP or
EPROTONOSUPPORT. However, it appears that in fact it succeeds, but
yields a credentials structure with pid 0, uid -1 and gid -1. These
are not real process, user and group IDs that can be allocated to a
real process (pid 0 needs to be reserved to give kill(0) its documented
special semantics, and similarly uid and gid -1 need to be reserved for
setresuid() and setresgid()) so it is not meaningful to signal them to
high-level API users.

An API user with Linux-specific knowledge can still inspect these fields
via g_credentials_get_native() if desired.

Similarly, if SO_PASSCRED is used to receive a SCM_CREDENTIALS message
on a receiving Unix socket, but the sending socket had not enabled
SO_PASSCRED at the time that the message was sent, it is possible
for it to succeed but yield a credentials structure with pid 0, uid
/proc/sys/kernel/overflowuid and gid /proc/sys/kernel/overflowgid. Even
if we were to read those pseudo-files, we cannot distinguish between
the overflow IDs and a real process that legitimately has the same IDs
(typically they are set to 'nobody' and 'nogroup', which can be used
by a real process), so we detect this situation by noticing that
pid == 0, and to save syscalls we do not read the overflow IDs from
/proc at all.

This results in a small API change: g_credentials_is_same_user() now
returns FALSE if we compare two credentials structures that are both
invalid. This seems like reasonable, conservative behaviour: if we cannot
prove that they are the same user, we should assume they are not.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-23 10:05:44 -05:00
Simon McVittie
381594e621 GDBus: prefer getsockopt()-style credentials-passing APIs
Conceptually, a D-Bus server is really trying to determine the credentials
of (the process that initiated) a connection, not the credentials that
the process had when it sent a particular message. Ideally, it does
this with a getsockopt()-style API that queries the credentials of the
connection's initiator without requiring any particular cooperation from
that process, avoiding a class of possible failures.

The leading '\0' in the D-Bus protocol is primarily a workaround
for platforms where the message-based credentials-passing API is
strictly better than the getsockopt()-style API (for example, on
FreeBSD, SCM_CREDS includes a process ID but getpeereid() does not),
or where the getsockopt()-style API does not exist at all. As a result
libdbus, the reference implementation of D-Bus, does not implement
Linux SCM_CREDENTIALS at all - it has no reason to do so, because the
SO_PEERCRED socket option is equally informative.

This change makes GDBusServer on Linux more closely match the behaviour
of libdbus.

In particular, GNOME/glib#1831 indicates that when a libdbus client
connects to a GDBus server, recvmsg() sometimes yields a SCM_CREDENTIALS
message with cmsg_data={pid=0, uid=65534, gid=65534}. I think this is
most likely a race condition in the early steps to connect:

        client           server
    connect
                         accept
    send '\0' <- race -> set SO_PASSCRED = 1
                         receive '\0'

If the server wins the race:

        client           server
    connect
                         accept
                         set SO_PASSCRED = 1
    send '\0'
                         receive '\0'

then everything is fine. However, if the client wins the race:

        client           server
    connect
                         accept
    send '\0'
                         set SO_PASSCRED = 1
                         receive '\0'

then the kernel does not record credentials for the message containing
'\0' (because SO_PASSCRED was 0 at the time). However, by the time the
server receives the message, the kernel knows that credentials are
desired. I would have expected the kernel to omit the credentials header
in this case, but it seems that instead, it synthesizes a credentials
structure with a dummy process ID 0, a dummy uid derived from
/proc/sys/kernel/overflowuid and a dummy gid derived from
/proc/sys/kernel/overflowgid.

In an unconfigured GDBusServer, hitting this race condition results in
falling back to DBUS_COOKIE_SHA1 authentication, which in practice usually
succeeds in authenticating the peer's uid. However, we encourage AF_UNIX
servers on Unix platforms to allow only EXTERNAL authentication as a
security-hardening measure, because DBUS_COOKIE_SHA1 relies on a series
of assumptions including a cryptographically strong PRNG and a shared
home directory with no write access by others, which are not necessarily
true for all operating systems and users. EXTERNAL authentication will
fail if the server cannot determine the client's credentials.

In particular, this caused a regression when CVE-2019-14822 was fixed
in ibus, which appears to be resolved by this commit. Qt clients
(which use libdbus) intermittently fail to connect to an ibus server
(which uses GDBusServer), because ibus no longer allows DBUS_COOKIE_SHA1
authentication or non-matching uids.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Closes: https://gitlab.gnome.org/GNOME/glib/issues/1831
2021-06-23 10:05:44 -05:00
Simon McVittie
88cfb7adfa gcredentialsprivate: Document the various private macros
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-23 10:05:44 -05:00
Thomas Jost
8c012e96de gdbus-codegen: honor "Property.EmitsChangedSignal" annotations
Co-Authored-by: Andy Holmes <andrew.g.r.holmes@gmail.com>
2021-06-23 10:05:44 -05:00
Alberts Muktupāvels
2a6de14217 Add a test for per-desktop overrides 2021-06-23 10:03:59 -05:00
Allison Lortie
34feba5a1a glib-compile-schemas: Handle per-desktop overrides
Add a new syntax to override files: if the group name has a ':' in it,
it indicates that we want to override the default values of keys for
only one desktop. For example:

[org.gnome.desktop.interface:Unity]
font-name='Ubuntu 12'

Will override the settings, only if "Unity" is found in
XDG_CURRENT_DESKTOP. Multiple per-desktop overrides can be specified
for a given key: the one which comes first in XDG_CURRENT_DESKTOP will
be used.

https://bugzilla.gnome.org/show_bug.cgi?id=746592
2021-06-23 10:03:59 -05:00
Allison Lortie
4ab36dac09 gsettingsschema: Allow per-desktop overrides
Recognise a new 'd' option in schema keys which gives a dictionary of
per-desktop default values. This dictionary is searched for the items
found in XDG_CURRENT_DESKTOP, in the order. If nothing matches (or if
the option is missing) then the default value is used as before.

This feature was requested by Alberts Muktupāvels and this patch is
based on an approach devised by them.

https://bugzilla.gnome.org/show_bug.cgi?id=746592
2021-06-23 10:03:59 -05:00
Allison Lortie
b011294015 gsettings: cleanup default value lookup
There are a couple of different ways (and soon one more) to access the
default value of a key. Clean up the various places that access this to
avoid duplication.

https://bugzilla.gnome.org/show_bug.cgi?id=746592
2021-06-23 10:03:59 -05:00
Ondrej Holy
4088f3017d gfile: Limit access to files when copying
file_copy_fallback creates new files with default permissions and
set the correct permissions after the operation is finished. This
might cause that the files can be accessible by more users during
the operation than expected. Use G_FILE_CREATE_PRIVATE for the new
files to limit access to those files.
2021-06-23 10:03:59 -05:00
Colin Walters
19e32204f5 build-sys: Pass CFLAGS to $(DTRACE)
Fedora is using https://fedoraproject.org/wiki/Changes/Annobin
to try to ensure that all objects are built with hardening flags.
Pass down `CFLAGS` to ensure the SystemTap objects use them.
2021-06-23 10:03:59 -05:00
Ray Strode
57c9f770be spawn: add shebang line to script
downstream tools get confused when the script is missing a shebang
line, and having a shebang line doesn't hurt, so add one.
2021-06-23 10:03:59 -05:00
Robert Ancell
ef9034d956 codegen: Change pointer casting to remove type-punning warnings
The existing code was generating code with undefined results that modern compilers warn about:

accounts-generated.c:204:23: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     (GDBusArgInfo **) &_accounts_accounts_method_info_list_cached_users_OUT_ARG_pointers,
2021-06-23 10:03:59 -05:00
Ray Strode
906f65da2a gdbus unix addresses test: don't g_debug when also testing stdout
At the moment the gdbus-unix-addresses test will fail if
G_MESSAGES_DEBUG is set, since the test checks stdout, and the
test has a g_debug call.

This commit drops the g_debug call, which isn't that useful anyway.
2021-06-23 10:03:59 -05:00
Марко Костић
4d478191d9 Update Serbian translation 2019-03-03 10:30:57 +00:00
Serdar Sağlam
d5799dece0 Update Turkish translation 2019-02-12 14:23:51 +00:00
Simon McVittie
d202953c47 Merge branch 'backport-552-gvariant-test-alignment-glib-2-56' into 'glib-2-56'
Backport tests: Allocate gvariant data from the heap to guarantee alignment to glib-2-56

See merge request GNOME/glib!557
2019-01-04 14:14:56 +00:00
Simon McVittie
4ef58e5661 gvariant test: Also force alignment for tuple test data
glib!552 (commit 9eed22b3) fixed this for the tests that failed on i686,
but this additional test failed on Debian's s390x port
(IBM z/Architecture, 64-bit big-endian).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-04 11:27:05 +00:00
Mart Raudsepp
85c4031696 tests: Allocate gvariant data from the heap to guarantee alignment
On glib-2-58 branch we don't have !455, thus we need aligned data
for the gvariant tests to not fail on i686.

Fixes #1626
2018-12-21 12:05:42 +00:00
Philip Withnall
8723aba598 2.56.4
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2.56.4
2018-12-18 15:03:51 +00:00
Balázs Meskó
c90c012aa5 Update Hungarian translation 2018-12-17 09:22:42 +00:00
Matej Urbančič
d74daea9c8 Updated Slovenian translation 2018-12-02 18:02:29 +01:00
Marek Cernocky
20e5d8c566 Updated Czech translation 2018-11-24 10:10:53 +01:00
Christian Kirbach
1f09e82afc Update German translation 2018-11-15 19:48:29 +00:00
Aurimas Černius
1ca781a2cd Updated Lithuanian translation 2018-11-10 17:46:43 +02:00
Rafael Fontenelle
8f66afc198 Update Brazilian Portuguese translation 2018-11-08 05:51:40 +00:00
Anders Jonsson
c2ff887d72 Update Swedish translation 2018-11-07 18:31:22 +00:00
Philip Withnall
7f68c36f14 Merge branch 'bookmarkfile-self-move-glib-2-56' into 'glib-2-56'
bookmarkfile: Don't move an item if the uri has not changed (backport to glib-2-56)

See merge request GNOME/glib!459
2018-11-06 22:39:22 +00:00
Marco Trevisan (Treviño)
5c6f185e9b bookmarkfile: Don't move an item if the uri has not changed
This was causing a crash, because we were first removing an item, freeing
both the instance itself and the key, and then trying to reuse those.

So, in this case, instead of reassigning an item, we can just return TRUE
as we have already the item at the right place, while it's not needed to
update the modified timestamp, since no modification happened in reality.

Fixes #1588
2018-11-06 17:23:01 -05:00
Marco Trevisan (Treviño)
e46739f18c bookmarkfile: test that moving to the same name works
Verify that we can move a bookmark item to the same name, but actually this
causes a crash right now.
2018-11-06 17:22:55 -05:00
Piotr Drąg
bfd006f439 Update Polish translation 2018-11-06 17:21:16 +01:00
Kukuh Syafaat
2a9979bc38 Update Indonesian translation 2018-11-06 16:18:38 +00:00
Philip Withnall
fe4fd7319f Merge branch '1582-backport-411-422-ossfuzz-fixes-glib-2-56' into 'glib-2-56'
Resolve "Backport GMarkup/GVariant/GDBus fixes to glib-2-58 and glib-2-56" (glib-2-56)

See merge request GNOME/glib!448
2018-11-06 13:11:51 +00:00
Philip Withnall
40c8b41c67 glib: Port various callers to use g_utf8_validate_len()
These were callers which explicitly specified the string length to
g_utf8_validate(), when it couldn’t be negative, and hence should be
able to unconditionally benefit from the increased string handling
length.

At least one call site would have previously silently changed behaviour
if called with strings longer than G_MAXSSIZE in length.

Another call site was passing strlen(string) to g_utf8_validate(), which
seems pointless: just pass -1 instead, and let g_utf8_validate()
calculate the string length. Its behaviour on embedded nul bytes
wouldn’t change, as strlen() stops at the first one.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
5fab65270d gutf8: Add a g_utf8_validate_len() function
This is a variant of g_utf8_validate() which requires the length to be
specified, thereby allowing string lengths up to G_MAXSIZE rather than
just G_MAXSSIZE.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
b78fb7407a tests: Use g_assert_null() in gdbus-serialization test
This introduces no real functional changes (except when compiling with
G_DISABLE_ASSERT, in which case it fixes the test). Mostly just a code
cleanup.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
244da15037 tests: Tidy up GError handling in gdbus-serialization test
This introduces no functional changes; just a bit of code tidying.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
2eded09ba3 gvariant: Clarify internal documentation about GVariant type strings
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
8a83d15564 gdbusmessage: Check for valid GVariantType when parsing a variant blob
The code was checking whether the signature provided by the blob was a
valid D-Bus signature — but that’s a superset of a valid GVariant type
string, since a D-Bus signature is zero or more complete types. A
GVariant type string is exactly one complete type.

This meant that a D-Bus message with a header field containing a variant
with an empty type signature (for example) could cause a critical
warning in the code parsing it.

Fix that by checking whether the string is a valid type string too.

Unit test included.

oss-fuzz#9810

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
d993f42700 gdbusmessage: Fix a typo in a documentation comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
c387ab9c9d gdbusmessage: Clarify error returns for g_dbus_message_new_from_blob()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
20e8040a76 gdbusmessage: Improve documentation for g_dbus_message_get_header()
The caller is responsible for checking the type of the returned
GVariant.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
a770239d71 gdbusmessage: Validate type of message header signature field
Parsing a D-Bus message with the signature field in the message header
of type other than ‘g’ (GVariant type signature) would cause a critical
warning. Instead, we should return a runtime error.

Includes a test.

oss-fuzz#9825

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
355c4b4176 gvariant: Limit GVariant strings to G_MAXSSIZE
When validating a string to see if it’s valid UTF-8, we pass a gsize to
g_utf8_validate(), which only takes a gssize. For large gsize values,
this will result in the gssize actually being negative, which will
change g_utf8_validate()’s behaviour to stop at the first nul byte. That
would allow subsequent nul bytes through the string validator, against
its documented behaviour.

Add a test case.

oss-fuzz#10319

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
6cc2994dfb gvariant: Check tuple offsets against serialised data length
As with the previous commit, when getting a child from a serialised
tuple, check its offset against the length of the serialised data of the
tuple (excluding the length of the offset table). The offset was already
checked against the length of the entire serialised tuple (including the
offset table) — but a child should not be able to start inside the
offset table.

A test is included.

oss-fuzz#9803

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
fe9564feda gvariant: Check array offsets against serialised data length
When getting a child from a serialised variable array, check its offset
against the length of the serialised data of the array (excluding the
length of the offset table). The offset was already checked against the
length of the entire serialised array (including the offset table) — but a
child should not be able to start inside the offset table.

A test is included.

oss-fuzz#9803

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
a95e9f79d8 gvarianttype: Impose a recursion limit of 128 on variant types
Previously, GVariant has allowed ‘arbitrary’ recursion on GVariantTypes,
but this isn’t really feasible. We have to deal with GVariants from
untrusted sources, and the nature of GVariantType means that another
level of recursion (and hence, for example, another stack frame in your
application) can be added with a single byte in a variant type signature
in the input. This gives malicious input sources far too much leverage
to cause deep stack recursion or massive memory allocations which can
DoS an application.

Limit recursion to 128 levels (which should be more than enough for
anyone™), document it and add a test. This is, handily, also the limit
of 64 applied by the D-Bus specification (§(Valid Signatures)), plus a
bit to allow wrapping of D-Bus messages in additional layers of
variants.

oss-fuzz#9857

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-06 12:07:47 +00:00
Philip Withnall
22350edcd6 gvariant: Fix checking arithmetic for tuple element ends
When checking whether a serialised GVariant tuple is in normal form,
it’s possible for `offset_ptr -= offset_size` to underflow and wrap
around, resulting in gvs_read_unaligned_le() reading memory outside the
serialised GVariant bounds.

See §(Tuples) in gvariant-serialiser.c for the documentation on how
tuples are serialised. Briefly, all variable-length elements in the
tuple have an offset to their end stored in an array of offsets at the
end of the tuple. The width of each offset is in offset_size. offset_ptr
is added to the start of the serialised tuple to get the offset which is
currently being examined. The offset array is in reverse order compared
to the tuple elements, hence the subtraction.

The bug can be triggered if a tuple contains a load of variable-length
elements, each of whose length is actually zero (i.e. empty arrays).

Includes a unit test.

oss-fuzz#9801

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-02 16:07:09 +00:00
Philip Withnall
7ac9adbe1e ci: Update CI image to use 2-58:v1 from registry
The CI image which this glib-2-56 branch was previously using has been
deleted from the registry (master has moved on). Tweak the CI
configuration to use the glib-2-58 image, since there doesn’t seem to be
much point in adding an image just for glib-2-56, given how little
development is still needed on this branch.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-02 16:07:09 +00:00