Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp850059iog; Mon, 13 Jun 2022 14:26:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vU6cOMwlMgWuib9UHS1P0Z5zeYXswGEv7VNtuWR0FXzMklFfGKEy7eJc5lLTQYBWWWmylU X-Received: by 2002:a17:907:7f8d:b0:711:d8db:2714 with SMTP id qk13-20020a1709077f8d00b00711d8db2714mr1481096ejc.63.1655155611870; Mon, 13 Jun 2022 14:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655155611; cv=none; d=google.com; s=arc-20160816; b=k7NosSLBRxrRQaVUH/wd64he7Xp2Ggmusg3OROUPYBpslrhE73TJqFHy1EcaBC/9XB qila6CdIvkBnoOWknLNKZKQRfytvTa91DrracPIe134Il8SZNG3UWxHQGWyH1rnIvmAS dmO5WapKgi3aCahU0KUK19B7zz2aVGrHTbM773ojTErnVBVaRz7ELN4PqQddvjgAtqU/ wRFXmpH2g9eAGIot/lOs9yAD5/lemhciOfnd+0Xl0UrE3mhzo1MDoHR0KEt6rHYBeHb/ RHt31Ek8qaupws/qzFKmddSG+/SxUxc/7+1uCiLbrVvNL5nxnMnvsPq/x99ieejx6YF6 8Bjg== 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=Ie2xrfdugqSnUY/lUmZJBYqEw/Jj5HQgDROYZDI7Ljg=; b=dKgrcYWElcyEvsNNq7VLtPmutCGpTr+K2Kt/EtxRXT+8EX84kVTBhPv9Q+kLSr4u0p BW+wC4koQ5p5b6H3igaOH8y/3gjsRH4IIuvpaVSFIroFsjVQ/jGgrvTrJIhqxXGtTnGn d8hDXOtcZEJ2Qk6BwWIY0b4SWQdMeDNpvvlmvC9teOkAEBOcT021P7sTH154jBQf/rRG FkmoI4eIRQrvp5eQv1AtpVrjtOa6rRuuFJqpODhraYdkUm9c+fOYmiMjaH9I/7ixSYFN +fDM7iTJSHd+jufgWXwikgn/e8tDKXq7eW8ETD0YRdu4UHBviMl6E4R0LmBiFdkv1SIM kjhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=q8Sos2zH; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd29-20020a1709076e1d00b00711988b5913si10071894ejc.804.2022.06.13.14.26.13; Mon, 13 Jun 2022 14:26:51 -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=@cloudflare.com header.s=google header.b=q8Sos2zH; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbiFMVO0 (ORCPT + 99 others); Mon, 13 Jun 2022 17:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352050AbiFMVNJ (ORCPT ); Mon, 13 Jun 2022 17:13:09 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B98B339B87 for ; Mon, 13 Jun 2022 13:52:41 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id bd16so1115740oib.6 for ; Mon, 13 Jun 2022 13:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=Ie2xrfdugqSnUY/lUmZJBYqEw/Jj5HQgDROYZDI7Ljg=; b=q8Sos2zHH2cqeJpqAWGopwq4BFpy5d162ZHvWsGBGzD8dXmnX4TsH4oGd9xtjxFj3k kkiT7ORHTaWO7TVdzrFrUtvSJwyodFHKf3kDLk5zfyB6+Q4t7bACoSZoThK4QulFXt66 4eu47sTHknmVkiiSbjTEY+HxauLbTxzPeZ3t8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Ie2xrfdugqSnUY/lUmZJBYqEw/Jj5HQgDROYZDI7Ljg=; b=Iphdn2+bOyF1gs/SvA8VVk8ClsbBellBj/ZrK3uv1n23V/AeIZzCahx2wxKpkAuMWP TFet5r9uieMfRjEbIjQ0RE8Ft3lkizT9OmclnGNsinD61L4u6dXE0r8GIM3wYz7tWOB4 vF9JerQj87kwz0gW0FoMXJzpoXPtYWx2IdMlTY9qPyyr/tWu79WIsdgepblqzACfMO3I pI9BorSrVNnkvauLj3Dp+LGtMngq4mzGPkDr6rk6odMSXSqMCETb7hGUW6i+p/2B4008 RWwK9yp7uu4eyqR+kKXchmVUXs6PkI11WrVlruLLiUuwSgL2HJi2UD/4hWKJQn+P8+Pb Q9cg== X-Gm-Message-State: AOAM530ujW0KZVtjVpJa7bZkXbKyYG+DH5zNaV0s3X9aw44ucA/yx96m 6nqrpf9Tx+InYvmRpoItHnuH7g== X-Received: by 2002:a05:6808:2394:b0:326:d5d6:a4ba with SMTP id bp20-20020a056808239400b00326d5d6a4bamr321996oib.67.1655153561069; Mon, 13 Jun 2022 13:52:41 -0700 (PDT) Received: from [192.168.0.41] ([184.4.90.121]) by smtp.gmail.com with ESMTPSA id dv8-20020a056870d88800b000f5eb6b409bsm4444747oab.45.2022.06.13.13.52.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jun 2022 13:52:40 -0700 (PDT) Message-ID: Date: Mon, 13 Jun 2022 15:52:38 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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" 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 References: <20220608150942.776446-1-fred@cloudflare.com> <87tu8oze94.fsf@email.froward.int.ebiederm.org> From: Frederick Lawler In-Reply-To: <87tu8oze94.fsf@email.froward.int.ebiederm.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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. I'm proposing we follow security_task_allocs() pattern, and add visibility for failure cases in prepare_creds(). > 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. > Eric >