From patchwork Fri Jun 22 23:23:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Strachan X-Patchwork-Id: 934131 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="VT4ke7z8"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41DjHJ1Fpjz9s2L for ; Mon, 25 Jun 2018 18:38:04 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AFB653E7636 for ; Mon, 25 Jun 2018 10:38:01 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 4A5823E60B3 for ; Sat, 23 Jun 2018 01:23:58 +0200 (CEST) Received: from mail-vk0-x249.google.com (mail-vk0-x249.google.com [IPv6:2607:f8b0:400c:c05::249]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 4B42D1000459 for ; Sat, 23 Jun 2018 01:23:57 +0200 (CEST) Received: by mail-vk0-x249.google.com with SMTP id y200-v6so3230062vky.7 for ; Fri, 22 Jun 2018 16:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=rEDEJ9NJH8VymJZ6WA3tzPO/fWPAXw3GHVFa3kQh/ps=; b=VT4ke7z815uq91NQBrmuaRTpfZqs0Ejz0wiT8mse/Lv004MpUU7Xaw5I/eGumO9LUB 2y7asktTlmHqt8/dVS640ZGknM4DxP8ltUORoMDW0sfSEe92dK1EiZL73w5hwvN7kD4F SxsOPikOreC8afwuKa1GoNZho7DhanlTiUz6BdAXuRBNpd6YV9XGWjcU7dEIPG6WTRmC nJGoMrDsH+jXDtQSQ1VEA4gZt98sxC14hR1Z8imtaQr8D7qzwOlMNugAZGHQbDJqyegx fI1AHtDxiUFyhmgY7ALE9spw7PHpFE5IGWHQR/pluJl0yRCLCQiMq53S8dxMo1XfH+bH r5ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=rEDEJ9NJH8VymJZ6WA3tzPO/fWPAXw3GHVFa3kQh/ps=; b=JeZlLwz7rjxAsTQwk+LvDSot+PuxG9794MRK6MXPRmKgpcqyh3r9rElGtPPSr+OWRf a7eVve6qQyKSBwJIjZ6D+rqgRnn8uXRttS1GLUpccni2ULqCQjybyY/eJGA94v0Ud0k2 cCu5Wrbufq33kfzynPgxT9cdy/m/JmxZS0ATU+JysRN9FoA2mExUvx+HuhuUb+1/K7tv +yEkh6rlPskBUab0q/1LwwXizEbtnyqSPCEqF/L+PanEaDRtypjFyyvjoImQBvqA4WH4 aWHcHkG1EZ//NAKesurQz4BDz0fQGszKmgIKk7h6izfSYvTs3lXtBNUULIhepzR8FKrP mnDQ== X-Gm-Message-State: APt69E3RyzKTTLm3LkahsbPaVAPqRN9+HvYKVHql0PuDMegcTpsqp2Gt qLIOq0soYAKTZDyVRzBD1LGnSpPmbOj+65WLwgIixAFZgF9+uXsmUEIQQ6+vM3S4L0CNJDJlWCC Mc3dM+BQKJZ9W0STbDQ7geMnOuDMdsB0Y9LgqXPDeEcTSySKiF0DHNdmZhSUBwIpq X-Google-Smtp-Source: AAOMgpf8SrJ1NHeyzviJ2HRsoVAJc5zIZKfycRg/I2ilO1Ww3fhsz895VO8aXMRBnuKhiQx/ITihf4pOp3NZ4NI= MIME-Version: 1.0 X-Received: by 2002:ab0:70ac:: with SMTP id q12-v6mr1573529ual.21.1529709835977; Fri, 22 Jun 2018 16:23:55 -0700 (PDT) Date: Fri, 22 Jun 2018 16:23:53 -0700 Message-Id: <20180622232353.151563-1-astrachan@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog From: Alistair Strachan To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it X-Mailman-Approved-At: Mon, 25 Jun 2018 10:37:44 +0200 Cc: kernel-team@android.com Subject: [LTP] [PATCH] verify_caps_exec: Respect TMP environment variable X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The filecapstest.sh wrapper script already allows the /tmp directory to be overridden with the TMP environment variable, however doing so has no effect on verify_caps_exec because it creates its own version of this fifo at a hardcoded location under /tmp. To ensure the fifo is correctly removed by the wrapper script, alter verify_caps_exec to respect the TMP environment variable and create a fifo at the same location. Signed-off-by: Alistair Strachan --- .../security/filecaps/verify_caps_exec.c | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/security/filecaps/verify_caps_exec.c b/testcases/kernel/security/filecaps/verify_caps_exec.c index 2c5cc0b2a..ff0a4837b 100644 --- a/testcases/kernel/security/filecaps/verify_caps_exec.c +++ b/testcases/kernel/security/filecaps/verify_caps_exec.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "config.h" #if HAVE_SYS_CAPABILITY_H #include @@ -119,22 +120,36 @@ static int perms_test(void) return ret; } -#define FIFOFILE "/tmp/caps_fifo" +static const char *get_caps_fifo(void) +{ + static char fifofile[PATH_MAX] = { 0, }; + + if (!fifofile[0]) { + const char *tmpdir = getenv("TMP"); + + if (!tmpdir) + tmpdir = "/tmp"; + snprintf(fifofile, PATH_MAX, "%s/caps_fifo", tmpdir); + } + + return fifofile; +} + static void create_fifo(void) { int ret; - ret = mkfifo(FIFOFILE, S_IRWXU | S_IRWXG | S_IRWXO); + ret = mkfifo(get_caps_fifo(), S_IRWXU | S_IRWXG | S_IRWXO); if (ret == -1 && errno != EEXIST) tst_brkm(TFAIL | TERRNO, NULL, "failed creating %s\n", - FIFOFILE); + get_caps_fifo()); } static void write_to_fifo(const char *buf) { int fd; - fd = open(FIFOFILE, O_WRONLY); + fd = open(get_caps_fifo(), O_WRONLY); write(fd, buf, strlen(buf)); close(fd); } @@ -144,7 +159,7 @@ static void read_from_fifo(char *buf) int fd; memset(buf, 0, 200); - fd = open(FIFOFILE, O_RDONLY); + fd = open(get_caps_fifo(), O_RDONLY); if (fd < 0) tst_brkm(TFAIL | TERRNO, NULL, "Failed opening fifo\n"); read(fd, buf, 199);