Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp604986iog; Wed, 15 Jun 2022 08:32:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uDVEWmjce4KhoUcu6LlKEaI83cmk1orEbv0IGHYmy/p7NQmBk7yZgMRvwdJYH4bR1hQErv X-Received: by 2002:a05:6a02:28d:b0:408:8cbf:2a0c with SMTP id bk13-20020a056a02028d00b004088cbf2a0cmr335272pgb.422.1655307174460; Wed, 15 Jun 2022 08:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655307174; cv=none; d=google.com; s=arc-20160816; b=m97e/MUep9YISHfQ6tbGYZ+ZVmfrsvIwzyLBG5BHfegfxu+OSGDmm2+PmkWQSAq5tU uI9EVJBTaWjXUv2PnouWqeIQOVoeIxEqBbit5u43yxY/ntW56qcQAhKxe63e7mv0hTYP /4dfUIFkjAtVkR5p0u01Z5rf98Nt2TLPR2my2pSr3snDWc78nnnI1ldrDFj3iqsbL5/N kQzH7Ft2Gp0lQ7/AU22D7G1brk0GuhwdqFChJBa/WUfzbO7ij0o8IcekbOKbva8wiNIW Qu0qeOZ9ocSAsbMpV6CZ+yOxb5OXYAPlT9Ik5hzytcfgORIpBwuUZuPKIxrEqCtdMKIb Xp6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=11B5WPKRY2tRkgjEYdRBoSPOFjo4BPsuubkByd9K7pg=; b=gvqX2cdirBHRMFQuvUgmqP0KVSyRZh5nSC8wnlq/T2y/Km9f4dsS/Cxukdr26bfLus rLFw5at5MlqHRWpDSPF1FSU3rC8na5zBH1RWfgMmfMqnoIp6q0hjM17j8gAidovAVngM Ndy0yrSv/7tacjtTc0h4PFKqpHzMQrOm3SPwgSTeQ29DgCPMzZz5u0U8SVhFyUwQep1h xJiog/UwE4ZFlN5P8FaOr/qfNYLxhYBc3jejTbfLXzgDKpwFFtXk7AF2Px7vDO4EkLqh ZuQHbTuD5OO1vxf8z14xUoUAz79yL6NIBW2jgZXpvYoLOeH/8JsCVcJvn4ACp0dvkBKq fk+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=uGNI+kne; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a170902e5cf00b0015e583f7b54si21794808plf.14.2022.06.15.08.32.38; Wed, 15 Jun 2022 08:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=uGNI+kne; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245170AbiFOPbm (ORCPT + 99 others); Wed, 15 Jun 2022 11:31:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354888AbiFOPb0 (ORCPT ); Wed, 15 Jun 2022 11:31:26 -0400 Received: from sonic308-15.consmr.mail.ne1.yahoo.com (sonic308-15.consmr.mail.ne1.yahoo.com [66.163.187.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A5251320 for ; Wed, 15 Jun 2022 08:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655307059; bh=11B5WPKRY2tRkgjEYdRBoSPOFjo4BPsuubkByd9K7pg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=uGNI+knegf36LS4/r95FCmH1OIO2Qb7UoKt59iyF9oikWgwwSFTNvEG4yEcuvdPbE4qEN30i2ESCGNqKdEBkCQevJWzdR8hnoVEFp7RNBY3BFtrQG1vbPgYxYxeFBPRbyqOzl5gDjaqNNQjH/0R59eMZmjGvrZEHeJ7hTbWYSa8qplr8G3o+vj81scd4W3g5iiY1Ve4sz4GaEftb/VAFiSvZMfHRUJceQlMkRPJFgxymltmBobijwlKn8q8wQ8fwXbAj8wE8NLbJV4k31+1wfmDCB0Q4TTSNw+pSz9Akl5ljtPPMpg60PfE0/SnpND/X3yZlhzwn2eqYjMj/ggi1Dw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655307059; bh=nzKto+wf34xdzo8rg3XPBlWBO9kgnMZLItskjrwj2CE=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Yc5aFKrEXaFCh4wchT1b09se8uPrVACQgkGheVE4AoXgMIA42FPmEN0Dpw835oqyJWjW01kz+11n1+D8Z3xgD8Io1+4IBmy/Z1dVoNgQT8h2JEQGL3lSo91kO4RgSKHiW0MrHtJvPb2g2oD0XEafPlbRBwi1Yx6CKs9AhzZ9peBOXVAASD79R5EWIxGlytOfldu1ZJhUqFyO4fQQ2afa8eb1tmJHFB9YJSdkSspd7jJ3BATR1LWD17WxHWIrbhES2AYmmFEAV9QK/pkVOdUZq/puuh7CTqces8z5US3XtdeKgwRiRN2/zYtme/WTKRZGApgqKccgZCN4n6kaOzmruQ== X-YMail-OSG: AseB.CwVM1lua8AHdkQZIKwEJdX_bZzUQV8HgtUBvx0Mg_SfHvpBIc6pZZH9LXf wyXgW0rCD7nJ4uPONHyoFEKvBFXq.yPgrTIZa8NGqFu0MILuC4b3Gx2mROZ6uf53ulvOJASnLYA7 _zCrAHkUzALzqmwnYc33X_ICuSYNOp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3DYWorF4SYp5R gtNldRQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Wed, 15 Jun 2022 15:30:59 +0000 Received: by hermes--canary-production-ne1-799d7bd497-nrsk4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 031fc72c838fb57df744484e20b11ff5; Wed, 15 Jun 2022 15:30:58 +0000 (UTC) Message-ID: <4ae12ee6-959c-51cb-9d7a-54adb3a0ea53@schaufler-ca.com> Date: Wed, 15 Jun 2022 08:30:57 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v3] cred: Propagate security_prepare_creds() error code Content-Language: en-US To: Paul Moore , Christian Brauner Cc: Frederick Lawler , "Eric W. Biederman" , 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 , Casey Schaufler References: <20220608150942.776446-1-fred@cloudflare.com> <87tu8oze94.fsf@email.froward.int.ebiederm.org> <87y1xzyhub.fsf@email.froward.int.ebiederm.org> <859cb593-9e96-5846-2191-6613677b07c5@cloudflare.com> <87o7yvxl4x.fsf@email.froward.int.ebiederm.org> <9ed91f15-420c-3db6-8b3b-85438b02bf97@cloudflare.com> <20220615103031.qkzae4xr34wysj4b@wittgenstein> From: Casey Schaufler In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.20280 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On 6/15/2022 7:14 AM, Paul Moore wrote: > On Wed, Jun 15, 2022 at 6:30 AM Christian Brauner wrote: >> On Tue, Jun 14, 2022 at 01:59:08PM -0500, Frederick Lawler wrote: >>> On 6/14/22 11:30 AM, Eric W. Biederman wrote: >>>> Frederick Lawler writes: >>>> >>>>> On 6/13/22 11:44 PM, Eric W. Biederman wrote: >>>>>> Frederick Lawler writes: >>>>>> >>>>>>> Hi Eric, >>>>>>> >>>>>>> On 6/13/22 12:04 PM, Eric W. Biederman wrote: >>>>>>>> Frederick Lawler 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. >>>>>> The general rule is we don't support cases without an in-tree user. I >>>>>> don't see an in-tree user. >>>>>> >>>>>>> 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. >>>>>> >>>>> We're writing a LSM BPF policy, and not a new LSM. Our policy aims to solve >>>>> unprivileged unshare, similar to Debian's patch [1]. We're in a position such >>>>> that we can't use that patch because we can't block _all_ of our applications >>>>> from performing an unshare. We prefer a granular approach. LSM BPF seems like a >>>>> good choice. >>>> I am quite puzzled why doesn't /proc/sys/user/max_user_namespaces work >>>> for you? >>>> >>> We have the following requirements: >>> >>> 1. Allow list criteria >>> 2. root user must be able to create namespaces whenever >>> 3. Everything else not in 1 & 2 must be denied >>> >>> We use per task attributes to determine whether or not we allow/deny the >>> current call to unshare(). >>> >>> /proc/sys/user/max_user_namespaces limits are a bit broad for this level of >>> detail. >>> >>>>> Because LSM BPF exposes these hooks, we should probably treat them as an >>>>> API. From that perspective, userspace expects unshare to return a EPERM >>>>> when the call is denied permissions. >>>> The BPF code gets to be treated as a out of tree kernel module. >>>> >>>>>> 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. >>>>>> >>>>> That's a good point, and it's possible we're using the wrong hook for the >>>>> policy. Do you know of other hooks we can look into? >> Fwiw, from this commit it wasn't very clear what you wanted to achieve >> with this. It might be worth considering adding a new security hook for >> this. Within msft it recently came up SELinux might have an interest in >> something like this as well. > Just to clarify things a bit, I believe SELinux would have an interest > in a LSM hook capable of implementing an access control point for user > namespaces regardless of Microsoft's current needs. I suspect due to > the security relevant nature of user namespaces most other LSMs would > be interested as well; it seems like a well crafted hook would be > welcome by most folks I think. Smack isn't going to be interested in such a hook with the current user namespace behavior. User namespaces are a discretionary access control and privilege (capabilities) feature. Smack implements only mandatory access control. I would still endorse adding the hook as I could see MAC aspects (e.g. general xattr mapping) being implemented as part of user namespaces.