From: Alexander Holler <holler@ahsoftware.de>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 1/5] WIP: Add syscall unlinkat_s (currently x86* only)
Date: Mon, 2 Feb 2015 18:05:09 +0100 [thread overview]
Message-ID: <1422896713-25367-2-git-send-email-holler@ahsoftware.de> (raw)
In-Reply-To: <1422896713-25367-1-git-send-email-holler@ahsoftware.de>
Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
arch/x86/syscalls/syscall_32.tbl | 1 +
arch/x86/syscalls/syscall_64.tbl | 1 +
fs/namei.c | 38 ++++++++++++++++++++++++++++++-----
include/asm-generic/audit_dir_write.h | 1 +
include/linux/fs.h | 1 +
include/linux/syscalls.h | 1 +
include/uapi/asm-generic/unistd.h | 4 +++-
tools/perf/builtin-trace.c | 2 ++
8 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl
index 9fe1b5d..7a3d530 100644
--- a/arch/x86/syscalls/syscall_32.tbl
+++ b/arch/x86/syscalls/syscall_32.tbl
@@ -364,3 +364,4 @@
355 i386 getrandom sys_getrandom
356 i386 memfd_create sys_memfd_create
357 i386 bpf sys_bpf
+359 i386 unlinkat_s sys_unlinkat_s
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl
index 281150b..97eaf01 100644
--- a/arch/x86/syscalls/syscall_64.tbl
+++ b/arch/x86/syscalls/syscall_64.tbl
@@ -328,6 +328,7 @@
319 common memfd_create sys_memfd_create
320 common kexec_file_load sys_kexec_file_load
321 common bpf sys_bpf
+322 common unlinkat_s sys_unlinkat_s
#
# x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/fs/namei.c b/fs/namei.c
index db5fe86..1ad3724 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3717,7 +3717,7 @@ EXPORT_SYMBOL(vfs_unlink);
* writeout happening, and we don't want to prevent access to the directory
* while waiting on the I/O.
*/
-static long do_unlinkat(int dfd, const char __user *pathname)
+static long do_unlinkat(int dfd, const char __user *pathname, bool secure)
{
int error;
struct filename *name;
@@ -3759,8 +3759,25 @@ exit2:
dput(dentry);
}
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
- if (inode)
- iput(inode); /* truncate the inode here */
+ if (inode) {
+ // TODO:
+ // if (inode is file and 's' flag is set)
+ // secure = true;
+ if (!secure)
+ iput(inode); /* truncate the inode here */
+ else {
+ struct super_block *sb = inode->i_sb;
+ if (sb->s_op->set_secure_delete)
+ sb->s_op->set_secure_delete(sb, true);
+ // TODO: We should fail if secure isn't supported,
+ // look up how that's possible here.
+ iput(inode); /* truncate the inode here */
+ // TODO: check if sb is still valid after the inode is gone
+ sync_filesystem(sb);
+ if (sb->s_op->set_secure_delete)
+ sb->s_op->set_secure_delete(sb, false);
+ }
+ }
inode = NULL;
if (delegated_inode) {
error = break_deleg_wait(&delegated_inode);
@@ -3796,12 +3813,23 @@ SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag)
if (flag & AT_REMOVEDIR)
return do_rmdir(dfd, pathname);
- return do_unlinkat(dfd, pathname);
+ return do_unlinkat(dfd, pathname, false);
}
SYSCALL_DEFINE1(unlink, const char __user *, pathname)
{
- return do_unlinkat(AT_FDCWD, pathname);
+ return do_unlinkat(AT_FDCWD, pathname, false);
+}
+
+SYSCALL_DEFINE3(unlinkat_s, int, dfd, const char __user *, pathname, int, flag)
+{
+ if ((flag & ~AT_REMOVEDIR) != 0)
+ return -EINVAL;
+
+ if (flag & AT_REMOVEDIR)
+ return do_rmdir(dfd, pathname);
+
+ return do_unlinkat(dfd, pathname, true);
}
int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
diff --git a/include/asm-generic/audit_dir_write.h b/include/asm-generic/audit_dir_write.h
index 7b61db4..5282aba 100644
--- a/include/asm-generic/audit_dir_write.h
+++ b/include/asm-generic/audit_dir_write.h
@@ -29,4 +29,5 @@ __NR_unlinkat,
__NR_renameat,
__NR_linkat,
__NR_symlinkat,
+__NR_unlinkat_s,
#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9ab779e..039e969 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1594,6 +1594,7 @@ struct super_operations {
int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
long (*nr_cached_objects)(struct super_block *, int);
long (*free_cached_objects)(struct super_block *, long, int);
+ void (*set_secure_delete) (struct super_block *, bool);
};
/*
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index bda9b81..b88019b 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -877,4 +877,5 @@ asmlinkage long sys_seccomp(unsigned int op, unsigned int flags,
asmlinkage long sys_getrandom(char __user *buf, size_t count,
unsigned int flags);
asmlinkage long sys_bpf(int cmd, union bpf_attr *attr, unsigned int size);
+asmlinkage long sys_unlinkat_s(int dfd, const char __user * pathname, int flag);
#endif
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index 22749c1..2ba072e 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -707,9 +707,11 @@ __SYSCALL(__NR_getrandom, sys_getrandom)
__SYSCALL(__NR_memfd_create, sys_memfd_create)
#define __NR_bpf 280
__SYSCALL(__NR_bpf, sys_bpf)
+#define __NR_unlinkat_s 281
+__SYSCALL(__NR_unlinkat_s, sys_unlinkat_s)
#undef __NR_syscalls
-#define __NR_syscalls 281
+#define __NR_syscalls 282
/*
* All syscalls below here should go away really,
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index fb12645..1507335 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1110,6 +1110,8 @@ static struct syscall_fmt {
{ .name = "uname", .errmsg = true, .alias = "newuname", },
{ .name = "unlinkat", .errmsg = true,
.arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, },
+ { .name = "unlinkat_s", .errmsg = true,
+ .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, },
{ .name = "utimensat", .errmsg = true,
.arg_scnprintf = { [0] = SCA_FDAT, /* dirfd */ }, },
{ .name = "write", .errmsg = true,
--
2.1.0
next prev parent reply other threads:[~2015-02-02 17:05 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-02 17:05 [PATCH 0/5] RFC: Offer a way for userspace to request real deletion of files Alexander Holler
2015-02-02 17:05 ` Alexander Holler [this message]
2015-02-03 6:05 ` [PATCH 1/5] WIP: Add syscall unlinkat_s (currently x86* only) Al Viro
2015-02-03 6:58 ` Alexander Holler
2015-02-03 7:56 ` Al Viro
2015-02-03 8:01 ` Alexander Holler
2015-02-03 8:10 ` Al Viro
2015-02-03 8:17 ` Alexander Holler
2015-02-03 8:51 ` Alexander Holler
2015-02-03 9:23 ` Alexander Holler
2015-02-03 12:48 ` Alexander Holler
2015-02-03 12:54 ` Alexander Holler
2015-02-03 17:48 ` Theodore Ts'o
2015-02-03 18:01 ` Alexander Holler
2015-02-03 23:33 ` Al Viro
2015-02-04 0:18 ` Alex Elsayed
2015-02-04 4:16 ` Andreas Dilger
2015-02-04 10:19 ` Alexander Holler
2015-02-04 12:07 ` Lukáš Czerner
2015-02-04 12:22 ` Alexander Holler
2015-02-04 12:42 ` Alexander Holler
2015-02-04 12:50 ` Alexander Holler
2015-02-04 13:07 ` Alexander Holler
2015-02-04 13:06 ` Michael Kerrisk
2015-02-04 13:21 ` Alexander Holler
[not found] ` <54D21CC8.4020705-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 13:29 ` Alexander Holler
[not found] ` <54D21EB8.6020208-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 14:19 ` Alexander Holler
[not found] ` <54D22A63.7090603-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 15:00 ` Austin S Hemmelgarn
2015-02-04 14:52 ` Lukáš Czerner
[not found] ` <alpine.LFD.2.00.1502041533130.26766-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2015-02-04 16:12 ` Alexander Holler
2015-02-04 16:25 ` Lukáš Czerner
[not found] ` <alpine.LFD.2.00.15020 41724180.26766@localhost.localdomain>
[not found] ` <alpine.LFD.2.00.1502041724180.26766-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2015-02-04 16:45 ` Alexander Holler
[not found] ` <54D24CA5.6080603-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 16:53 ` Alexander Holler
2015-02-04 19:33 ` Theodore Ts'o
2015-02-04 19:56 ` Alexander Holler
2015-02-03 16:44 ` Alex Elsayed
2015-02-03 7:58 ` Davidlohr Bueso
2015-02-03 7:52 ` Alexander Holler
[not found] ` <1422896713-25367-2-git-send-email-holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 8:01 ` Michael Kerrisk
2015-02-02 17:05 ` [PATCH 2/5] WIP: fs: fat: support unlinkat_s() for secure deletion of files Alexander Holler
2015-02-02 17:05 ` [PATCH 3/5] WIP: fs: ext4: " Alexander Holler
2015-02-03 13:50 ` Lukáš Czerner
2015-02-03 14:50 ` Alexander Holler
2015-02-03 15:13 ` Alexander Holler
2015-02-03 15:24 ` Alexander Holler
2015-02-03 15:41 ` Lukáš Czerner
2015-02-03 15:46 ` Alexander Holler
2015-02-03 16:38 ` Alexander Holler
2015-02-03 18:50 ` Alexander Holler
2015-02-02 17:05 ` [PATCH 4/5] WIP: Add patch for coreutils to support unlinkat_s (x86_64 only) Alexander Holler
2015-02-02 17:05 ` [PATCH 5/5] WIP: Add test for unlinkat_s Alexander Holler
2015-02-03 15:15 ` [PATCH 0/5] RFC: Offer a way for userspace to request real deletion of files One Thousand Gnomes
2015-02-03 15:45 ` Alexander Holler
[not found] ` <1422896713-25367-1-git-send-email-holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2015-02-04 8:01 ` Michael Kerrisk
2015-02-06 12:17 ` Alexander Holler
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=1422896713-25367-2-git-send-email-holler@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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).