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 A6CB6C36010 for ; Fri, 11 Apr 2025 09:07:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68CE5280193; Fri, 11 Apr 2025 05:07:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63AFE280190; Fri, 11 Apr 2025 05:07:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52988280193; Fri, 11 Apr 2025 05:07:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 35181280190 for ; Fri, 11 Apr 2025 05:07:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 82D54142237 for ; Fri, 11 Apr 2025 09:07:53 +0000 (UTC) X-FDA: 83321185626.09.B175CEF Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by imf30.hostedemail.com (Postfix) with ESMTP id 009C980004 for ; Fri, 11 Apr 2025 09:07:48 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of roberto.sassu@huaweicloud.com designates 14.137.139.23 as permitted sender) smtp.mailfrom=roberto.sassu@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744362471; a=rsa-sha256; cv=none; b=mGt7wO76q41UYbkky61VkC2f5OS1MEhggMJ17SJE30kR10r88oPwj1g74SuV1AgYQyMzT/ x/rsI3AtLLzzLN10xjiXRn+B25ZQQrNsr2lXTdubGdwCNhMvXEXy8g2/z5jsVxMeEGttNN 01i93amFsojx0BJ2U2BjK+ckorkujg4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of roberto.sassu@huaweicloud.com designates 14.137.139.23 as permitted sender) smtp.mailfrom=roberto.sassu@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744362471; 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; bh=Jo2tAz7jSOJP2ymYZNDVVXeqvPedMX0dp5rX56/2HEA=; b=ZJroUTUYeV5iInvUEde2Yx2m0dSK+OJcanOwnZ+6NldJoYeDEGR0JdLiSYi+sdb1Zb8wt1 7D9+CJIve3NAfAa/NggOBIMj/76RtUmdBbvNSF6b1zOy7QZR4eINpZarggxEZubNeDZXiO wh2hW4P1NSt+tPPsWzez4GFWS2VYtys= Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout11.his.huawei.com (SkyGuard) with ESMTPS id 4ZYrS06f7fz1HBPW for ; Fri, 11 Apr 2025 17:07:44 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id A6F7E1402F6 for ; Fri, 11 Apr 2025 17:07:45 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwA3vUvX2_hnBgnbBQ--.19774S2; Fri, 11 Apr 2025 10:07:45 +0100 (CET) Message-ID: Subject: Re: Credentials not fully initialized before bprm_check LSM hook From: Roberto Sassu To: sergeh@kernel.org Cc: Alexander Viro , Christian Brauner , Kees Cook , Paul Moore , James Morris , "Serge E. Hallyn" , "Eric W. Biederman" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, zohar@linux.ibm.com Date: Fri, 11 Apr 2025 11:07:31 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID:LxC2BwA3vUvX2_hnBgnbBQ--.19774S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tryrCr15ZrWrAw43Zw1DZFb_yoW8tr4kpF WftF15tF4vgrySkr12q3WUXayayrZ5G398Jr98WFy5u3yDGr1vkrWxt3y5uFy5GrWrK3W2 yay3ZwnavFyDC3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvjb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AF wI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUF1 v3UUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAPBGf4v18BWQAAst X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 009C980004 X-Stat-Signature: jq8xzabereprh4ozp879a4qkyxdenr6h X-HE-Tag: 1744362468-247292 X-HE-Meta: U2FsdGVkX19vlRlrGKaFnBZnv3KS+GLX5PSP41dygH+7c8rbCchkv7j2H5BxxxgHKL2W3baSA5/KjdvVsHc8LrKxipI86dO5ald4gOQ3xw/l6Jr1QgozIdYwUjf92FJubQS8C9AsFlXcLsAzwewoALAF6vHVLPvN4e1lnOVJ1cwBVLISGb7dchnUnIAykraAAWIGqfiRRjDm5oFBq1A7PV2p2ZaNfeLruoKVpxKo/lWNXKp8ZgnL4fmsMr84P82ZxPfnIOuluv35ILwyzzRz7mhNEYS9H1snFr+oZ9MB9g2tyaykqSsX/7NY/JlZneuRuM9EoyJBBb/GqoJKrK5GtADQ9o1r6hlhOqB8DqocYt6uKvqvQlDa3Nr574vHwPAhPpfKuYnSSn5o4J2Budc/Yu5cuXUdfvAJkoihmxwljOyMFDL6iJ7UXMqDZs8wOsjRCezKXfTvFonUubn5tWatHL2wNU87KaCTLIcEI/4AFJwUmg5CvPV3xWMxH0umfzk7r7bou5uT8UITLUR9B8YLiZ+oXBqUIHJw/bEnCpSt63TOHi6fZoEpdkuFJ7b/9Uh9I3y+74UO4xXfmseyeIziOUTYeHSFdCfQW6+s6BI0xIcCNEI8TYfaKXWCaurvA82u9LkSN33Sd8kd/xDcLWkLxXllJb77LPC2kNZUb7lkt3ulwjhYom8bUYmmxMu7GvjrjAOHgWyfUUwhCvggegqenBaNPAGl8H55vtOpXBBuOjkDmFKYGNU5IUd7yrJobtLUkvYljDuBoINlHu05Mf1edR+HbY8exfOvAcYn4J4hWQF7/QCpLXdNklVK6icp+UrukKIoRB8wsDEaknT+svPe4/ndjcba//pspiIUqAOhuDqjDokAaNWvSljmVV3outRda10KDniAWlp7A4cgIcUV0/YVGS1xHru2B+YLdNE+FCW9hIzPMFdF5I9gosBmVFRcUx+sF7eMd/my+TeOhPP qM1mi1Gm gdFAP/BM0Igs/JBxeNsm/dFJuDyU8iKcRIoqAcIU14jsHEnD/mipafWBG8km0IkTVpnQiM3FnCYAmndmtxpjfESrFXsiwicR7TN6TO4uN1Iwr+EkpqpaOGZHIs/KR9HiTGD16XG7oeadLX/5UsWoT7iGiIvdrVgsfR6TCWcIrrTHcD56Bo/0W/rhjkgVBQaKNvnsg6RQUbO3ucq+CF3v5b2pNwS88CuEnDflMq/ayTFqdkJUDGposgXwcrg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000039, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, 2025-04-10 at 17:24 +0000, sergeh@kernel.org wrote: > On Thu, Apr 10, 2025 at 01:47:07PM +0200, Roberto Sassu wrote: > > Hi everyone > >=20 > > recently I discovered a problem in the implementation of our IMA > > bprm_check hook, in particular when the policy is matched against the > > bprm credentials (to be committed later during execve(). > >=20 > > Before commit 56305aa9b6fab ("exec: Compute file based creds only > > once"), bprm_fill_uid() was called in prepare_binprm() and filled the > > euid/egid before calling security_bprm_check(), which in turns calls > > IMA. > >=20 > > After that commit, bprm_fill_uid() was moved to begin_new_exec(), which > > is when the last interpreter is found. > >=20 > > The consequence is that IMA still sees the not yet ready credentials > > and an IMA rule like: > >=20 > > measure func=3DCREDS_CHECK euid=3D0 >=20 > "IMA still sees" at which point exactly? IMA sees the credentials in bprm->cred prepared with prepare_bprm_creds(), where the euid/egid are taken from the current process. > Do I understand right that the problem is that ima's version of > security_bprm_creds_for_exec() needs to run after > bprm_creds_from_file()? IMA's version of security_bprm_check(). security_bprm_creds_for_exec() is for checking scripts executed by the interpreters with execveat() and the AT_EXECVE_CHECK flag. Uhm, it would not be technically a problem to move the IMA hook later, but it would miss the intermediate binary search steps, which are visible with security_bprm_check(). > Given that Eric's commit message said that no bprm handlers use > the uid, it seems it should be safe to just move that? Well, we just found one :) Thanks Roberto > > will not be matched for sudo-like applications. > >=20 > > It does work however with SELinux, because it computes the transition > > before IMA in the bprm_creds_for_exec hook. > >=20 > > Since IMA needs to be involved for each execution in the chain of > > interpreters, we cannot move to the bprm_creds_from_file hook. > >=20 > > How do we solve this problem? The commit mentioned that it is an > > optimization, so probably would not be too hard to partially revert it > > (and keeping what is good). > >=20 > > Thanks > >=20 > > Roberto > >=20