From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EDA0CCA47B for ; Mon, 13 Jun 2022 20:52:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8CC28D01DD; Mon, 13 Jun 2022 16:52:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A2948D01E3; Mon, 13 Jun 2022 16:52:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 869158D01DD; Mon, 13 Jun 2022 16:52:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6E43A8D01E2 for ; Mon, 13 Jun 2022 16:52:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4B15734F51 for ; Mon, 13 Jun 2022 20:52:42 +0000 (UTC) X-FDA: 79574411364.16.FA11A0E Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf06.hostedemail.com (Postfix) with ESMTP id D320D180087 for ; Mon, 13 Jun 2022 20:52:41 +0000 (UTC) Received: by mail-oi1-f173.google.com with SMTP id w16so9188772oie.5 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=7AnpRP53J9AVYSR9aXap0ooO1j33Gu7PMX14Hnst9riV1L/eya3N/bqI0Bai31qxRS SROpVZHK/sTAw+LAozZ/fofoJOwrA98N00X2lj4rdMlfo0nehHVs9jW4AI0E0cnXyCyN 94hVb4TCgZxGSAA2GNs5yOwc3Q/I5YIfE5Vm0a0M236eRYeyJzAnNv+JHEI1s0EZ8edL mTf0z8quh6Eea2erMarjYg49qhPcoxQiAGPh+B9Zz/4wnTr3436aypaGwWqZpjTkStgZ BOq+KIxNvNi5vLIzXvcM2OOiiUt48hAh9hf7SkQq4a4PnvQIZj5yhQUVJVy1JRINpVxC RRTw== X-Gm-Message-State: AOAM531MYU6uV2NdS5aLsKDT9Fv0unDfGrVtazV6evM/fEihDaBZyF3l 5pxXInsbyg3d8xqUIDGAVroy6g== X-Google-Smtp-Source: ABdhPJxwqO943xteTGAgFieA/vZp5/Zn/6Qxyj5rF6Le0Sf8rKMQHGa/+OpWxWOapQGjDXa0MQVMLw== 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 ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=cloudflare.com header.s=google header.b=q8Sos2zH; dmarc=pass (policy=reject) header.from=cloudflare.com; spf=none (imf06.hostedemail.com: domain of fred@cloudflare.com has no SPF policy when checking 209.85.167.173) smtp.mailfrom=fred@cloudflare.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655153562; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ie2xrfdugqSnUY/lUmZJBYqEw/Jj5HQgDROYZDI7Ljg=; b=QQqloM1m5sqUStyrY7NVNzCS513topfIPjWducvSiL9SehcGqlL4sSRPAv1kqAVx9Mh0+2 Nrn1q6pl78nkWlaLvtJYNiye5pMjqXml+e4ioZJRpTnp7uxh1GAbsTMS7vA6m6MC0i4zNh LloBftAqqCEMPhB05eixbw9sEUqiL1g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655153562; a=rsa-sha256; cv=none; b=g6QqsbuKC+xyZFFkvMsNxeaAuqTWutgGF+6RuHGiTylhA6FjGoAXh45vjO+LddqKnlb57y ajUGqcQLmiGk3lrl1GbORRPhEe/PgsNn/CM71IAS2hPrQzM55JogFnnBUva7z3IzoTjfo3 B15Xr6EhGsqvdQjjKWqs8VxcIb8XVWs= X-Stat-Signature: od5sfcd1x379iqphe9fphsec5997yqus X-Rspamd-Queue-Id: D320D180087 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=cloudflare.com header.s=google header.b=q8Sos2zH; dmarc=pass (policy=reject) header.from=cloudflare.com; spf=none (imf06.hostedemail.com: domain of fred@cloudflare.com has no SPF policy when checking 209.85.167.173) smtp.mailfrom=fred@cloudflare.com X-Rspamd-Server: rspam10 X-HE-Tag: 1655153561-803826 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 >