Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1325203rdb; Mon, 19 Feb 2024 11:19:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV1ovCOMpBxP2mPLlT/jlbRtvPoyKBgCcegnGfag9f+HaLayFL3iFZDhe4j7iZ4k6QKjO1hcsRCa4Q9/29XNLtp7cMZTkoAqIrZmeQuPQ== X-Google-Smtp-Source: AGHT+IHko8IYacJwl92E4dOik0Rdu5VgqJYw+2pTsUB2CZ8dXn81TdvLXGilKg8WYdNf2Cvfj/zK X-Received: by 2002:a17:902:820c:b0:1db:7052:2f62 with SMTP id x12-20020a170902820c00b001db70522f62mr11217613pln.50.1708370353168; Mon, 19 Feb 2024 11:19:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708370353; cv=pass; d=google.com; s=arc-20160816; b=pxeewieogfdP03RZnvA6J13SeCbjWn+LmWGqTNWNabn3Fwvt9Dmy/2Ckok2eIA8iVt F8lQD2FuA6FIvhR5w+AkNZMYMcKF3I0IqZnCLQuKR+PxS3PZ8IVH/p1p/9k63Rzn8/7d +Pcg4zi7k9cTQjDGxFX+D28Xt12tcLMFD8b68EJ5SWncbgc4qPWT6MUyn7jM/tM3g9BI +mXhh1VhZ+kRyGIrvwDQgqhSidOalx/zf15oIzNpdtZZ+y6ungdu9Awp0oI+xzgZ6Fu3 99T1oUs9z4ha5lapbOalV/O9J6GK5F2bz5YzD1yL4YKFVEv7TVQY2rQdEFc7VT5ZHzU7 iuJw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=9e7Y/Wztq2yfZaAb/Ap9+m9mjN7h7oHSxMZwECWtMO4=; fh=PH643LKJgvuZYoiKapu6Yf2SgFAZHKph804h5Bo2C84=; b=mp7WvhYdmSzmEmbODmlWUcB6Pjy+H/VkT1Q2QdTT3ZaJQRFCgnSwHiAIqDiL5axZKR ocWdEZTNdF+ryKQyAic21evrR6Nrd90KhHxl8+0wYHoWV7Miay+c9ie7+U0bKsGB1d2R uPiZoofxoTJ8/kVj0t3h2263F757/oJ9SNP8PGVMOHBgruK3+mSvcbvtOuLTvdhU/LIR dsWt5Q/gbW5hGwdcqT0cEuKN0YZz//WTbiL/cAYgryCnMyKSLybOGu4sYT10Gdl1o04I sXrJ/Pt3gjnksCYy0GAm+riZd9EQtferjpdx/EWQkxwC946Rza3GQnhFMdgaeBJC09Jl 4pHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=vX0UKSCQ; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-71860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71860-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e14-20020a170902ef4e00b001d9481c14bcsi4935236plx.414.2024.02.19.11.19.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:19:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=vX0UKSCQ; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-71860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71860-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9F318B21A1D for ; Mon, 19 Feb 2024 19:18:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9457650A62; Mon, 19 Feb 2024 19:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="vX0UKSCQ" Received: from smtp-8fad.mail.infomaniak.ch (smtp-8fad.mail.infomaniak.ch [83.166.143.173]) (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 EB1975026E for ; Mon, 19 Feb 2024 19:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370304; cv=none; b=s9QrYcSHUCH+MYgXmLKU8radzWMrF0x18mni26ZYw5pfeZVm864We99VJJenX/uZ7qJaBlLF2rEE3qEE+mlJXw+R80uLXuExiYnCh4wO3bSfhpi01orQP0F4mG1fxnFctpi04lr7KXbUkwSE5aLWDfbpJJpklrl8EQqzJdpafKI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370304; c=relaxed/simple; bh=lWp1mvnF6XdLVxAwayXsUI7kHokjjbIIQ8IV4f8d2fc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GBKdlMNpz49RLE02AYqctzAVOPUmoRWgUIr0vAZqPWKLX0YObpF784XMr95nPfZQ+Ln0nV4ygMifo+6uANrp+jd8VouWpyMb6PmJqy90YHoxiqg8wnpvIlN5WId2Vw7qyd/mYJ8fHdqQNgKNWR8Ka8PK4Amei9+lH9l7xowblRU= 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=vX0UKSCQ; arc=none smtp.client-ip=83.166.143.173 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-4-0001.mail.infomaniak.ch (smtp-4-0001.mail.infomaniak.ch [10.7.10.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4Tdsks0cSsznBQ; Mon, 19 Feb 2024 20:18:13 +0100 (CET) Received: from unknown by smtp-4-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4Tdskr0wsqzHNV; Mon, 19 Feb 2024 20:18:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1708370292; bh=lWp1mvnF6XdLVxAwayXsUI7kHokjjbIIQ8IV4f8d2fc=; h=From:To:Cc:Subject:Date:From; b=vX0UKSCQSIn+wlfY47YBGvvF7KwJaXD7ijzCLv/U/WDG0LHjbyGxgSQhOIDPlmWWQ vi2Dkp6AVjK6V9IqjgVRfi7e0rq4/qStY9YSQbUUwZtQXZOGf6Y9XoXbnp4YByabAO LhvcVHDitDj0ZJvKLkWU7AeIpW5uQjot3UxaVR5Q= 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 Subject: [PATCH] landlock: Warn once if a Landlock action is requested while disabled Date: Mon, 19 Feb 2024 20:18:04 +0100 Message-ID: <20240219191804.2978911-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: Günther Noack Cc: stable@vger.kernel.org Fixes: 265885daf3e5 ("landlock: Add syscall implementations") Signed-off-by: Mickaël Salaün --- 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 f0bc50003b46..b5b424819dee 100644 --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -33,6 +33,18 @@ #include "ruleset.h" #include "setup.h" +static bool is_not_initialized(void) +{ + if (likely(landlock_initialized)) + return false; + + pr_warn_once( + "Disabled but requested by user space. " + "You should enable Landlock at boot time: " + "https://docs.kernel.org/userspace-api/landlock.html#kernel-support\n"); + return true; +} + /** * 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_not_initialized()) return -EOPNOTSUPP; if (flags) { @@ -407,7 +419,7 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd, struct landlock_ruleset *ruleset; int err; - if (!landlock_initialized) + if (is_not_initialized()) return -EOPNOTSUPP; /* No flag for now. */ @@ -467,7 +479,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_not_initialized()) return -EOPNOTSUPP; /* -- 2.43.0