From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-security-module@vger.kernel.org,
Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Eric Paris <eparis@parisplace.org>,
selinux@vger.kernel.org, Casey Schaufler <casey@schaufler-ca.com>,
Eric Biederman <ebiederm@xmission.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Matthew Wilcox <willy@infradead.org>
Subject: [PATCH v3 2/2] proc: ensure security hook is called after exec
Date: Fri, 18 Dec 2020 16:06:16 -0800 [thread overview]
Message-ID: <20201219000616.197585-2-stephen.s.brennan@oracle.com> (raw)
In-Reply-To: <20201219000616.197585-1-stephen.s.brennan@oracle.com>
Smack needs its security_task_to_inode() hook to be called when a task
execs a new executable. Store the self_exec_id of the task and call the
hook via pid_update_inode() whenever the exec_id changes.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
As discussed on the v2 of the patch, this should allow Smack to receive a
security_task_to_inode() call only when the uid/gid changes, or when the task
execs a new binary. I have verified that this doesn't change the performance of
the patch set, and that we do fall out of RCU walk on tasks which have recently
exec'd.
fs/proc/base.c | 4 +++-
fs/proc/internal.h | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 4b246e9bd5df..ad59e92e8433 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1917,6 +1917,7 @@ struct inode *proc_pid_make_inode(struct super_block * sb,
}
task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid);
+ ei->exec_id = task->self_exec_id;
security_task_to_inode(task, inode);
out:
@@ -1965,6 +1966,7 @@ void pid_update_inode(struct task_struct *task, struct inode *inode)
task_dump_owner(task, inode->i_mode, &inode->i_uid, &inode->i_gid);
inode->i_mode &= ~(S_ISUID | S_ISGID);
+ PROC_I(inode)->exec_id = task->self_exec_id;
security_task_to_inode(task, inode);
}
@@ -1979,7 +1981,7 @@ static bool pid_inode_needs_update(struct task_struct *task, struct inode *inode
task_dump_owner(task, inode->i_mode, &uid, &gid);
if (!uid_eq(uid, inode->i_uid) || !gid_eq(gid, inode->i_gid))
return true;
- return false;
+ return task->self_exec_id != PROC_I(inode)->exec_id;
}
/*
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index f60b379dcdc7..1df9b039dfc3 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -92,7 +92,10 @@ union proc_op {
struct proc_inode {
struct pid *pid;
- unsigned int fd;
+ union {
+ unsigned int fd;
+ u32 exec_id;
+ };
union proc_op op;
struct proc_dir_entry *pde;
struct ctl_table_header *sysctl;
--
2.25.1
next prev parent reply other threads:[~2020-12-19 0:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-19 0:06 [PATCH v3 1/2] proc: Allow pid_revalidate() during LOOKUP_RCU Stephen Brennan
2020-12-19 0:06 ` Stephen Brennan [this message]
2021-01-04 14:16 ` [PATCH v3 2/2] proc: ensure security hook is called after exec Stephen Smalley
2021-01-04 14:22 ` Stephen Smalley
2021-01-04 19:51 ` Stephen Brennan
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=20201219000616.197585-2-stephen.s.brennan@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=adobriyan@gmail.com \
--cc=casey@schaufler-ca.com \
--cc=ebiederm@xmission.com \
--cc=eparis@parisplace.org \
--cc=jmorris@namei.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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).