Message ID | 999a4733-c554-43ca-a6e9-998c939fbeb8@I-love.SAKURA.ne.jp |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp956236dyc; Sat, 3 Feb 2024 02:54:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7mG4tOInGR11SrK6HuME4UDsAqzhvvbmMVY1bhR9mQ4DA3JO9dnfrrp8AuAkkHPr/rAr2 X-Received: by 2002:a05:6a00:670c:b0:6e0:2fa2:5280 with SMTP id hm12-20020a056a00670c00b006e02fa25280mr381260pfb.7.1706957676115; Sat, 03 Feb 2024 02:54:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706957676; cv=pass; d=google.com; s=arc-20160816; b=JOfwAD3JqH4ynssqA4JVJJ8KLHeUAJ+CSwQl75bjG3CXUrNfphzSDpK5uzmasBWstF imgJ5XPscCIaSNVH10Jkdiw+slS2OqOIpmJyx1zr4+xxrLKZ4iB1QlL/UTCTCtC02fnr 8MM2M7tscpRVzAyOjymvLnsoFckzprqbZo4oWVNafQw+zOZbttMk/Y6++xOp+xwqzXIp zoPfHYfy7Atj8jo19pKVBLxGD017UNKIh0FXuJd6uXos2QBoovrPo6Mmu9Z95tL2KsDx E+Oq3KmaZ6KjIxmh5ju/g8e+DRgsY7heK/lJRykc21mYkVjl+d95JbBnTITH863E01G4 5gLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=eyzkI9KRM4oFmcnSoKD7+j+7OX1cpzdu3vTzRqgPdkI=; fh=mWfKK1N/B27kkRlvoV59PHuZBCewWIsj2V5yvZ5Cc0g=; b=gWUbfM3LaJOQhAjG3vAr71yD+gUrPVYJkUDx51H3IJM+QJqhgU76yk0FKaqk5t4jsZ TaSNqVs+1iAZ1LGIhQoudVut58Ttcfh0jLFMsjTDMh4lLYM2JS0Rpq0wPkDr5zFKw71h CMCplAtiWeb+fyWX+9XKNRigP3j27oyGvFy+fV/rHs18z9bVXfpMO9ty776LNSdGiCSK GUpRo44Op8lhJ5GF3eutXm52ipiqTmwy9yuhKdBx7q56Mi4KkFtgSbHX3poFW+g+RZg+ pp0ZkgPYrdTWGSppVHTXzgP3lSbjZy2MsL5SspNM86XNBMdY93Q6128ucCu9L6G1pB0c k/sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWm5huawaTuTO1GB6DdumvhZsrCSWsJXuRaNVVPw+pG46DudvR1JM8cwjmrVWW/+onCTaDGbzJd4jqMscTfWefuBZMQ4A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j7-20020a634a47000000b005cdfd6f30a0si3016443pgl.748.2024.02.03.02.54.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 02:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51033-ouuuleilei=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 947F128A948 for <ouuuleilei@gmail.com>; Sat, 3 Feb 2024 10:54:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3A525DF2C; Sat, 3 Feb 2024 10:53:30 +0000 (UTC) Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (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 812955D8E1; Sat, 3 Feb 2024 10:53:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706957608; cv=none; b=X3rif85nL3IVFtHRp87PVVxzs/gZs0CwOs93SWyzVibBMgOUV5g85UzN3sljMPvP5PA6Q1/modZ5+VOm+D2wVDMyL2bH7+tZIRoXEKIl8K3EAnCy9f0nhiexJ0YyCrZs5xzAMn9UyjpK2FhnppJHzwO5y2PJnZXDf0qylvZudtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706957608; c=relaxed/simple; bh=mh230nw9C+CMlZ+KBHNN6+L7nuVm0C8xivOOp+Zjens=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=dfkiCIAQHMdFFU+MpRNUYmvHgvwOSkBLgro9mGeETtt/8KnPvUpqWlTwKlLUT5/mzCGmlLyzFMIvx5VDoaNLt1+tDXdi5H6k/aLt3U9KidGLKmRoDnnqkmmrDEmG1FMY9P9N4fqRj1OijFLAXkoK9vHvs0CVvoGlElEY2IJ3HEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from fsav120.sakura.ne.jp (fsav120.sakura.ne.jp [27.133.134.247]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 413Aqsi8052538; Sat, 3 Feb 2024 19:52:55 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav120.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav120.sakura.ne.jp); Sat, 03 Feb 2024 19:52:54 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav120.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 413AqOqw052397 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sat, 3 Feb 2024 19:52:54 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <999a4733-c554-43ca-a6e9-998c939fbeb8@I-love.SAKURA.ne.jp> Date: Sat, 3 Feb 2024 19:52:54 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/3] LSM: add security_execve_abort() hook Content-Language: en-US From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> To: Linus Torvalds <torvalds@linux-foundation.org>, Eric Biederman <ebiederm@xmission.com>, Kees Cook <keescook@chromium.org>, Alexander Viro <viro@zeniv.linux.org.uk>, Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>, Paul Moore <paul@paul-moore.com>, James Morris <jmorris@namei.org>, "Serge E. Hallyn" <serge@hallyn.com> Cc: linux-security-module <linux-security-module@vger.kernel.org>, linux-fsdevel <linux-fsdevel@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org> References: <8fafb8e1-b6be-4d08-945f-b464e3a396c8@I-love.SAKURA.ne.jp> In-Reply-To: <8fafb8e1-b6be-4d08-945f-b464e3a396c8@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789874852279051764 X-GMAIL-MSGID: 1789874852279051764 |
Series |
fs/exec: remove current->in_execve flag
|
|
Commit Message
Tetsuo Handa
Feb. 3, 2024, 10:52 a.m. UTC
A regression caused by commit 978ffcbf00d8 ("execve: open the executable
file before doing anything else") has been fixed by commit 4759ff71f23e
("exec: Check __FMODE_EXEC instead of in_execve for LSMs") and commit
3eab830189d9 ("uselib: remove use of __FMODE_EXEC"). While fixing this
regression, Linus commented that we want to remove current->in_execve flag.
The current->in_execve flag was introduced by commit f9ce1f1cda8b ("Add
in_execve flag into task_struct.") when TOMOYO LSM was merged, and the
reason was explained in commit f7433243770c ("LSM adapter functions.").
In short, TOMOYO's design is not compatible with COW credential model
introduced in Linux 2.6.29, and the current->in_execve flag was added for
emulating security_bprm_free() hook which has been removed by introduction
of COW credential model.
security_task_alloc()/security_task_free() hooks have been removed by
commit f1752eec6145 ("CRED: Detach the credentials from task_struct"),
and these hooks have been revived by commit 1a2a4d06e1e9 ("security:
create task_free security callback") and commit e4e55b47ed9a ("LSM: Revive
security_task_alloc() hook and per "struct task_struct" security blob.").
But security_bprm_free() hook did not revive until now. Now that Linus
wants TOMOYO to stop carrying state across two independent execve() calls,
and TOMOYO can stop carrying state if a hook for restoring previous state
upon failed execve() call were provided, this patch revives the hook.
Since security_bprm_committing_creds() and security_bprm_committed_creds()
hooks are called when an execve() request succeeded, we don't need to call
security_bprm_free() hook when an execve() request succeeded. Therefore,
this patch adds security_execve_abort() hook which is called only when an
execve() request failed after successful prepare_bprm_creds() call.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
fs/exec.c | 1 +
include/linux/lsm_hook_defs.h | 1 +
include/linux/security.h | 5 +++++
security/security.c | 11 +++++++++++
4 files changed, 18 insertions(+)
Comments
On Sat, Feb 03, 2024 at 07:52:54PM +0900, Tetsuo Handa wrote: > A regression caused by commit 978ffcbf00d8 ("execve: open the executable > file before doing anything else") has been fixed by commit 4759ff71f23e > ("exec: Check __FMODE_EXEC instead of in_execve for LSMs") and commit > 3eab830189d9 ("uselib: remove use of __FMODE_EXEC"). While fixing this > regression, Linus commented that we want to remove current->in_execve flag. > > The current->in_execve flag was introduced by commit f9ce1f1cda8b ("Add > in_execve flag into task_struct.") when TOMOYO LSM was merged, and the > reason was explained in commit f7433243770c ("LSM adapter functions."). > > In short, TOMOYO's design is not compatible with COW credential model > introduced in Linux 2.6.29, and the current->in_execve flag was added for > emulating security_bprm_free() hook which has been removed by introduction > of COW credential model. > > security_task_alloc()/security_task_free() hooks have been removed by > commit f1752eec6145 ("CRED: Detach the credentials from task_struct"), > and these hooks have been revived by commit 1a2a4d06e1e9 ("security: > create task_free security callback") and commit e4e55b47ed9a ("LSM: Revive > security_task_alloc() hook and per "struct task_struct" security blob."). > > But security_bprm_free() hook did not revive until now. Now that Linus > wants TOMOYO to stop carrying state across two independent execve() calls, > and TOMOYO can stop carrying state if a hook for restoring previous state > upon failed execve() call were provided, this patch revives the hook. > > Since security_bprm_committing_creds() and security_bprm_committed_creds() > hooks are called when an execve() request succeeded, we don't need to call > security_bprm_free() hook when an execve() request succeeded. Therefore, > this patch adds security_execve_abort() hook which is called only when an > execve() request failed after successful prepare_bprm_creds() call. > > Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> This looks good to me. Given this touches execve and is related to the recent execve changes, shall I carry this in the execve tree for testing and send a PR to Linus for it before v6.8 releases? There's already an Ack from Serge, so this seems a reasonable way to go unless Paul would like it done some other way? Reviewed-by: Kees Cook <keescook@chromium.org>
On 2024/02/07 23:24, Kees Cook wrote: > This looks good to me. > > Given this touches execve and is related to the recent execve changes, > shall I carry this in the execve tree for testing and send a PR to Linus > for it before v6.8 releases? Yes, please do so. (My git tree is currently down.) > > There's already an Ack from Serge, so this seems a reasonable way to go > unless Paul would like it done some other way? > > Reviewed-by: Kees Cook <keescook@chromium.org> > Thank you.
On Wed, Feb 7, 2024 at 9:24 AM Kees Cook <keescook@chromium.org> wrote: > > On Sat, Feb 03, 2024 at 07:52:54PM +0900, Tetsuo Handa wrote: > > A regression caused by commit 978ffcbf00d8 ("execve: open the executable > > file before doing anything else") has been fixed by commit 4759ff71f23e > > ("exec: Check __FMODE_EXEC instead of in_execve for LSMs") and commit > > 3eab830189d9 ("uselib: remove use of __FMODE_EXEC"). While fixing this > > regression, Linus commented that we want to remove current->in_execve flag. > > > > The current->in_execve flag was introduced by commit f9ce1f1cda8b ("Add > > in_execve flag into task_struct.") when TOMOYO LSM was merged, and the > > reason was explained in commit f7433243770c ("LSM adapter functions."). > > > > In short, TOMOYO's design is not compatible with COW credential model > > introduced in Linux 2.6.29, and the current->in_execve flag was added for > > emulating security_bprm_free() hook which has been removed by introduction > > of COW credential model. > > > > security_task_alloc()/security_task_free() hooks have been removed by > > commit f1752eec6145 ("CRED: Detach the credentials from task_struct"), > > and these hooks have been revived by commit 1a2a4d06e1e9 ("security: > > create task_free security callback") and commit e4e55b47ed9a ("LSM: Revive > > security_task_alloc() hook and per "struct task_struct" security blob."). > > > > But security_bprm_free() hook did not revive until now. Now that Linus > > wants TOMOYO to stop carrying state across two independent execve() calls, > > and TOMOYO can stop carrying state if a hook for restoring previous state > > upon failed execve() call were provided, this patch revives the hook. > > > > Since security_bprm_committing_creds() and security_bprm_committed_creds() > > hooks are called when an execve() request succeeded, we don't need to call > > security_bprm_free() hook when an execve() request succeeded. Therefore, > > this patch adds security_execve_abort() hook which is called only when an > > execve() request failed after successful prepare_bprm_creds() call. > > > > Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> > > This looks good to me. > > Given this touches execve and is related to the recent execve changes, > shall I carry this in the execve tree for testing and send a PR to Linus > for it before v6.8 releases? > > There's already an Ack from Serge, so this seems a reasonable way to go > unless Paul would like it done some other way? Please hold off on this Kees (see my email from yesterday), I'd prefer to take this via the LSM tree and with the immediate regression resolved I'd prefer this go in during the upcoming merge window and not during the -rcX cycle. Or am I misunderstanding things about the state of Linus' tree currently? -- paul-moore.com
On Wed, Feb 07, 2024 at 10:21:07AM -0500, Paul Moore wrote: > On Wed, Feb 7, 2024 at 9:24 AM Kees Cook <keescook@chromium.org> wrote: > > > > On Sat, Feb 03, 2024 at 07:52:54PM +0900, Tetsuo Handa wrote: > > > A regression caused by commit 978ffcbf00d8 ("execve: open the executable > > > file before doing anything else") has been fixed by commit 4759ff71f23e > > > ("exec: Check __FMODE_EXEC instead of in_execve for LSMs") and commit > > > 3eab830189d9 ("uselib: remove use of __FMODE_EXEC"). While fixing this > > > regression, Linus commented that we want to remove current->in_execve flag. > > > > > > The current->in_execve flag was introduced by commit f9ce1f1cda8b ("Add > > > in_execve flag into task_struct.") when TOMOYO LSM was merged, and the > > > reason was explained in commit f7433243770c ("LSM adapter functions."). > > > > > > In short, TOMOYO's design is not compatible with COW credential model > > > introduced in Linux 2.6.29, and the current->in_execve flag was added for > > > emulating security_bprm_free() hook which has been removed by introduction > > > of COW credential model. > > > > > > security_task_alloc()/security_task_free() hooks have been removed by > > > commit f1752eec6145 ("CRED: Detach the credentials from task_struct"), > > > and these hooks have been revived by commit 1a2a4d06e1e9 ("security: > > > create task_free security callback") and commit e4e55b47ed9a ("LSM: Revive > > > security_task_alloc() hook and per "struct task_struct" security blob."). > > > > > > But security_bprm_free() hook did not revive until now. Now that Linus > > > wants TOMOYO to stop carrying state across two independent execve() calls, > > > and TOMOYO can stop carrying state if a hook for restoring previous state > > > upon failed execve() call were provided, this patch revives the hook. > > > > > > Since security_bprm_committing_creds() and security_bprm_committed_creds() > > > hooks are called when an execve() request succeeded, we don't need to call > > > security_bprm_free() hook when an execve() request succeeded. Therefore, > > > this patch adds security_execve_abort() hook which is called only when an > > > execve() request failed after successful prepare_bprm_creds() call. > > > > > > Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> > > > > This looks good to me. > > > > Given this touches execve and is related to the recent execve changes, > > shall I carry this in the execve tree for testing and send a PR to Linus > > for it before v6.8 releases? > > > > There's already an Ack from Serge, so this seems a reasonable way to go > > unless Paul would like it done some other way? > > Please hold off on this Kees (see my email from yesterday), I'd prefer > to take this via the LSM tree and with the immediate regression > resolved I'd prefer this go in during the upcoming merge window and > not during the -rcX cycle. Or am I misunderstanding things about the > state of Linus' tree currently? My understanding was that TOMOYO is currently broken in Linus's tree. If that's true, I'd like to make sure it gets fixed before v6.8 is released. If it's working okay, then sure, that's fine to wait. :) -Kees
On Wed, Feb 7, 2024 at 10:43 AM Kees Cook <keescook@chromium.org> wrote: > On Wed, Feb 07, 2024 at 10:21:07AM -0500, Paul Moore wrote: .. > > Please hold off on this Kees (see my email from yesterday), I'd prefer > > to take this via the LSM tree and with the immediate regression > > resolved I'd prefer this go in during the upcoming merge window and > > not during the -rcX cycle. Or am I misunderstanding things about the > > state of Linus' tree currently? > > My understanding was that TOMOYO is currently broken in Linus's tree. If > that's true, I'd like to make sure it gets fixed before v6.8 is > released. > > If it's working okay, then sure, that's fine to wait. :) Okay, let's get confirmation from Tetsuo on the current state of TOMOYO in Linus' tree. If it is currently broken, I'll merge the next updated patchset from Tetsuo into the lsm/stable-6.8 branch and send it up to Linus during v6.8-rcX after some soaking in linux-next. If it's working, we'll wait :)
On Wed, 7 Feb 2024 at 16:45, Paul Moore <paul@paul-moore.com> wrote: > > Okay, let's get confirmation from Tetsuo on the current state of > TOMOYO in Linus' tree. If it is currently broken [..] As far as I understand, the current state is working, just the horrid random flag. So I think the series is a cleanup and worth doing, but also not hugely urgent. But it would probably be good to just get this whole thing over and done with, rather than leave it lingering for another release for no reason. Linus
On Wed, Feb 7, 2024 at 12:57 PM Linus Torvalds <torvalds@linux-foundation.org> wrote: > > On Wed, 7 Feb 2024 at 16:45, Paul Moore <paul@paul-moore.com> wrote: > > > > Okay, let's get confirmation from Tetsuo on the current state of > > TOMOYO in Linus' tree. If it is currently broken [..] > > As far as I understand, the current state is working, just the horrid > random flag. > > So I think the series is a cleanup and worth doing, but also not > hugely urgent. But it would probably be good to just get this whole > thing over and done with, rather than leave it lingering for another > release for no reason. I've always operated under a policy of "just fixes" during the -rcX period of development, but you're the boss. Once we get something suitable for merging I'll send it up to you after it has soaked in linux-next for a bit.
On 2024/02/08 2:57, Linus Torvalds wrote: > On Wed, 7 Feb 2024 at 16:45, Paul Moore <paul@paul-moore.com> wrote: >> >> Okay, let's get confirmation from Tetsuo on the current state of >> TOMOYO in Linus' tree. If it is currently broken [..] > > As far as I understand, the current state is working, just the horrid > random flag. Yes, the current state is working. > > So I think the series is a cleanup and worth doing, but also not > hugely urgent. But it would probably be good to just get this whole > thing over and done with, rather than leave it lingering for another > release for no reason. Right.
On Wed, Feb 7, 2024 at 5:23 PM Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> wrote: > On 2024/02/08 2:57, Linus Torvalds wrote: > > On Wed, 7 Feb 2024 at 16:45, Paul Moore <paul@paul-moore.com> wrote: > >> > >> Okay, let's get confirmation from Tetsuo on the current state of > >> TOMOYO in Linus' tree. If it is currently broken [..] > > > > As far as I understand, the current state is working, just the horrid > > random flag. > > Yes, the current state is working. Thanks for confirming that Tetsuo.
diff --git a/fs/exec.c b/fs/exec.c index af4fbb61cd53..d6d35a06fd08 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1521,6 +1521,7 @@ static void free_bprm(struct linux_binprm *bprm) if (bprm->cred) { mutex_unlock(¤t->signal->cred_guard_mutex); abort_creds(bprm->cred); + security_execve_abort(); } do_close_execat(bprm->file); if (bprm->executable) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 76458b6d53da..fd100ab71a33 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -54,6 +54,7 @@ LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, const struct f LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm) LSM_HOOK(void, LSM_RET_VOID, bprm_committing_creds, const struct linux_binprm *bprm) LSM_HOOK(void, LSM_RET_VOID, bprm_committed_creds, const struct linux_binprm *bprm) +LSM_HOOK(void, LSM_RET_VOID, execve_abort, void) LSM_HOOK(int, 0, fs_context_submount, struct fs_context *fc, struct super_block *reference) LSM_HOOK(int, 0, fs_context_dup, struct fs_context *fc, struct fs_context *src_sc) diff --git a/include/linux/security.h b/include/linux/security.h index d0eb20f90b26..31532b30c4f0 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -299,6 +299,7 @@ int security_bprm_creds_from_file(struct linux_binprm *bprm, const struct file * int security_bprm_check(struct linux_binprm *bprm); void security_bprm_committing_creds(const struct linux_binprm *bprm); void security_bprm_committed_creds(const struct linux_binprm *bprm); +void security_execve_abort(void); int security_fs_context_submount(struct fs_context *fc, struct super_block *reference); int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc); int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param); @@ -648,6 +649,10 @@ static inline void security_bprm_committed_creds(const struct linux_binprm *bprm { } +static inline void security_execve_abort(void) +{ +} + static inline int security_fs_context_submount(struct fs_context *fc, struct super_block *reference) { diff --git a/security/security.c b/security/security.c index 3aaad75c9ce8..10adc4d3c5e0 100644 --- a/security/security.c +++ b/security/security.c @@ -1223,6 +1223,17 @@ void security_bprm_committed_creds(const struct linux_binprm *bprm) call_void_hook(bprm_committed_creds, bprm); } +/** + * security_execve_abort() - Notify that exec() has failed + * + * This hook is for undoing changes which cannot be discarded by + * abort_creds(). + */ +void security_execve_abort(void) +{ + call_void_hook(execve_abort); +} + /** * security_fs_context_submount() - Initialise fc->security * @fc: new filesystem context