what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

secrm.kernel.patch.2.2.14

secrm.kernel.patch.2.2.14
Posted Feb 22, 2000
Authored by Martin Mevald | Site penguin.cz

Secure Deletion under Linux kernel patch. If a regular file has set attribute "s" on ext2 filesystem, the file will be securely deleted after an "unlink" call by the "srm" program.

tags | kernel
systems | linux
SHA-256 | 185dbe50cdf98826e19a79ff400060c4cd6bac8183c39ca9ce245c94d15badea

secrm.kernel.patch.2.2.14

Change Mirror Download
diff -u -w -r /usr/src/linux-origin/fs/namei.c /usr/src/linux/fs/namei.c
--- /usr/src/linux-origin/fs/namei.c Sun Jan 30 17:03:48 2000
+++ /usr/src/linux/fs/namei.c Sat Feb 12 10:35:53 2000
@@ -12,11 +12,17 @@
* lookup logic.
*/

+#define __KERNEL_SYSCALLS__
+
#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/smp_lock.h>
#include <linux/quotaops.h>

+#include <linux/string.h>
+#include <linux/unistd.h>
+#include <linux/sched.h>
+
#include <asm/uaccess.h>
#include <asm/unaligned.h>
#include <asm/semaphore.h>
@@ -24,6 +30,8 @@
#include <asm/pgtable.h>

#include <asm/namei.h>
+#include <linux/ext2_fs.h> /* for EXT2_SECRM_FL */
+

/* This can be removed after the beta phase. */
#define CACHE_SUPERVISE /* debug the correctness of dcache entries */
@@ -1025,25 +1033,202 @@
return error;
}

