linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>,
	Frederick Lawler <fred@cloudflare.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-cachefs@redhat.com, linux-cifs@vger.kernel.org,
	samba-technical@lists.samba.org, linux-mm@kvack.org,
	linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org,
	linux-security-module@vger.kernel.org, netdev@vger.kernel.org,
	keyrings@vger.kernel.org, selinux@vger.kernel.org,
	serge@hallyn.com, amir73il@gmail.com, kernel-team@cloudflare.com,
	Jeff Moyer <jmoyer@redhat.com>, Paul Moore <paul@paul-moore.com>,
	Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH v3] cred: Propagate security_prepare_creds() error code
Date: Tue, 14 Jun 2022 07:39:24 -0700	[thread overview]
Message-ID: <b9d27b14-3b45-470d-9c7b-c6f7fb0ca8a5@schaufler-ca.com> (raw)
In-Reply-To: <87y1xzyhub.fsf@email.froward.int.ebiederm.org>

On 6/13/2022 9:44 PM, Eric W. Biederman wrote:
> Frederick Lawler <fred@cloudflare.com> writes:
>
>> Hi Eric,
>>
>> On 6/13/22 12:04 PM, Eric W. Biederman wrote:
>>> Frederick Lawler <fred@cloudflare.com> writes:
>>>
>>>> While experimenting with the security_prepare_creds() LSM hook, we
>>>> noticed that our EPERM error code was not propagated up the callstack.
>>>> Instead ENOMEM is always returned.  As a result, some tools may send a
>>>> confusing error message to the user:
>>>>
>>>> $ unshare -rU
>>>> unshare: unshare failed: Cannot allocate memory
>>>>
>>>> A user would think that the system didn't have enough memory, when
>>>> instead the action was denied.
>>>>
>>>> This problem occurs because prepare_creds() and prepare_kernel_cred()
>>>> return NULL when security_prepare_creds() returns an error code. Later,
>>>> functions calling prepare_creds() and prepare_kernel_cred() return
>>>> ENOMEM because they assume that a NULL meant there was no memory
>>>> allocated.
>>>>
>>>> Fix this by propagating an error code from security_prepare_creds() up
>>>> the callstack.
>>> Why would it make sense for security_prepare_creds to return an error
>>> code other than ENOMEM?
>>>   > That seems a bit of a violation of what that function is supposed to do
>>>
>> The API allows LSM authors to decide what error code is returned from the
>> cred_prepare hook. security_task_alloc() is a similar hook, and has its return
>> code propagated.
> It is not an api.  It is an implementation detail of the linux kernel.
> It is a set of convenient functions that do a job.

Yeah, sort of. We still don't want to change it willy-nilly as it
has multiple users from both ends.

>
> The general rule is we don't support cases without an in-tree user.  I
> don't see an in-tree user.

Unfortunately, the BPF security module allows arbitrary out-of-tree programs
in any hook. While returns other than -ENOMEM may be nonsensical, they are
possible. This is driving the LSM infrastructure in the direction of being
an API, in that users of BPF need to know what they are allowed to do in
their hook programs.

> I'm proposing we follow security_task_allocs() pattern, and add visibility for
> failure cases in prepare_creds().
> I am asking why we would want to.  Especially as it is not an API, and I
> don't see any good reason for anything but an -ENOMEM failure to be
> supported.
>
> Without an in-tree user that cares it is probably better to go the
> opposite direction and remove the possibility of return anything but
> memory allocation failure.  That will make it clearer to implementors
> that a general error code is not supported and this is not a location
> to implement policy, this is only a hook to allocate state for the LSM.

The more clearly we define how a function is to be used the more it looks
like an API. The LSM security_ interfaces are not well designed. They have
appeared, changed and disappeared organically. This was fine when there was
one user and tolerable when there were a few, but is getting to be painful
as the number of security modules increases and their assumptions and
behavior diverges from subject/object mandatory access control.


>>> I have probably missed a very interesting discussion where that was
>>> mentioned but I don't see link to the discussion or anything explaining
>>> why we want to do that in this change.
>>>
>> AFAIK, this is the start of the discussion.
> You were on v3 and had an out of tree piece of code so I assumed someone
> had at least thought about why you want to implement policy in a piece
> of code whose only purpose is to allocate memory to store state.

I agree with both sides to some extent. The caller shouldn't assume that
the only possible error is -ENOMEM, but the LSM hook should never do anything
else, either. If there is a legitimate case where an different error may
be returned and a reasonable, different action the caller(s) would take in
that case, the change makes sense. Otherwise, no.

> Eric
>


  reply	other threads:[~2022-06-14 14:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 15:09 Frederick Lawler
2022-06-09 23:18 ` Eric Biggers
2022-06-13 13:46   ` Frederick Lawler
2022-06-13 17:04 ` Eric W. Biederman
2022-06-13 20:52   ` Frederick Lawler
2022-06-14  4:44     ` Eric W. Biederman
2022-06-14 14:39       ` Casey Schaufler [this message]
2022-06-14 16:06       ` Frederick Lawler
2022-06-14 16:30         ` Eric W. Biederman
2022-06-14 18:59           ` Frederick Lawler
2022-06-15 10:30             ` Christian Brauner
2022-06-15 14:14               ` Paul Moore
2022-06-15 15:06                 ` Ignat Korchagin
2022-06-15 15:33                   ` Paul Moore
2022-06-15 15:55                     ` Casey Schaufler
2022-06-16 15:04                       ` Frederick Lawler
2022-06-15 15:30                 ` Casey Schaufler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9d27b14-3b45-470d-9c7b-c6f7fb0ca8a5@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=amir73il@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=fred@cloudflare.com \
    --cc=jmoyer@redhat.com \
    --cc=kernel-team@cloudflare.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=samba-technical@lists.samba.org \
    --cc=selinux@vger.kernel.org \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox