2015-08-10 02:43:20

by Andy Lutomirski

[permalink] [raw]
Subject: kdbus_proc_permission (Re: [GIT PULL] kdbus updates for Greg)

I spotted this:

+/**
+ * kdbus_proc_permission() - check /proc permissions on target pid
+ * @pid_ns: namespace we operate in
+ * @cred: credentials of requestor
+ * @target: target process
+ *
+ * This checks whether a process with credentials @cred can access information
+ * of @target in the namespace @pid_ns. This tries to follow /proc permissions,
+ * but is slightly more restrictive.
+ *
+ * Return: The /proc access level (KDBUS_META_PROC_*) is returned.
+ */
+static unsigned int kdbus_proc_permission(const struct pid_namespace *pid_ns,
+ const struct cred *cred,
+ struct pid *target)

That code ended up in a pull request, although AFAICT it was never in
any patch email sent to me or to any public mailing list. I suspect
it was at least partially a response to one of my old reviews.

I haven't checked the context in which it's used, but in order for
kdbus_proc_permission to do what it claims to do, it appears to be
missing calls to security_inode_permission and
security_file_permission.

--Andy


2015-08-24 09:52:14

by David Herrmann

[permalink] [raw]
Subject: Re: kdbus_proc_permission (Re: [GIT PULL] kdbus updates for Greg)

Hi

On Mon, Aug 10, 2015 at 4:42 AM, Andy Lutomirski <[email protected]> wrote:
> I spotted this:
>
> +/**
> + * kdbus_proc_permission() - check /proc permissions on target pid
> + * @pid_ns: namespace we operate in
> + * @cred: credentials of requestor
> + * @target: target process
> + *
> + * This checks whether a process with credentials @cred can access information
> + * of @target in the namespace @pid_ns. This tries to follow /proc permissions,
> + * but is slightly more restrictive.
> + *
> + * Return: The /proc access level (KDBUS_META_PROC_*) is returned.
> + */
> +static unsigned int kdbus_proc_permission(const struct pid_namespace *pid_ns,
> + const struct cred *cred,
> + struct pid *target)
>
> That code ended up in a pull request, although AFAICT it was never in
> any patch email sent to me or to any public mailing list. I suspect
> it was at least partially a response to one of my old reviews.

Exactly. It's an attempt to model metadata access similar to /proc
access (thus, access to kdbusfs implies access to procfs, but not vice
versa (nor any implication on hidepid)).

> I haven't checked the context in which it's used, but in order for
> kdbus_proc_permission to do what it claims to do, it appears to be
> missing calls to security_inode_permission and
> security_file_permission.

Both are expected to be added by lsm patches (both hooks you mentioned
are empty if no lsm is selected).

Thanks
David

2015-08-31 15:37:58

by Andy Lutomirski

[permalink] [raw]
Subject: Re: kdbus_proc_permission (Re: [GIT PULL] kdbus updates for Greg)

On Mon, Aug 24, 2015 at 2:52 AM, David Herrmann <[email protected]> wrote:
> Hi
>
> On Mon, Aug 10, 2015 at 4:42 AM, Andy Lutomirski <[email protected]> wrote:
>> I spotted this:
>>
>> +/**
>> + * kdbus_proc_permission() - check /proc permissions on target pid
>> + * @pid_ns: namespace we operate in
>> + * @cred: credentials of requestor
>> + * @target: target process
>> + *
>> + * This checks whether a process with credentials @cred can access information
>> + * of @target in the namespace @pid_ns. This tries to follow /proc permissions,
>> + * but is slightly more restrictive.
>> + *
>> + * Return: The /proc access level (KDBUS_META_PROC_*) is returned.
>> + */
>> +static unsigned int kdbus_proc_permission(const struct pid_namespace *pid_ns,
>> + const struct cred *cred,
>> + struct pid *target)
>>
>> That code ended up in a pull request, although AFAICT it was never in
>> any patch email sent to me or to any public mailing list. I suspect
>> it was at least partially a response to one of my old reviews.
>
> Exactly. It's an attempt to model metadata access similar to /proc
> access (thus, access to kdbusfs implies access to procfs, but not vice
> versa (nor any implication on hidepid)).

