From: Wander Lairson Costa <wander@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Laurent Vivier <laurent@vivier.eu>,
YunQiang Su <ysu@wavecomp.com>,
Wander Lairson Costa <wander@redhat.com>,
Helge Deller <deller@gmx.de>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Andrew Morton <akpm@linux-foundation.org>,
Alexey Gladkov <legion@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Rafael Aquini <aquini@redhat.com>, Phil Auld <pauld@redhat.com>,
Rolf Eike Beer <eb@emlix.com>,
Muchun Song <songmuchun@bytedance.com>,
linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
infrastructure)), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH RFC 2/4] process: add the PF_SUID flag
Date: Mon, 27 Dec 2021 19:34:33 -0300 [thread overview]
Message-ID: <20211227223436.317091-3-wander@redhat.com> (raw)
In-Reply-To: <20211227223436.317091-1-wander@redhat.com>
If the binary file in an execve system call is a suid executable, we add
the PF_SUID flag to the process and all its future new children and
threads.
In a later commit, we will use this information to determine if it is
safe to core dump such a process.
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
fs/exec.c | 4 ++++
include/linux/sched.h | 1 +
kernel/fork.c | 2 ++
3 files changed, 7 insertions(+)
diff --git a/fs/exec.c b/fs/exec.c
index 3913b335b95f..b4bd157a5282 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1311,6 +1311,10 @@ int begin_new_exec(struct linux_binprm * bprm)
me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
PF_NOFREEZE | PF_NO_SETAFFINITY);
+
+ if (bprm->suid_bin)
+ me->flags |= PF_SUID;
+
flush_thread();
me->personality &= ~bprm->per_clear;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e3b328b81ac0..f7811c42b004 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1651,6 +1651,7 @@ extern struct pid *cad_pid;
#define PF_VCPU 0x00000001 /* I'm a virtual CPU */
#define PF_IDLE 0x00000002 /* I am an IDLE thread */
#define PF_EXITING 0x00000004 /* Getting shut down */
+#define PF_SUID 0x00000008 /* The process comes from a suid/sgid binary */
#define PF_IO_WORKER 0x00000010 /* Task is an IO worker */
#define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */
#define PF_FORKNOEXEC 0x00000040 /* Forked but didn't exec */
diff --git a/kernel/fork.c b/kernel/fork.c
index 231b1ba3ca9f..1e1ffff70d14 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2080,6 +2080,8 @@ static __latent_entropy struct task_struct *copy_process(
delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
p->flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER | PF_IDLE | PF_NO_SETAFFINITY);
p->flags |= PF_FORKNOEXEC;
+ if (current->flags & PF_SUID)
+ p->flags |= PF_SUID;
INIT_LIST_HEAD(&p->children);
INIT_LIST_HEAD(&p->sibling);
rcu_copy_process(p);
--
2.27.0
next prev parent reply other threads:[~2021-12-27 22:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-27 22:34 [PATCH RFC 0/4] coredump: mitigate privilege escalation of process coredump Wander Lairson Costa
2021-12-27 22:34 ` [PATCH RFC 1/4] exec: add a flag indicating if an exec file is a suid/sgid Wander Lairson Costa
2021-12-27 22:34 ` Wander Lairson Costa [this message]
2021-12-27 22:34 ` [PATCH RFC 3/4] coredump: mitigate privilege escalation of process coredump Wander Lairson Costa
2021-12-27 22:34 ` [PATCH RFC 4/4] exec: only set the suid flag if the current proc isn't root Wander Lairson Costa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211227223436.317091-3-wander@redhat.com \
--to=wander@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=aquini@redhat.com \
--cc=axboe@kernel.dk \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=deller@gmx.de \
--cc=dietmar.eggemann@arm.com \
--cc=eb@emlix.com \
--cc=ebiederm@xmission.com \
--cc=juri.lelli@redhat.com \
--cc=laurent@vivier.eu \
--cc=legion@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=pauld@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=songmuchun@bytedance.com \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=ysu@wavecomp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).