From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A87EFC433DF for ; Mon, 18 May 2020 04:47:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 863D520715 for ; Mon, 18 May 2020 04:47:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="avL6pZkU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726378AbgERErr (ORCPT ); Mon, 18 May 2020 00:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbgERErr (ORCPT ); Mon, 18 May 2020 00:47:47 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C898C061A0C for ; Sun, 17 May 2020 21:47:46 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id x2so4382745pfx.7 for ; Sun, 17 May 2020 21:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=X/lhy2lqdLYOlnTnlwuNEX14NtdAXY44agjxDbsMHek=; b=avL6pZkUlCn+t3YkdiJMlLLxbozudebElBmHL2Tw6SfB9qnfnHabcBO154nR7cq50E nyJh5pPe9UlSBBXP2RjzipcR34z0Chi/1QkLlSg+oujwfALZuxmQbaWSHWomveBF/nPJ xM1LKug4z3C9em40JlstY1lONBmER/sBp3iFk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=X/lhy2lqdLYOlnTnlwuNEX14NtdAXY44agjxDbsMHek=; b=GUCqJH/cKPB5ovYEkM2aWlII/XEyUbonyQW3QceU0rVdiLzFU2j86UR+nN4eRHFZjq C25jN2ai8qnPDcQmkUIF2zpMZieNPLPDjJP9fBaZZeSNTRIBzWIqteORc6Dzln702YGJ Q25T4RRSClzYi6+DL3HheSWh96JP1MG9vbeCh9e2WQGA66ft8ZrZGxZiAB+BgkIw93Hl ipDNQWh6sNie/N7bDPk2QUUJKOJJdS+PBHbvSkbczj030P9qnXdAdJA7aMeuQECzsU9l +q6i648h1+FOjIP+dYRD8UAPadF3kJd63hUxABN7WaA5zIpBuJb9rldYaj4LHftTMb/s lUFg== X-Gm-Message-State: AOAM5326X2GtvCIX2Ei1JKGBAtPwXFUgnVyNuQN8tL7jr3Yde9wbT+T+ XGHnhUccWF+DhBJs8Ud1aDOqZA== X-Google-Smtp-Source: ABdhPJyC+IQcZZeglGPmJ9VEQKllWJvgBjA2CQs/cdQJaDsi3Z/YHvSXoNagRTwXLs2GUZqe6cjPeA== X-Received: by 2002:a63:df4f:: with SMTP id h15mr13604951pgj.30.1589777265568; Sun, 17 May 2020 21:47:45 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g6sm7259713pjx.48.2020.05.17.21.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 21:47:44 -0700 (PDT) Date: Sun, 17 May 2020 21:47:43 -0700 From: Kees Cook To: linux-kselftest@vger.kernel.org Cc: Shuah Khan , David Drysdale , Tetsuo Handa , Al Viro , Eric Biggers , Dmitry Vyukov , linux-kernel@vger.kernel.org Subject: [PATCH] selftests/exec: Verify execve of non-regular files fail Message-ID: <202005172143.D25AC29@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a named pipe as an exec target to make sure that non-regular files are rejected by execve() with EACCES. This can help verify commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files during execve()"). Signed-off-by: Kees Cook --- tools/testing/selftests/exec/.gitignore | 1 + tools/testing/selftests/exec/Makefile | 2 +- tools/testing/selftests/exec/execveat.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/exec/.gitignore b/tools/testing/selftests/exec/.gitignore index c078ece12ff0..94b02a18f230 100644 --- a/tools/testing/selftests/exec/.gitignore +++ b/tools/testing/selftests/exec/.gitignore @@ -9,3 +9,4 @@ execveat.ephemeral execveat.denatured /recursion-depth xxxxxxxx* +pipe diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile index 33339e31e365..cfafa1f8a2fa 100644 --- a/tools/testing/selftests/exec/Makefile +++ b/tools/testing/selftests/exec/Makefile @@ -4,7 +4,7 @@ CFLAGS += -Wno-nonnull CFLAGS += -D_GNU_SOURCE TEST_GEN_PROGS := execveat -TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir +TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir pipe # Makefile is a run-time dependency, since it's accessed by the execveat test TEST_FILES := Makefile diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c index cbb6efbdb786..67bf7254a48f 100644 --- a/tools/testing/selftests/exec/execveat.c +++ b/tools/testing/selftests/exec/execveat.c @@ -5,7 +5,9 @@ * Selftests for execveat(2). */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE /* to get O_PATH, AT_EMPTY_PATH */ +#endif #include #include #include @@ -311,6 +313,10 @@ static int run_tests(void) fail += check_execveat_fail(AT_FDCWD, fullname_symlink, AT_SYMLINK_NOFOLLOW, ELOOP); + /* Non-regular file failure */ + fail += check_execveat_fail(dot_dfd, "pipe", 0, EACCES); + unlink("pipe"); + /* Shell script wrapping executable file: */ /* dfd + path */ fail += check_execveat(subdir_dfd, "../script", 0); @@ -384,6 +390,8 @@ static void prerequisites(void) fd = open("subdir.ephemeral/script", O_RDWR|O_CREAT|O_TRUNC, 0755); write(fd, script, strlen(script)); close(fd); + + mkfifo("pipe", 0755); } int main(int argc, char **argv) -- 2.20.1 -- Kees Cook