From patchwork Mon Feb 2 17:05:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 5763241 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8F0BA9F336 for ; Mon, 2 Feb 2015 17:06:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2EFA2077D for ; Mon, 2 Feb 2015 17:06:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABAA12077C for ; Mon, 2 Feb 2015 17:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932082AbbBBRGL (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 Received: by mail.ahsoftware.de (Postfix, from userid 65534) id 15D7B2C9C45F; Mon, 2 Feb 2015 18:05:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from wandq.ahsoftware (p4FC36183.dip0.t-ipconnect.de [79.195.97.131]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id F0AA82C9C3F0; Mon, 2 Feb 2015 18:05:31 +0100 (CET) Received: by wandq.ahsoftware (Postfix, from userid 65534) id 5ECEC1E8284; Mon, 2 Feb 2015 18:05:31 +0100 (CET) Received: from krabat.ahsoftware (unknown [192.168.207.2]) by wandq.ahsoftware (Postfix) with ESMTP id E993F1E8271; Mon, 2 Feb 2015 17:05:18 +0000 (UTC) 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 +