Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1844431rbb; Tue, 27 Feb 2024 03:06:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7NVtS6RJ9anpFmtTI6L/j0hR+6b3ij/lAg0YVOqpn2SwGB5m/lLBh5vYGf2W+g3aUWDuyzKjD2zaHijbXvcWRFBDkG9uDo9eLbc7pFg== X-Google-Smtp-Source: AGHT+IFt3Brd4nr7TkIIwi43gpnFnigZArdaJa/y4/vhWbqpK1aEFV2PlZtWH3fomxE9X33AbdTO X-Received: by 2002:a17:906:168f:b0:a3f:583c:b005 with SMTP id s15-20020a170906168f00b00a3f583cb005mr6601946ejd.55.1709032013208; Tue, 27 Feb 2024 03:06:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709032013; cv=pass; d=google.com; s=arc-20160816; b=ymQ2lX/SGkugNaIep8ChNr+AX+qdhHaF5LCqDUnLrpeiYb9WW5s9+nkNfsdCKy84Un UIn34+f73vRXFJSGEh5O53dJ8Di8ib3vXfGQYKo4E8K77IB22YftJ4k5QZN9pWz+zElw 6xwSL8FIQWrAQSFFrSOL4xZk0bN6Et8z7Gh9hcwUUcG0FSnSWKd9NqBKef18wo7jq4lv rpfWKtC0v69IUisCvE+4ZzklSy/LdmYx1N+gta6wDHPDowyf+hQzeJlB/3SzjiUkR3Zn IOG4vuowfhq/P+mZ6tIWLhVKRuf5pKt3fDXV7WLYAi1SdHRvUaYB+P9je7eOsNTy989g tdzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7ypRpZtpArNK6J+/q9HdBvyEwLdUeFYk76lIMLSmZU4=; fh=SdM8AuPHyc7UBevB0e5vFTFJXyucRz4h4ci5G/v3IDU=; b=dgg/k46Dcr+Y4Ld0HwhTAkC4OA9REob/MaFDixoewz1q07R1vrYURkuEM6+4S4gOhP 4JkFeRTZdL5j8droYnEnaCA4PFRy2c1Q+8HpivAMWS4QT9W0TpuSlu8RrbeJTFnR2WOZ T86RwinkyKV2n0y/ZRxcZv8vK920CiNwxwymNqpuPpQwetAy/Ty+2IrZggAOutvEMwZu gK/CN3DW2xVzksdkfN8qc/brYkeCpEInpGaIRo1saA1WmJO5o+JpxMQnscJnmajizEl2 fHw5XP0WVSHKTHMEMBEPKTB36cDPl9jH8n9aS8JrejzOZbmlolyhffnyL4iNVtijwkPW BZ8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="oCw/iF23"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-83095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83095-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cb22-20020a170906a45600b00a3f84d83b4asi678337ejb.619.2024.02.27.03.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="oCw/iF23"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-83095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83095-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AAC071F24D42 for ; Tue, 27 Feb 2024 11:06:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95D5C13A244; Tue, 27 Feb 2024 11:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="oCw/iF23" Received: from smtp-8fa9.mail.infomaniak.ch (smtp-8fa9.mail.infomaniak.ch [83.166.143.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87CD1386CF; Tue, 27 Feb 2024 11:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709031976; cv=none; b=mp0QAo7RMBPQstTb02JEA8qeU3q9272C/3FOPHFLTtxe42LlyVDGyRt9SaEp1SoHOOs4YbfTvQaKywt0GgfaL3EyehOMcRlQzgDGXiKA1YTpNP8MOwsZP/hheafp58EgDNFlNsgVYYJpNnE6GKj+xVTuf4RfzVEx8eseSjKMpH0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709031976; c=relaxed/simple; bh=jPUoWxQfL0gN4M9XnMPtb4OVmzxvQ8jhCx4n49IoT7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gWgoNqp/EMPYDlzGfr/dm1v4s3jBOb1/etbsf2ujKFmgnnpOAFKdWQ97Uj0YU+L2tgKbKZ3+bFit66WnaKzmwjE0fXuNExH7nxU5+1Ho7KU2wd7MFYoYrjs4i1VBwSdwezv1yZkFTaUR0bS6L23BSvVI228PepjIchUCXn/V3qY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=oCw/iF23; arc=none smtp.client-ip=83.166.143.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TkZRL3hQgzfF; Tue, 27 Feb 2024 12:06:06 +0100 (CET) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4TkZRL0Ngrz3k; Tue, 27 Feb 2024 12:06:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1709031966; bh=jPUoWxQfL0gN4M9XnMPtb4OVmzxvQ8jhCx4n49IoT7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCw/iF23a34Rv0MBwr2Ia6cQ8m8h0jvHC8OAnyauVIncs0HoaFwNz47dPhVBwgEjw R5yruWwiqbByh+WzDRqxenUS46BMI9ak98EP9PcOxTd4ecJ/LXUlBEDCPa5K9iN5Qt hb3lJFSu+CT4yjc6FlcRhOYLyM3bfinMCILgyBUg= From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: =?UTF-8?q?G=C3=BCnther=20Noack?= , Paul Moore , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Konstantin Meskhidze , Shervin Oloumi , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, stable@vger.kernel.org, Kees Cook , =?UTF-8?q?G=C3=BCnther=20Noack?= Subject: [PATCH v2 2/2] landlock: Warn once if a Landlock action is requested while disabled Date: Tue, 27 Feb 2024 12:05:50 +0100 Message-ID: <20240227110550.3702236-2-mic@digikod.net> In-Reply-To: <20240227110550.3702236-1-mic@digikod.net> References: <20240227110550.3702236-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha Because sandboxing can be used as an opportunistic security measure, user space may not log unsupported features. Let the system administrator know if an application tries to use Landlock but failed because it isn't enabled at boot time. This may be caused by bootloader configurations with outdated "lsm" kernel's command-line parameter. Cc: stable@vger.kernel.org Fixes: 265885daf3e5 ("landlock: Add syscall implementations") Reviewed-by: Kees Cook Reviewed-by: Günther Noack Signed-off-by: Mickaël Salaün --- Changes since v1: * Add Kees's and Günther's Reviewed-by. * Rename is_not_initialized() to not_initialized() and invert the logic, as suggested by Günther. This is a cosmetic change without global behavioral changed. * Update link to point to a new subsection. --- security/landlock/syscalls.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c index 898358f57fa0..6788e73b6681 100644 --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -33,6 +33,18 @@ #include "ruleset.h" #include "setup.h" +static bool is_initialized(void) +{ + if (likely(landlock_initialized)) + return true; + + pr_warn_once( + "Disabled but requested by user space. " + "You should enable Landlock at boot time: " + "https://docs.kernel.org/userspace-api/landlock.html#boot-time-configuration\n"); + return false; +} + /** * copy_min_struct_from_user - Safe future-proof argument copying * @@ -173,7 +185,7 @@ SYSCALL_DEFINE3(landlock_create_ruleset, /* Build-time checks. */ build_check_abi(); - if (!landlock_initialized) + if (!is_initialized()) return -EOPNOTSUPP; if (flags) { @@ -398,7 +410,7 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd, struct landlock_ruleset *ruleset; int err; - if (!landlock_initialized) + if (!is_initialized()) return -EOPNOTSUPP; /* No flag for now. */ @@ -458,7 +470,7 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32, struct landlock_cred_security *new_llcred; int err; - if (!landlock_initialized) + if (!is_initialized()) return -EOPNOTSUPP; /* -- 2.44.0