I haven't looked at what calls this function, but I guess the model is
inaccurate and errs in the too-permissive direction.

Fedora actually labels inodes in /proc (ls -Zd /proc/???, for
example), but I don't know what it does with those labels.

>
>> I haven't checked the context in which it's used, but in order for
>> kdbus_proc_permission to do what it claims to do, it appears to be
>> missing calls to security_inode_permission and
>> security_file_permission.
>
> Both are expected to be added by lsm patches (both hooks you mentioned
> are empty if no lsm is selected).

Will that mean that existing MAC policies stop being fully enforced
(in effect) if kdbus is installed?

--Andy

2015-08-31 16:22:42

by David Herrmann

[permalink] [raw]
Subject: Re: kdbus_proc_permission (Re: [GIT PULL] kdbus updates for Greg)

Hi

On Mon, Aug 31, 2015 at 5:37 PM, Andy Lutomirski <[email protected]> wrote:
> On Mon, Aug 24, 2015 at 2:52 AM, David Herrmann <[email protected]> wrote:
>> On Mon, Aug 10, 2015 at 4:42 AM, Andy Lutomirski <[email protected]> wrote:
>>> I haven't checked the context in which it's used, but in order for
>>> kdbus_proc_permission to do what it claims to do, it appears to be
>>> missing calls to security_inode_permission and
>>> security_file_permission.
>>
>> Both are expected to be added by lsm patches (both hooks you mentioned
>> are empty if no lsm is selected).
>
> Will that mean that existing MAC policies stop being fully enforced
> (in effect) if kdbus is installed?

It means kdbus messages carry information about the sender, which LSMs
might prevent you to read via /proc. Just like you can send dbus
messages to a peer, which LSM-enhanced dbus-daemon might not allow. If
you use LSMs, we clearly advise you to wait for kdbus to gain LSM
support. We explicitly support legacy dbus1-compat for exactly such
reasons.

Thanks
David

2015-08-31 19:10:16

by Andy Lutomirski

[permalink] [raw]
Subject: Re: kdbus_proc_permission (Re: [GIT PULL] kdbus updates for Greg)

On Mon, Aug 31, 2015 at 9:22 AM, David Herrmann <[email protected]> wrote:
> Hi
>
> On Mon, Aug 31, 2015 at 5:37 PM, Andy Lutomirski <[email protected]> wrote:
>> On Mon, Aug 24, 2015 at 2:52 AM, David Herrmann <[email protected]> wrote:
>>> On Mon, Aug 10, 2015 at 4:42 AM, Andy Lutomirski <[email protected]> wrote:
>>>> I haven't checked the context in which it's used, but in order for
>>>> kdbus_proc_permission to do what it claims to do, it appears to be
>>>> missing calls to security_inode_permission and
>>>> security_file_permission.
>>>
>>> Both are expected to be added by lsm patches (both hooks you mentioned
>>> are empty if no lsm is selected).
>>
>> Will that mean that existing MAC policies stop being fully enforced
>> (in effect) if kdbus is installed?
>
> It means kdbus messages carry information about the sender, which LSMs
> might prevent you to read via /proc. Just like you can send dbus
> messages to a peer, which LSM-enhanced dbus-daemon might not allow.

It's a security-sensitive function that doesn't do what the name and
description suggest. Whether that's an active problem or not is
unknown, but it's certainly a maintainability problem.

> If
> you use LSMs, we clearly advise you to wait for kdbus to gain LSM
> support. We explicitly support legacy dbus1-compat for exactly such
> reasons.

This is not an acceptable attitude for security.

There are so many things wrong with your statement that I'll limit
myself to one of them: Fedora 23/Rawhide, which is the *reference*
platform, uses SELinux.

--Andy

>
> Thanks
> David



--
Andy Lutomirski
AMA Capital Management, LLC