Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754262AbbBBRGL (ORCPT ); Mon, 2 Feb 2015 12:06:11 -0500 Received: from h1446028.stratoserver.net ([85.214.92.142]:59996 "EHLO mail.ahsoftware.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753321AbbBBRFe (ORCPT ); Mon, 2 Feb 2015 12:05:34 -0500 From: Alexander Holler To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexander Holler Subject: [PATCH 4/5] WIP: Add patch for coreutils to support unlinkat_s (x86_64 only) Date: Mon, 2 Feb 2015 18:05:12 +0100 Message-Id: <1422896713-25367-5-git-send-email-holler@ahsoftware.de> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422896713-25367-1-git-send-email-holler@ahsoftware.de> References: <1422896713-25367-1-git-send-email-holler@ahsoftware.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4404 Lines: 133 You have to build the new rm yourself Signed-off-by: Alexander Holler --- ...ion-s-to-rm-to-support-unlinkat_s-current.patch | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 0001-WIP-Add-option-s-to-rm-to-support-unlinkat_s-current.patch diff --git a/0001-WIP-Add-option-s-to-rm-to-support-unlinkat_s-current.patch b/0001-WIP-Add-option-s-to-rm-to-support-unlinkat_s-current.patch new file mode 100644 index 0000000..268cf56 --- /dev/null +++ b/0001-WIP-Add-option-s-to-rm-to-support-unlinkat_s-current.patch @@ -0,0 +1,111 @@ +From b4df97b5199e3fe7563a6e83a36fae031ee4777d Mon Sep 17 00:00:00 2001 +From: Alexander Holler +Date: Mon, 2 Feb 2015 16:59:24 +0100 +Subject: [PATCH] WIP: Add option -s to rm to support unlinkat_s() (currently + x86_64 only) + +Signed-off-by: Alexander Holler +--- + src/mv.c | 1 + + src/remove.c | 9 ++++++++- + src/remove.h | 3 +++ + src/rm.c | 9 ++++++++- + 4 files changed, 20 insertions(+), 2 deletions(-) + +diff --git a/src/mv.c b/src/mv.c +index 0bcc1bb..03d3417 100644 +--- a/src/mv.c ++++ b/src/mv.c +@@ -76,6 +76,7 @@ rm_option_init (struct rm_options *x) + x->ignore_missing_files = false; + x->remove_empty_directories = true; + x->recursive = true; ++ x->secure = false; + x->one_file_system = false; + + /* Should we prompt for removal, too? No. Prompting for the 'move' +diff --git a/src/remove.c b/src/remove.c +index db8f993..a97e72c 100644 +--- a/src/remove.c ++++ b/src/remove.c +@@ -367,7 +367,14 @@ static enum RM_status + excise (FTS *fts, FTSENT *ent, struct rm_options const *x, bool is_dir) + { + int flag = is_dir ? AT_REMOVEDIR : 0; +- if (unlinkat (fts->fts_cwd_fd, ent->fts_accpath, flag) == 0) ++ int rc; ++#ifdef __x86_64__ ++ if (x->secure) ++ rc = syscall (322, fts->fts_cwd_fd, ent->fts_accpath, flag); // x86_64 ++ else ++#endif ++ rc = unlinkat (fts->fts_cwd_fd, ent->fts_accpath, flag); ++ if (rc == 0) + { + if (x->verbose) + { +diff --git a/src/remove.h b/src/remove.h +index a450192..530b70b 100644 +--- a/src/remove.h ++++ b/src/remove.h +@@ -49,6 +49,9 @@ struct rm_options + /* If true, recursively remove directories. */ + bool recursive; + ++ /* If true, use unlinkat_s(). */ ++ bool secure; ++ + /* If true, remove empty directories. */ + bool remove_empty_directories; + +diff --git a/src/rm.c b/src/rm.c +index c1a23d5..c061579 100644 +--- a/src/rm.c ++++ b/src/rm.c +@@ -77,6 +77,7 @@ static struct option const long_opts[] = + {"-presume-input-tty", no_argument, NULL, PRESUME_INPUT_TTY_OPTION}, + + {"recursive", no_argument, NULL, 'r'}, ++ {"secure", no_argument, NULL, 's'}, + {"dir", no_argument, NULL, 'd'}, + {"verbose", no_argument, NULL, 'v'}, + {GETOPT_HELP_OPTION_DECL}, +@@ -155,6 +156,7 @@ Remove (unlink) the FILE(s).\n\ + --no-preserve-root do not treat '/' specially\n\ + --preserve-root do not remove '/' (default)\n\ + -r, -R, --recursive remove directories and their contents recursively\n\ ++ -s, --secure securely (use unlinkat_s)\n\ + -d, --dir remove empty directories\n\ + -v, --verbose explain what is being done\n\ + "), stdout); +@@ -193,6 +195,7 @@ rm_option_init (struct rm_options *x) + x->one_file_system = false; + x->remove_empty_directories = false; + x->recursive = false; ++ x->secure = false; + x->root_dev_ino = NULL; + x->stdin_tty = isatty (STDIN_FILENO); + x->verbose = false; +@@ -223,7 +226,7 @@ main (int argc, char **argv) + /* Try to disable the ability to unlink a directory. */ + priv_set_remove_linkdir (); + +- while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, NULL)) != -1) ++ while ((c = getopt_long (argc, argv, "dfirsvIR", long_opts, NULL)) != -1) + { + switch (c) + { +@@ -254,6 +257,10 @@ main (int argc, char **argv) + x.recursive = true; + break; + ++ case 's': ++ x.secure = true; ++ break; ++ + case INTERACTIVE_OPTION: + { + int i; +-- +2.1.0 + -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/