From patchwork Sat Oct 1 15:49:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?G=C3=BCnther_Noack?= X-Patchwork-Id: 12996560 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C197DC433FE for ; Sat, 1 Oct 2022 15:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229441AbiJAPu2 (ORCPT ); Sat, 1 Oct 2022 11:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbiJAPtu (ORCPT ); Sat, 1 Oct 2022 11:49:50 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9696EA4; Sat, 1 Oct 2022 08:49:42 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id sd10so14633157ejc.2; Sat, 01 Oct 2022 08:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=C+GyJq5HgV0Z7OWkJYmIbswU12VCmy8zCOP8Qkw/Jxk=; b=JX+QhPsgsYH+4Y5925GaOBrdj9lBxxjGtGsfghXR46TFeSk6Yk73Ebx09carhitfhK 3sD+hWonnh8GIDKobAfguFdyEn2nFGQyMttYCv4QNmXVi3PU1DRzdYaoc9yEFxGaiELi zpTNf4K22+pB7GL5oX7YDfispzABA0AeDE4/rf6nydRK4K5g1NpEeoQalW/pxA5Cmzwe MNaxnYSPonmETpB8d/ks3a/FlWKhXcx1OGVUo0x12cwszXeOaWPvvuilFFqU9HaeppBZ hZXGD7OfrrpQbRa5CyzzAfbzXhLdXnhheYU0jgMZ8zrXjSsrmfyKQlxpx9xGLbASlKbe Ww5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=C+GyJq5HgV0Z7OWkJYmIbswU12VCmy8zCOP8Qkw/Jxk=; b=36ZhncJH/Y0fKzqxm9iMiPZoSxd0r3PwJjNRSrthbU/QNoQ09oVOcgo+4e5V3TGOc6 OEbbtetEMS5kYTClf7mwV9UtkfQW2M+VmxvyiwcH4ML8k9VfYtDqOuzDeTIk01Y+/kBD PvYLwLZBHBbbvJhgpFuSqkNiCSsHrMp4BlJL8IsmvI3fYd99nJttk4m8c+xSQtOZmIzL taud5eyRKPPO00mUYpnfHBurwgP/rTe0U7JkpwFwxNOIE+bZuRsUl6iHtzYJ6Ae+AGlO //QK/yQkLhRjRqcOC3i1EFqZTte4ILgtBZF5M4JRkmV4qhGNeeUwiIenUOYJMpIsEZt6 VI0A== X-Gm-Message-State: ACrzQf2uP2xR14wc4Wjm4z9SvG2nMhHJ2UgO9bo+9ywWE7Q0KUANzgKg 7UTBWSwTbqIjVwWxId5sEqqiI7F5Ljg= X-Google-Smtp-Source: AMsMyM682WsbaP7pWXQEJnQk9dUkboey1i8Vo103/2qFv1Had2nQ3ViU/u11AS9TaMpQ59i2C3hmVQ== X-Received: by 2002:a17:906:da86:b0:77a:52b3:da48 with SMTP id xh6-20020a170906da8600b0077a52b3da48mr9757858ejb.373.1664639381441; Sat, 01 Oct 2022 08:49:41 -0700 (PDT) Received: from nuc.i.gnoack.org ([2a02:168:633b:1:1e69:7aff:fe05:97e6]) by smtp.gmail.com with ESMTPSA id d26-20020aa7d69a000000b00458cc5f802asm617151edr.73.2022.10.01.08.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 08:49:41 -0700 (PDT) From: =?utf-8?q?G=C3=BCnther_Noack?= To: linux-security-module@vger.kernel.org Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , James Morris , Paul Moore , "Serge E . Hallyn" , linux-fsdevel@vger.kernel.org, Konstantin Meskhidze , =?utf-8?q?G=C3=BCnt?= =?utf-8?q?her_Noack?= Subject: [PATCH v8 8/9] samples/landlock: Extend sample tool to support LANDLOCK_ACCESS_FS_TRUNCATE Date: Sat, 1 Oct 2022 17:49:07 +0200 Message-Id: <20221001154908.49665-9-gnoack3000@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001154908.49665-1-gnoack3000@gmail.com> References: <20221001154908.49665-1-gnoack3000@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Update the sandboxer sample to restrict truncate actions. This is automatically enabled by default if the running kernel supports LANDLOCK_ACCESS_FS_TRUNCATE, except for the paths listed in the LL_FS_RW environment variable. Signed-off-by: Günther Noack --- samples/landlock/sandboxer.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c index 3e404e51ec64..771b6b10d519 100644 --- a/samples/landlock/sandboxer.c +++ b/samples/landlock/sandboxer.c @@ -76,7 +76,8 @@ static int parse_path(char *env_path, const char ***const path_list) #define ACCESS_FILE ( \ LANDLOCK_ACCESS_FS_EXECUTE | \ LANDLOCK_ACCESS_FS_WRITE_FILE | \ - LANDLOCK_ACCESS_FS_READ_FILE) + LANDLOCK_ACCESS_FS_READ_FILE | \ + LANDLOCK_ACCESS_FS_TRUNCATE) /* clang-format on */ @@ -160,10 +161,8 @@ static int populate_ruleset(const char *const env_var, const int ruleset_fd, LANDLOCK_ACCESS_FS_MAKE_FIFO | \ LANDLOCK_ACCESS_FS_MAKE_BLOCK | \ LANDLOCK_ACCESS_FS_MAKE_SYM | \ - LANDLOCK_ACCESS_FS_REFER) - -#define ACCESS_ABI_2 ( \ - LANDLOCK_ACCESS_FS_REFER) + LANDLOCK_ACCESS_FS_REFER | \ + LANDLOCK_ACCESS_FS_TRUNCATE) /* clang-format on */ @@ -226,11 +225,17 @@ int main(const int argc, char *const argv[], char *const *const envp) return 1; } /* Best-effort security. */ - if (abi < 2) { - ruleset_attr.handled_access_fs &= ~ACCESS_ABI_2; - access_fs_ro &= ~ACCESS_ABI_2; - access_fs_rw &= ~ACCESS_ABI_2; + switch (abi) { + case 1: + /* Removes LANDLOCK_ACCESS_FS_REFER for ABI < 2 */ + ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_REFER; + __attribute__((fallthrough)); + case 2: + /* Removes LANDLOCK_ACCESS_FS_TRUNCATE for ABI < 3 */ + ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_TRUNCATE; } + access_fs_ro &= ruleset_attr.handled_access_fs; + access_fs_rw &= ruleset_attr.handled_access_fs; ruleset_fd = landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);