Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp561753rdb; Mon, 29 Jan 2024 10:26:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVbVYCMCIjmjjcbgibjI8L6ovPNhvZ10HunxrMyje6HI5Oc7HJUtlgPfSK/SAhES3NIKC0 X-Received: by 2002:a17:902:b08f:b0:1d5:5984:df52 with SMTP id p15-20020a170902b08f00b001d55984df52mr2937166plr.60.1706552785003; Mon, 29 Jan 2024 10:26:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706552784; cv=pass; d=google.com; s=arc-20160816; b=YlDIiUGcKEavDGnwRVtE6cIPVgh5QO+WZLGqaxTDFZ7QBAg93+H0bUJs3wOxVWKDRv V7FhPcAgDBOCkV/SwZl22xDDTd/Wxb4Q4E33IoVEfFF9DEM9KJVH4oHQzeDWCMajz0Uo +n6PVnRMIYnt9z3gAQ5KbbL/YkNbaE19xxg1w92pEBjA8qWolkmd125MwrqPy0JR8PVj wni1P+n8tVYHEpUmpoccco12McKyiYeHxDQUcaLrk4kPwgDFlCwDfkxx2alLa9LuUP/4 x/fDSc3n/lB0Hr1kWMt5XbKTI/PK631VHqE9HBYi5mEHgkU/880kRu02C16BWllA93ca uqdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:user-agent:message-id:in-reply-to:date:references:cc:to :from; bh=RgvYNxExQSfSszN1d9kLzwSEHsxfp7NT7b1CqUyJLFM=; fh=IioeUVsnAbFIsFuJ6IurVx4ov6vFbrU/OHq6NYeeIHE=; b=Z9KYQfryULQdF6GPaI8tMt3gqNOHmEA/ISlKSlqsOaTqN+IOl0nBu4F+PDdkIBqwck yBZ+GJB46UtOd5CRm72g39IFXF03WxZWcT4meGNbrnGHqfSq6k7NoDgtx+ZLchYoSG+f 0K/vdIjF+tF6Uhxu9NEoR8WeIkEJmXEFUz2GZ0N1n9pjjKMemHM/qqigP7bXipy9Cz/L Zrx4XMNmWwlbEYwVCKwO+PBaLViu3JCR/JRPfROO+6cg1BWjnJMEZJ9EII2eam5pAx5A 7yvo/CT3JgYg0/0SPZCfQpKGVlPKAfnhH5MnXDxmqsibnyt4TCA1D98B8idGKy90ncFv PHsQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=xmission.com dmarc=pass fromdomain=xmission.com); spf=pass (google.com: domain of linux-kernel+bounces-43297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w6-20020a170902d3c600b001d8ef01f108si1320635plb.221.2024.01.29.10.26.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 10:26:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=xmission.com dmarc=pass fromdomain=xmission.com); spf=pass (google.com: domain of linux-kernel+bounces-43297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9ED94B26426 for ; Mon, 29 Jan 2024 18:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E732F6F07A; Mon, 29 Jan 2024 18:15:32 +0000 (UTC) Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A1593F9F3; Mon, 29 Jan 2024 18:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706552132; cv=none; b=sv9cPvlGA6AWOVsYKwvps2AeY9IoXMP3HuNtrhVlgaD74VE/psn8aHQq1CuvMWnCDZe9DiwDKUJG8TinrYNaUtXHerjM5oMRuJ4Ngl4q/Yc0J34hYo2z1gJs4tcZQG7G7F9TMjVoH9A4cZqEUPXxQprtIXokcMwO1+gHnzN+dvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706552132; c=relaxed/simple; bh=Am5aEz8EwJQXXuKnZa+C00jQvnC7PmkUOWBDLEGjGEk=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=Oj/xb+nYadSqdAADwogVPI9b2tOBXmG9sOeVa8Kz10Hd8Lvn2m0L5XxU5P8kF/7U9dGyg+0iJtxqJZ7YVh5mGNkZFUtFrbVeWFywz1JowRmYZXp6RUKee74k9GAAnfrmIKwDdCzpYyDuhDH5zPr701aAjKH+T+45mjorlUPDDbA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in02.mta.xmission.com ([166.70.13.52]:45144) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1rUWAI-00ET44-Sf; Mon, 29 Jan 2024 11:15:26 -0700 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:35054 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1rUWAH-00Edcf-6p; Mon, 29 Jan 2024 11:15:26 -0700 From: "Eric W. Biederman" To: Tetsuo Handa Cc: Linus Torvalds , Kees Cook , Christian Brauner , Jan Kara , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML References: <613a54d2-9508-4f87-a163-a25a77a101cd@I-love.SAKURA.ne.jp> <87frygbx04.fsf@email.froward.int.ebiederm.org> Date: Mon, 29 Jan 2024 12:15:02 -0600 In-Reply-To: (Tetsuo Handa's message of "Mon, 29 Jan 2024 13:46:28 +0900") Message-ID: <8734ug9fbt.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1rUWAH-00Edcf-6p;;;mid=<8734ug9fbt.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18wl42UHne2LVIOqfwPN0l+F1RkALgM9RU= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4995] * 0.5 XMGappySubj_01 Very gappy subject * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_03 6+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Tetsuo Handa X-Spam-Relay-Country: X-Spam-Timing: total 728 ms - load_scoreonly_sql: 0.12 (0.0%), signal_user_changed: 12 (1.7%), b_tie_ro: 10 (1.4%), parse: 1.48 (0.2%), extract_message_metadata: 15 (2.0%), get_uri_detail_list: 2.6 (0.4%), tests_pri_-2000: 5 (0.7%), tests_pri_-1000: 2.9 (0.4%), tests_pri_-950: 1.34 (0.2%), tests_pri_-900: 1.07 (0.1%), tests_pri_-90: 202 (27.8%), check_bayes: 197 (27.0%), b_tokenize: 10 (1.4%), b_tok_get_all: 8 (1.1%), b_comp_prob: 3.5 (0.5%), b_tok_touch_all: 171 (23.5%), b_finish: 0.88 (0.1%), tests_pri_0: 467 (64.2%), check_dkim_signature: 0.82 (0.1%), check_dkim_adsp: 3.8 (0.5%), poll_dns_idle: 0.37 (0.1%), tests_pri_10: 2.4 (0.3%), tests_pri_500: 13 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 1/3] LSM: add security_bprm_aborting_creds() hook X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Tetsuo Handa writes: > On 2024/01/29 13:10, Eric W. Biederman wrote: >>> @@ -1519,6 +1519,7 @@ static void free_bprm(struct linux_binprm *bprm) >>> } >>> free_arg_pages(bprm); >>> if (bprm->cred) { >>> + security_bprm_aborting_creds(bprm); >>> mutex_unlock(¤t->signal->cred_guard_mutex); >>> abort_creds(bprm->cred); >> >> Why isn't abort_creds calling security_free_cred enough here? > > Because security_cred_free() from put_cred_rcu() is called from RCU callback > rather than from current thread doing execve(). > TOMOYO wants to restore attributes of current thread doing execve(). > >> The fact that somewhere Tomoyo is modifying a credential that the rest >> of the kernel sees as read-only, and making it impossible to just >> restore that credential is very concerning from a maintenance >> perspective. > > TOMOYO does not use "struct cred"->security. > TOMOYO uses only "struct task_struct"->security. > > struct lsm_blob_sizes tomoyo_blob_sizes __ro_after_init = { > .lbs_task = sizeof(struct tomoyo_task), > }; > > TOMOYO uses security_task_alloc() for allocating "struct task_struct"->security, > security_task_free() for releasing "struct task_struct"->security, > security_bprm_check() for updating "struct task_struct"->security, > security_bprm_committed_creds() for erasing old "struct task_struct"->security, > security_bprm_aborting_creds() for restoring old "struct task_struct"->security. > > Commit a6f76f23d297 ("CRED: Make execve() take advantage of copy-on-write > credentials") made TOMOYO impossible to do above. current->in_execve flag was a > hack for emulating security_bprm_aborting_creds() using security_prepare_creds(). > >> Can't Tomoyo simply allow reading of files that have __FMODE_EXEC >> set when allow_execve is set, without needing to perform a domain >> transition, and later back out that domain transition? > > No. That does not match TOMOYO's design. > > allow_execve keyword does not imply "allow opening that file for non-execve() purpose". Huh? I was proposing using the allow_execve credential to allow opening and reading the file for execve purpose. So you don't need to perform a domain transition early. > Also, performing a domain transition before execve() reaches point of no return is > the TOMOYO's design, but COW credentials does not allow such behavior. My question is simple. Why can't TOMOYO use the changing of credentials in task->cred to perform the domain transition? Why can't TOMOYO work with the code in execve? I don't see anything that fundamentally requires you to have the domain transition early. All I have seen so far is an assertion that you are using task->security. Is there anything except for the reading of the executable that having the domain transition early allows? My primary concern with TOMOYO being the odd man out, and using hooks for purposes arbitrary purposes instead of purposes they are logically designed to be used for? If you aren't going to change your design your new hook should be: security_execve_revert(current); Or maybe: security_execve_abort(current); At least then it is based upon the reality that you plan to revert changes to current->security. Saying anything about creds or bprm when you don't touch them, makes no sense at all. Causing people to completely misunderstand what is going on, and making it more likely they will change the code in ways that will break TOMOYO. What I understand from the documentation you provided about TOMOYO is: - TOMOYO provides the domain transition early so that the executable can be read. - TOMOYO did that because it could not detect reliably when a file was opened for execve and read for execve. Am I wrong in my understanding? If that understanding is correct, now that (file->f_mode & __FMODE_EXEC) is a reliable indication of a file used exclusively for exec then it should be possible to take advantage of the new information and get TOMOYO and the rest of the execve playing nicely with each other without having to add new hooks. If the maintenance concerns are not enough please consider the situation from an attack surface concern. Any hacked together poorly maintained surface is ripe bugs, and the exploitation of those bugs. Sometimes those bugs will break you in obvious ways, other times those bugs will break you in overlooked and exploitable ways. Eric