From: tal.tchwella@gmail.com
To: linux-kernel@vger.kernel.org
Cc: tchwella@mit.edu
Subject: [PATCH 3/3] open fds check when starting chroot
Date: Wed, 20 Mar 2013 06:09:07 -0700 [thread overview]
Message-ID: <1363784947-24060-4-git-send-email-tal.tchwella@gmail.com> (raw)
In-Reply-To: <1363784947-24060-1-git-send-email-tal.tchwella@gmail.com>
From: Tal Tchwella <tchwella@mit.edu>
This patch checks for open fds to directories when a non-root user tries to chroot,
and does not allow that user to chroot if the application has an open fd to a directory
because the appilcation has an escape path with that fd.
Signed-off-by: Tal Tchwella <tchwella@mit.edu>
---
fs/open.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/fs/open.c b/fs/open.c
index 82832d8..6dc6443 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -426,6 +426,30 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
{
struct path path;
int error;
+ struct files_struct *current_files;
+ struct fdtable *files_table;
+ int i = 0;
+
+ error = -EPERM;
+ /*
+ * Checks to see if there are open file descriptors to directories
+ * when a user that does not have the chroot capability
+ * tries to chroot. Since chroot is availble to all users,
+ * want to eliminate ways to break out. The second part
+ * of the if statement, is true by default,
+ * since during the initilization of the kernel, it
+ * goes into chroot mode.
+ */
+ if (!capable(CAP_SYS_CHROOT) && current->user_chroot != CHROOT_INIT) {
+ current_files = current->files;
+ files_table = files_fdtable(current_files);
+ while (files_table->fd[i] != NULL) {
+ if (S_ISDIR(files_table->fd[i]->
+ f_dentry->d_inode->i_mode))
+ goto out;
+ i++;
+ }
+ }
error = user_path_dir(filename, &path);
if (error)
--
1.7.9.5
next prev parent reply other threads:[~2013-03-20 13:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-20 13:09 [PATCH 0/3] Patches to enable chroot for all users tal.tchwella
2013-03-20 13:09 ` [PATCH 1/3] enabled " tal.tchwella
2013-03-20 13:09 ` [PATCH 2/3] socket checks for uds fds transfer tal.tchwella
2013-03-20 13:09 ` tal.tchwella [this message]
2013-03-20 15:35 ` [PATCH 0/3] Patches to enable chroot for all users Casey Schaufler
-- strict thread matches above, loose matches on Subject: below --
2013-03-20 12:53 Tal Tchwella
2013-03-20 12:53 ` [PATCH 3/3] open fds check when starting chroot Tal Tchwella
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=1363784947-24060-4-git-send-email-tal.tchwella@gmail.com \
--to=tal.tchwella@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tchwella@mit.edu \
/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
Powered by JetHome