From mboxrd@z Thu Jan 1 00:00:00 1970 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 7A9852D8367; Fri, 21 Nov 2025 19:20:18 +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=1763752820; cv=none; b=QvpB7+hPiS630JGDi1vvwcrtT9CL5/mq2ZdYP6PyaXT7C1E4UOdXtydkHg4rBBBNF7YgBCAK/v2UN2GrhDsc3Zol7OWhtAs3ZTViTcX012BDXK7EtpaGzwrewwhVgzunS/XspurT8b8JtekPzMOMWnFKbTyO4e18PlLptIeoKi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763752820; c=relaxed/simple; bh=JTxhSWA6jxw9e4SLyOt7ueqSOQ+RMIIFCViCtct749k=; h=From:To:Cc:In-Reply-To:References:Date:Message-ID:MIME-Version: Content-Type:Subject; b=CYwahzyNfyUz1iuvheaRsCQa0yk6gOEA7fpzyB3v5hPX3wZ0ddUEfiiaywoRPTBAOdC8lRIki1GvrMhLuiqUPjDFG56FF2dIJ7ln3cjG6hAaluBOU0TZ+LK471ihbWhssrhvsGp7RR3U5NK9mMxiUIJ3kdcjcP856xwiBubp4L4= 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 in01.mta.xmission.com ([166.70.13.51]:56436) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1vMWfr-00EM7W-Dy; Fri, 21 Nov 2025 12:20:03 -0700 Received: from ip72-198-198-28.om.om.cox.net ([72.198.198.28]:50660 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1vMWfp-000k4P-Vv; Fri, 21 Nov 2025 12:20:03 -0700 From: "Eric W. Biederman" To: Bernd Edlinger Cc: Alexander Viro , Alexey Dobriyan , Oleg Nesterov , Kees Cook , Andy Lutomirski , Will Drewry , Christian Brauner , Andrew Morton , Michal Hocko , Serge Hallyn , James Morris , Randy Dunlap , Suren Baghdasaryan , Yafang Shao , Helge Deller , Adrian Reber , Thomas Gleixner , Jens Axboe , Alexei Starovoitov , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, tiozhang , Luis Chamberlain , "Paulo Alcantara (SUSE)" , Sergey Senozhatsky , Frederic Weisbecker , YueHaibing , Paul Moore , Aleksa Sarai , Stefan Roesch , Chao Yu , xu xin , Jeff Layton , Jan Kara , David Hildenbrand , Dave Chinner , Shuah Khan , Elena Reshetova , David Windsor , Mateusz Guzik , Ard Biesheuvel , "Joel Fernandes (Google)" , "Matthew Wilcox (Oracle)" , Hans Liljestrand , Penglei Jiang , Lorenzo Stoakes , Adrian Ratiu , Ingo Molnar , "Peter Zijlstra (Intel)" , Cyrill Gorcunov , Eric Dumazet In-Reply-To: (Bernd Edlinger's message of "Fri, 21 Nov 2025 12:26:48 +0100") References: <87tsyozqdu.fsf@email.froward.int.ebiederm.org> <87wm3ky5n9.fsf@email.froward.int.ebiederm.org> <87h5uoxw06.fsf_-_@email.froward.int.ebiederm.org> <87a50gxo0i.fsf@email.froward.int.ebiederm.org> <87o6ovx38h.fsf@email.froward.int.ebiederm.org> Date: Fri, 21 Nov 2025 13:19:55 -0600 Message-ID: <87ikf3w5us.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1vMWfp-000k4P-Vv;;;mid=<87ikf3w5us.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=72.198.198.28;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18mnrD+bsi9GaqPd61WTLqlIJTub8z3bTo= X-Spam-Level: **** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.1 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 1.5 TR_Symld_Words too many words that have symbols inside * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 1.0 XM_B_Phish_Phrases Commonly used Phishing Phrases * 1.0 XM_B_SpammyTLD Contains uncommon/spammy TLD * 0.0 TR_XM_PhishingBody Phishing flag in body of message * 1.5 XM_B_SpammyTLD3 Phishing rule with uncommon/spammy TLD Combo X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ****;Bernd Edlinger X-Spam-Relay-Country: X-Spam-Timing: total 871 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 11 (1.2%), b_tie_ro: 9 (1.1%), parse: 1.97 (0.2%), extract_message_metadata: 32 (3.7%), get_uri_detail_list: 6 (0.7%), tests_pri_-2000: 48 (5.5%), tests_pri_-1000: 11 (1.3%), tests_pri_-950: 1.33 (0.2%), tests_pri_-900: 1.19 (0.1%), tests_pri_-90: 124 (14.3%), check_bayes: 123 (14.1%), b_tokenize: 23 (2.7%), b_tok_get_all: 17 (1.9%), b_comp_prob: 4.6 (0.5%), b_tok_touch_all: 73 (8.4%), b_finish: 0.89 (0.1%), tests_pri_0: 619 (71.1%), check_dkim_signature: 0.63 (0.1%), check_dkim_adsp: 2.4 (0.3%), poll_dns_idle: 0.67 (0.1%), tests_pri_10: 3.1 (0.4%), tests_pri_500: 13 (1.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC][PATCH] exec: Move cred computation under exec_update_lock X-SA-Exim-Connect-IP: 166.70.13.51 X-SA-Exim-Rcpt-To: too long (recipient list exceeded maximum allowed size of 512 bytes) X-SA-Exim-Mail-From: ebiederm@xmission.com X-SA-Exim-Scanned: No (on out01.mta.xmission.com); SAEximRunCond expanded to false Bernd Edlinger writes: > On 11/21/25 10:35, Bernd Edlinger wrote: >> On 11/21/25 08:18, Eric W. Biederman wrote: >>> Bernd Edlinger writes: >>> >>>> Hi Eric, >>>> >>>> thanks for you valuable input on the topic. >>>> >>>> On 11/21/25 00:50, Eric W. Biederman wrote: >>>>> "Eric W. Biederman" writes: >>>>> >>>>>> Instead of computing the new cred before we pass the point of no >>>>>> return compute the new cred just before we use it. >>>>>> >>>>>> This allows the removal of fs_struct->in_exec and cred_guard_mutex. >>>>>> >>>>>> I am not certain why we wanted to compute the cred for the new >>>>>> executable so early. Perhaps I missed something but I did not see any >>>>>> common errors being signaled. So I don't think we loose anything by >>>>>> computing the new cred later. >>>>> >>>>> I should add that the permission checks happen in open_exec, >>>>> everything that follows credential wise is just about representing in >>>>> struct cred the credentials the new executable will have. >>>>> >>>>> So I am really at a loss why we have had this complicated way of >>>>> computing of computed the credentials all of these years full of >>>>> time of check to time of use problems. >>>>> >>>> >>>> Well, I think I see a problem with your patch: >>>> >>>> When the security engine gets the LSM_UNSAFE_PTRACE flag, it might >>>> e.g. return -EPERM in bprm_creds_for_exec in the apparmor, selinux >>>> or the smack security engines at least. Previously that callback >>>> was called before the point of no return, and the return code should >>>> be returned as a return code the the caller of execve. But if we move >>>> that check after the point of no return, the caller will get killed >>>> due to the failed security check. >>>> >>>> Or did I miss something? >>> >>> I think we definitely need to document this change in behavior. I would >>> call ending the exec with SIGSEGV vs -EPERM a quality of implementation >>> issue. The exec is failing one way or the other so I don't see it as a >>> correctness issue. >>> >>> In the case of ptrace in general I think it is a bug if the mere act of >>> debugging a program changes it's behavior. So which buggy behavior >>> should we prefer? SIGSEGV where it is totally clear that the behavior >>> has changed or -EPERM and ask the debugged program to handle it. >>> I lean towards SIGSEGV because then it is clear the code should not >>> handle it. >>> >>> In the case of LSM_UNSAFE_NO_NEW_PRIVS I believe the preferred way to >>> handle unexpected things happening is to terminate the application. >>> >>> In the case of LSM_UNSAFE_SHARE -EPERM might be better. I don't know >>> of any good uses of any good uses of sys_clone(CLONE_FS ...) outside >>> of CLONE_THREAD. >>> >>> >>> Plus all of these things are only considerations if we are exec'ing a >>> program that transitions to a different set of credentials. Something >>> that happens but is quite rare itself. >>> >>> In practice I don't expect there is anything that depends on the exact >>> behavior of what happens when exec'ing a suid executable to gain >>> privileges when ptraced. The closes I can imagine is upstart and >>> I think upstart ran as root when ptracing other programs so there is no >>> gaining of privilege and thus no reason for a security module to >>> complain. >>> >>> Who knows I could be wrong, and someone could actually care. Which is >>> hy I think we should document it.>> >> >> >> Well, I dont know for sure, but the security engine could deny the execution >> for any reason, not only because of being ptraced. >> Maybe there can be a policy which denies user X to execute e.g. any suid programs. >> >> >> Bernd. >> > > Hmm, funny.. > > I installed this patch on top of > > commit fd95357fd8c6778ac7dea6c57a19b8b182b6e91f (HEAD -> master, origin/master, origin/HEAD) > Merge: c966813ea120 7b6216baae75 > Author: Linus Torvalds > Date: Thu Nov 20 11:04:37 2025 -0800 > > but it does panic when I try to boot: > > [ 0.870539] TERM=1inux > [ 0.870573] Starting init: /bin/sh exists but couldn't execute it (error -14) 0.8705751 Kernel panic- not syncing: No working init found. Try passing i mit= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance > [ 0.870577] CPU: UID: 0 PID: 1 Comm: sh Not tainted 6.18.0-rc6+ #1 PREEMPT(voluntary) > [ 0.870579] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBo x 12/01/2006 > [ 0.870580] Call Trace: > [ 0.870590] > [ 0.870592] vpanic+0x36d/0x380 > [ 0.870607] ? __pfx_kernel_init+0x10/0x10 > [ 0.870615] panic+0x5b/0x60 > [ 0.870617] kernel_init+0x17d/0x1c0 > [ 0.870623] ret_from_fork+0x124/0x150 > [ 0.870625} ? __pfx_kernel_init+0x10/0x10 > [ 0.870627] ret_from_fork_asm+0x1a/0x30 > [ 0.870632] > [ 0.8706631 Kernel Offset: 0x3a800000 from Oxffffffff81000000 (relocation ran ge: 0xffffffff80000000-0xffffffffbfffffff) > [ 0.880034] ---[ end Kernel panic - not syncing: No working init found. Try passing init option to kernel. See Linux Documentation/admin-guide/init.rst for guidance. 1---` > > > Is that a known problem? Nope. It looks like the code needs a little bit bug fixing testing. I will take see about taking a look. Eric