Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1519745iog; Tue, 14 Jun 2022 07:40:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/G49vOOmP7xcOrNYilBEDJKYHWQ42Q8RlvqK/jhYVShmdRkSf4v4VkJHXpqLPA05xRs0b X-Received: by 2002:a63:5610:0:b0:3f2:7e19:1697 with SMTP id k16-20020a635610000000b003f27e191697mr4707375pgb.74.1655217615056; Tue, 14 Jun 2022 07:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655217615; cv=none; d=google.com; s=arc-20160816; b=FF/B5yyaU5xsaw5VYp/RXd0UUl8sq767wUvSP/Uz8WwpB261pBR45qo3jQkHQqKDKV LkAMSZB0y+DETx0S7acgkhTRI3Lo7cVEA+ENzjlczKT70lOt4e7Kn6dS9sIbaBUePUUY IsUWt4WjS+rr+rIcVKHcS7klgs85XmvRqHfmY34B8uXxqhHbLqhXAY5FzpmO+9pKAiyM Sg+Cz/POnEu1pdEZ//cuWVDL02Vvul0BzigENIOjJvRXYbt7HJr6K7XZy3GKpIkZVLSl ROC0W79JlS9aWYTlKa+MpDNH9FW+zTTPn98LMbkgutLY3QKvMQVo8o6g5cWOJxJmN+Vv x8Ew== 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=Gk+oETTOXCvl6hKJwiKfVQx247tk4GOZsL6eS8rtiko=; b=qAz2DiH74qiBFvDq7jkktAv3eqQ5TzBSKZnhik6OTl81Jk/vURc91z8G8M7k9TN/s8 +t0D2ANlFYkeQ8Ie2m/0DN7lhXjacTipmPlfNLUlKgetNjr/OzD1C8KexzvoqnL31l+K uvitLe6GXJzkfniNGI/2zfLuTgecZxLZ82S3gMquz1/1EdgOa/HZChsTtfsEV29yDjk9 wiAA9dMWvh5UK8k9BxtN99p2elOUiXanIPYmg26wDDDshnLL0fdTA5dzOfJOF4OAFm8q zWBYxCfMjw9a1X+Wux2zfsoE675MBW+Zxj/wWTMw5XiaG38HCt8YJyhHs/ZNfQIoV8j3 p/lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=fRFIaqLc; 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 k186-20020a636fc3000000b003f9f41da8casi13742745pgc.14.2022.06.14.07.39.55; Tue, 14 Jun 2022 07:40:15 -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=fRFIaqLc; 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 S1347552AbiFNOjr (ORCPT + 99 others); Tue, 14 Jun 2022 10:39:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348579AbiFNOjf (ORCPT ); Tue, 14 Jun 2022 10:39:35 -0400 Received: from sonic316-26.consmr.mail.ne1.yahoo.com (sonic316-26.consmr.mail.ne1.yahoo.com [66.163.187.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBC428E11 for ; Tue, 14 Jun 2022 07:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655217569; bh=Gk+oETTOXCvl6hKJwiKfVQx247tk4GOZsL6eS8rtiko=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=fRFIaqLcfobn1LNVl0zrObgmf1hRdINcfRrUmpLcvSg3N0XuqRqgsWlZn5KxMH8l49l0D/abHlPhyAMUUO2GGCDJesuNH8Kpmaa3YgqX0v4VvY06jPrF5HScxPs366YY2ONTePIsLO6+bsIrz/oFE0ETMPJwiL5Fc7l9A5O52eqlUVEn2u6Hv446oiu3mS7Em6viRQw0Eerb2KZ/WLQFgjnvwinwyVZgUZqVxvTHUHjPZlUOcpmI7z+3pcZ+UkItKYPlyw2PX6J4h25WWNn2cNwE4TCrQ8Jlmq2H+Rgpn+lDH1kZESTNcLpJSjPABDc+86KBFATzQZC91mBFay1TDw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1655217569; bh=lRUBSB76OG5uRwjsyAtEUmfLb2iPR7sDD1HFxFWV66b=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Qf8RR/99yPxdxlUs+k9WbY66HCWw5zL3eg/AG/d8PaF2ZW7sRQsWq6gmO9A/l7NZTWI7UdRqKM5bDHbs6wupQkeVNnPnRU2E5aJ02Zk+dMR4zD7/s5cNknCyMX/GityW/LiHFvSd/XM7aartsEujYu09UY1GhHeq1D712AxFIJsY8aK/OlILZVF6egzn6sq8A7407LfIYkuACSJL8g1M/mmbhUgbiOsQ+CYK1mUY0RpwWvYX8gqa2sPB3WEOxqty1MukDjP2FW6rxr1jRuQBeQgVCqktKQ2g163zpXEobbQtJYRhHhj9nK4BnkDO+kDP4JBwDWeJ+g1U93EjktSC1Q== X-YMail-OSG: l34EP_4VM1mCZNS.V_eCLpRm9dh5I1CsXixH4kuccuVcaljnubvC2j4A6MMQ129 Y2Pi1pBZKWkGXaXj27i38I8ExPjiKP1Xgpcl4tm9xqnMiwV4KKbA3RIP0pHjrVRzdj7MRxTx9iBG YkdEQiInROMc3joMrXGCf9wmezHz6P8mJ.fFwD3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S2Z X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.ne1.yahoo.com with HTTP; Tue, 14 Jun 2022 14:39:29 +0000 Received: by hermes--canary-production-bf1-856dbf94db-nwd6f (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 047d13c43786ba81a547ff9186866ac4; Tue, 14 Jun 2022 14:39:27 +0000 (UTC) Message-ID: Date: Tue, 14 Jun 2022 07:39:24 -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: "Eric W. Biederman" , Frederick Lawler 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 , Paul Moore , Casey Schaufler References: <20220608150942.776446-1-fred@cloudflare.com> <87tu8oze94.fsf@email.froward.int.ebiederm.org> <87y1xzyhub.fsf@email.froward.int.ebiederm.org> From: Casey Schaufler In-Reply-To: <87y1xzyhub.fsf@email.froward.int.ebiederm.org> 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/13/2022 9: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. 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 >