-int vfs_unlink(struct inode *dir, struct dentry *dentry)
+
+
+
+
+
+/* call program secrm - security delete */
+static int vfs_unlink_exec_srm(void *file_name)
+{
+
+ static char * envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
+ char *argv[]={"/bin/secrm",(char *)file_name,NULL };
+
+
+
+ /* Prevent parent user process from sending signals to child.
+ Otherwise, if the secrm program does not exist, it might
+ be possible to get a user defined signal handler to execute
+ as the super user right after the execve fails if you time
+ the signal just right.
+ */
+ spin_lock_irq(&current->sigmask_lock);
+ flush_signals(current);
+ flush_signal_handlers(current);
+ spin_unlock_irq(&current->sigmask_lock);
+
+
+ /* Drop the "current user" thing */
+ free_uid(current);
+
+ /* Give secrm all privileges..
+ Waitpid reports error without it. */
+ current->uid = current->euid = current->fsuid = 0;
+ cap_set_full(current->cap_inheritable);
+ cap_set_full(current->cap_effective);
+
+
+
+
+
+ /* Allow execve args to be in kernel space. */
+
+
+
+/* printk("set_fs(KERNEL_DS)\n");*/
+
+ set_fs(KERNEL_DS);
+
+/* printk("Execve\n"); */
+
+ /* Go, go, go... */
+ if (execve("/bin/secrm", argv, envp) < 0) {
+
+ printk("vfs_unlink_exec_srm: can't exec /bin/secrm\n");
+ return -errno;
+ }
+
+ return 0;
+
+
+}
+
+
+int vfs_unlink(struct inode *dir, struct dentry *dentry, const char *name, struct dentry **dir2)
{
int error;
+ pid_t pid,waitpid_result;
+ int status;
+ sigset_t tmpsig;
+ mm_segment_t addr_limit;
+

error = may_delete(dir, dentry, 0);
if (!error) {
error = -EPERM;
if (dir->i_op && dir->i_op->unlink) {
+
+ /*dentry->d_inode->i_sb->s_type->name == ext2*/
+ /* filesystem type*/
+
+ if (!strcmp(dentry->d_inode->i_sb->s_type->name,"ext2"))
+ {
+
+
+ if (dentry->d_inode->u.ext2_i.i_flags & EXT2_SECRM_FL )
+ {
+
+
+ /* printk("Security flag set.\n"); */
+
+ if (S_ISREG(dentry->d_inode->i_mode)) {
+ /* printk("Regular file: %s\n",name); */
+
+ /* printk("Starting thread...\n"); */
+
+ unlock_dir(*dir2);
+ unlock_kernel();
+
+ *dir2=NULL; /* do_unlink - don't unlock*/
+ /* printk("vfs_unlink: unlock\n"); */
+
+ pid = kernel_thread(vfs_unlink_exec_srm, (void*) name, 0);
+
+
+
+ if (pid<0) {
+ printk("fork failed: vfs_unlink_exec_srm\n");
+ lock_kernel();
+ return -EIO;
+
+ }
+
+
+
+ /* Block everything but SIGKILL/SIGSTOP */
+ spin_lock_irq(&current->sigmask_lock);
+ tmpsig = current->blocked;
+ siginitsetinv(&current->blocked, sigmask(SIGKILL) | sigmask(SIGSTOP));
+ recalc_sigpending(current);
+ spin_unlock_irq(&current->sigmask_lock);
+
+ /*printk("Waitpid...\n");*/
+
+ addr_limit=get_fs();
+
+ set_fs(KERNEL_DS);
+
+
+ waitpid_result = waitpid(pid, &status,__WCLONE);
+
+ set_fs(addr_limit);
+
+ /* Allow signals again.. */
+ spin_lock_irq(&current->sigmask_lock);
+ current->blocked = tmpsig;
+ recalc_sigpending(current);
+ spin_unlock_irq(&current->sigmask_lock);
+
+
+
+ /*printk("\npid:%i\nwaitpid:%i\nresult:%i\n\n",pid,waitpid_result,status);*/
+
+ lock_kernel();
+
+ if (waitpid_result != pid) {
+
+ printk("vfs_unlink: secrm error (waitpid)\n");
+ return -EIO;
+ }
+
+ if (!status) return 0; /* OK */
+
+ if (status<0x100) {
+
+
+ printk("vfs_unlink: secrm - signal %i caught.\n",status);
+
+ return -EINTR;
+
+
+ }
+
+
+ status=status>>8;
+
+ /* printk("vfs_unlink: secrm exit code:%i\n",status); */
+
+ return -status;
+
+
+ }
+
+ }
+
+
+ }
+
+
+
+
+
DQUOT_INIT(dir);
error = dir->i_op->unlink(dir, dentry);
+
}
+
}
+
return error;
}

+
+
static inline int do_unlink(const char * name)
{
int error;
- struct dentry *dir;
+ struct dentry *dir,*dir2;
struct dentry *dentry;

dentry = lookup_dentry(name, NULL, 0);
@@ -1051,12 +1236,15 @@
if (IS_ERR(dentry))
goto exit;

- dir = lock_parent(dentry);
+ dir=dir2= lock_parent(dentry);
error = -ENOENT;
if (check_parent(dir, dentry))
- error = vfs_unlink(dir->d_inode, dentry);
+ error = vfs_unlink(dir->d_inode, dentry,name,&dir2);

- unlock_dir(dir);
+ /* dir2 == NULL - dir unlocked */
+
+ if (dir2) unlock_dir(dir);
+/* else printk("do_unlock: don't unlock\n"); */
dput(dentry);
exit:
return error;
diff -u -w -r /usr/src/linux-origin/include/linux/fs.h /usr/src/linux/include/linux/fs.h
--- /usr/src/linux-origin/include/linux/fs.h Sun Jan 30 17:48:15 2000
+++ /usr/src/linux/include/linux/fs.h Wed Feb 9 23:49:16 2000
@@ -566,7 +566,7 @@
* VFS helper functions..
*/
extern int vfs_rmdir(struct inode *, struct dentry *);
-extern int vfs_unlink(struct inode *, struct dentry *);
+extern int vfs_unlink(struct inode *, struct dentry *, const char * name, struct dentry **) ;
extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);

/*
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    0 Files
  • 17
    Apr 17th
    0 Files
  • 18
    Apr 18th
    0 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close