Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5720672rwl; Tue, 11 Apr 2023 09:05:26 -0700 (PDT) X-Google-Smtp-Source: AKy350bNOkdl3UbzX7grO9G4sAz9Rl1+wuF05AqG5FSGgdEd1l4ade1Nd3zeEn0hFQB8DvUHxGPd X-Received: by 2002:aa7:95b1:0:b0:62d:dd8b:f42a with SMTP id a17-20020aa795b1000000b0062ddd8bf42amr15705676pfk.25.1681229125735; Tue, 11 Apr 2023 09:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681229125; cv=none; d=google.com; s=arc-20160816; b=hrJfEt2jybNXZx9uIrL8soYRWCrOox+2gNiQZkDzhIU2lvefvv7BzjL5fowVadK0y9 Pwdm6lkTgx1FkSzLzdFmv8c/X7Z8LWcn88TOnlYppbcHiYg41YUjeDWKGedDv2+xGtp6 GXA84hUwjzqTreGEM8lP8jG4h7vDKANCbYWKXx90u9lKhCMc9ENBEPTHUgQTj3Tud8w/ PiR2AY3ePfbsKiIZ+NcqahEEEjv9SSiWRbcjNHqrh3QZGUkMjBly25wrJFO15+DAdw+x LWI84ilLuPopl9eVnUJI640z3Gow/SxF/lHp41sROns0+SdKsLZSiaZNChyqogw+Xh99 7FRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WWKn71lrpv08tQFC3mFllZTwYCHaZAApwvOSNdmKIP0=; b=D1Cy5MoMwwIGy+RJo1h0CSQe+0hzYLrJayXG6uaCdac2YzQHbdJEWtDD2ORVv+QKP3 MEm9fJ8qNRf9PPMeJ5AUZEpoFPNpqzYIVSJref9o3OCEtPvHF4GM5WUp3RSW8KgmFis9 ynLv5gKYhZ5/KFJe1ZY7OoxO0cg9UcVLbaDvN4jBhdKaHzht0geT+tr+Cpv1epAqWgDA JHJc5M5aKDNJsT3qBfqOVuKs7ImOtVHu6/FXtrrOADb+xxo6kJpNoR3mp/2m5fCHVdIb Se1tA5uwnj4PRiCCV/D9xC8+yXLJCEAqQqNcgFWYv/U8XAQ1xbJ2z5qBkAx5E3TJnN5u ZcIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=kmXCCjWX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s197-20020a632cce000000b004f2022f3cc2si14101904pgs.813.2023.04.11.09.05.05; Tue, 11 Apr 2023 09:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=kmXCCjWX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjDKQBl (ORCPT + 99 others); Tue, 11 Apr 2023 12:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230449AbjDKQBV (ORCPT ); Tue, 11 Apr 2023 12:01:21 -0400 Received: from sonic307-15.consmr.mail.ne1.yahoo.com (sonic307-15.consmr.mail.ne1.yahoo.com [66.163.190.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BDFC59D6 for ; Tue, 11 Apr 2023 09:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681228872; bh=WWKn71lrpv08tQFC3mFllZTwYCHaZAApwvOSNdmKIP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=kmXCCjWXxAgPgnSYBrmJw1VKxSeQhbExt02NPShwmWLIfwfQX7FoJ/oHa7JBCI8AqjYwPWmG2TviCfX4ewzdiBDynDwdZEGjEOVnU/Pt/xNEbgBvkzypRQVY1B8UiAi+rekgQizu1F4Tq1/EIhv0+uTuPXewU26wIIVAjARWJwYTyMM7r+a4CbP7FviTn8jaWxSryH70aYfsoqand6lPBSiHq0ZO5D/oBn8K3/QXviM91lhoY1rUMd9T0yx+5LAKYMv/w92th8xlbf8d3JivdnRQk0xFxBGiUmS6EpEM7JL8VBfy8YVAYznNJ20PoldD2WVPHw0TOvCrRcH+p2C0aA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681228872; bh=kZ6Y5O5nW9K2etas3eFy+njSD+OGSaNSE0PtLyy1AvC=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=H4rGROfAvT6dH4WJhaKYkEy7YKgOz6W6T8CidJWPC2hR3JWmLrPJ8D6/BdEX1WnJdIikrEOwI2qXrf5D1rzkpXBnxcBRQFFcEvkfHlC0qwcJ78Qi7MVNPfmzqXYjx8i4gayYb3Lz2uVCvHATSK4qX75uGVEKkim25IdDrE7dVwwztgG9b6JPJQNsOFlgUlJtGpRL6zUzb1clF2OuF6AThcbuKrukbHaiid/mBqn4NN+arhbOBYtou1X9Htv2r9oDmFVCkJJUvupJt9AIGLryiEdDfTwpFB1XXOlhTJpyNakoJzxJn1Dy9kPriHa2JpW7IfLUFRI0cTUvRUqy+BqYtA== X-YMail-OSG: KXP0MigVM1lG0a1i7D3qtSMY7A1_FdV.yzsjRwyw_bBQ8_.Ag4CuC52iPA4wKh3 yz6nW0oQWbYNk3HLnikqsjsXpSBedRk772TpxvWRkM_gJxNM626__mvmnJA1fJf0PmoQ5AUvvLh6 zYOLIEPvOgNxVxPMMaLr82bsXxU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jgPBRl1mgfZIdETlcsCfNqQp9ealPd_N63PojXOrZ2Mqrk_WfOCT f_2HeJer6QVzhbPn2jw-- X-Sonic-MF: X-Sonic-ID: a41358ba-f0f1-4e3f-8679-9a601b73b58c Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Tue, 11 Apr 2023 16:01:12 +0000 Received: by hermes--production-gq1-546798879c-7rgpc (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8b8bac55a2979a45d5da198554da66f8; Tue, 11 Apr 2023 16:01:08 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net Subject: [PATCH v8 05/11] LSM: Create lsm_list_modules system call Date: Tue, 11 Apr 2023 08:59:15 -0700 Message-Id: <20230411155921.14716-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411155921.14716-1-casey@schaufler-ca.com> References: <20230411155921.14716-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers. The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior. Signed-off-by: Casey Schaufler --- Documentation/userspace-api/lsm.rst | 3 +++ include/linux/syscalls.h | 1 + kernel/sys_ni.c | 1 + security/lsm_syscalls.c | 39 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/Documentation/userspace-api/lsm.rst b/Documentation/userspace-api/lsm.rst index b45e402302b3..a86e3817f062 100644 --- a/Documentation/userspace-api/lsm.rst +++ b/Documentation/userspace-api/lsm.rst @@ -63,6 +63,9 @@ Get the specified security attributes of the current process .. kernel-doc:: security/lsm_syscalls.c :identifiers: sys_lsm_get_self_attr +.. kernel-doc:: security/lsm_syscalls.c + :identifiers: sys_lsm_list_modules + Additional documentation ======================== diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 97487d66dca9..6f6525364288 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1063,6 +1063,7 @@ asmlinkage long sys_lsm_get_self_attr(unsigned int attr, struct lsm_ctx *ctx, size_t *size, __u32 flags); asmlinkage long sys_lsm_set_self_attr(unsigned int attr, struct lsm_ctx *ctx, __u32 flags); +asmlinkage long sys_lsm_list_modules(u64 *ids, size_t *size, u32 flags); /* * Architecture-specific system calls diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index d03c78ef1562..ceb3d21a62d0 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -265,6 +265,7 @@ COND_SYSCALL(mremap); /* security/lsm_syscalls.c */ COND_SYSCALL(lsm_get_self_attr); COND_SYSCALL(lsm_set_self_attr); +COND_SYSCALL(lsm_list_modules); /* security/keys/keyctl.c */ COND_SYSCALL(add_key); diff --git a/security/lsm_syscalls.c b/security/lsm_syscalls.c index feee31600219..6efbe244d304 100644 --- a/security/lsm_syscalls.c +++ b/security/lsm_syscalls.c @@ -53,3 +53,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, { return security_getselfattr(attr, ctx, size, flags); } + +/** + * sys_lsm_list_modules - Return a list of the active security modules + * @ids: the LSM module ids + * @size: size of @ids, updated on return + * @flags: reserved for future use, must be zero + * + * Returns a list of the active LSM ids. On success this function + * returns the number of @ids array elements. This value may be zero + * if there are no LSMs active. If @size is insufficient to contain + * the return data -E2BIG is returned and @size is set to the minimum + * required size. In all other cases a negative value indicating the + * error is returned. + */ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags) +{ + size_t total_size = lsm_active_cnt * sizeof(*ids); + size_t usize; + int i; + + if (flags) + return -EINVAL; + + if (get_user(usize, size)) + return -EFAULT; + + if (put_user(total_size, size) != 0) + return -EFAULT; + + if (usize < total_size) + return -E2BIG; + + for (i = 0; i < lsm_active_cnt; i++) + if (put_user(lsm_idlist[i]->id, ids++)) + return -EFAULT; + + return lsm_active_cnt; +} -- 2.39.2