Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6588882rwl; Thu, 29 Dec 2022 16:08:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtwFhnvsbvRNeTDvG0ArHlRigx8o2mlvi6fEyXfO4nFMLvlTDxUBOTq3X2vbj5nZKrbW008 X-Received: by 2002:a05:6a20:4e04:b0:9d:efbf:786a with SMTP id gk4-20020a056a204e0400b0009defbf786amr33868337pzb.31.1672358903667; Thu, 29 Dec 2022 16:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672358903; cv=none; d=google.com; s=arc-20160816; b=cbtO9yZLoeuPIe+9fcWI2wOTvZmdOFYWe+cOBLOyqJl/uVOZt1GjftQIevRoDEfySP 986HGBm0bhNfIxhiag/BLk1SUi24oBwasnlgclAhyVRSIlUlUPH+fcVKwz13sjOer9Rj 68pdvfyoHGVvgGltv8h7b/JBqEwPcaazdxveR/HFl5RSGPdF5iBkOkeBaxhBAD4sab2N i3mtO/0UHCr3EFtCZQIW8gy3k8i2/YM1nA03BJGfz7ot+DrmThjyOGVpxCBrwucgOSWL kLY5ZUTd/6n7wIEWdd5LxONuRfUnvSTM7JOPwtW+P5QWoiKQ0RmGoxtBnCRLaExj+ELK TFEw== 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=nXuYCBxN4Zmh9IPWHGdwx157B1zGKh55272CrsdwG88=; b=iFpX/vKPiI77M8hkh+dyfalIoEgAq361gziwMIbTxUz+0yTS6Mf2r8bftFRaaBIUtS NWXDGpF0OKeHzRkOsoOTvPvrGvai4j8L9IpGkfN5NQZXIviG3xHO5ts6U8CCkzTPjTGv uaIapkkxP5uhks0sHSaGcTcMYV3vL1SzoH3YALfAc21zGlJfzoij9PBNS90TRQzVbu90 NI6WiYVOuy9veC03VSMkyp/10A6CJbfLTfGmPmHZK8/Zf0m9yxeWmx3gkx+aKas0H3t/ UqvUwaCOTj+v10/ggLuwQocycl+UJrW8l1sWyWH+E64sIWVxu/CKYCTCfOucNci322Ug zoWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=cFmUyHHo; 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 x138-20020a633190000000b0045d60c88ad2si23302652pgx.164.2022.12.29.16.08.10; Thu, 29 Dec 2022 16:08:23 -0800 (PST) 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=cFmUyHHo; 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 S234251AbiL2XhX (ORCPT + 62 others); Thu, 29 Dec 2022 18:37:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234321AbiL2Xgy (ORCPT ); Thu, 29 Dec 2022 18:36:54 -0500 Received: from sonic310-31.consmr.mail.ne1.yahoo.com (sonic310-31.consmr.mail.ne1.yahoo.com [66.163.186.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4619511A2B for ; Thu, 29 Dec 2022 15:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1672357012; bh=nXuYCBxN4Zmh9IPWHGdwx157B1zGKh55272CrsdwG88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=cFmUyHHo4cSiSAhl84uzkmvW6nphZiHwW7+ZeQ9AdzKhZ3dFBkdMB9NoeUTR9qXZiwO7R/XcWIwfwY2TNXVZpXz0Q7h/T/RN5DSCNAsJSveB4Y0BTIH0LMLFswkeF3xD3j1Ol9RvuM1L6VeIPvUlAQVrnofvyeQzJPdq0+Pc401N+djhR8rHSzEvKpS2csPKIirlIWqkmwq8UihUo5kdtNwb59BmNosuMo7GaBKYcSYYzeEMd7WJXaL6wct7/RAUBY7x+SIiNLc4n8hFI+YtDAMlVDy+ikiuZrY6fUkwA+WKyRJ28+NkfuvSeX5G5JqMwr/V/1b6zrJdLBPqYNgsXA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1672357012; bh=ICwp+xM9QxAlmAG6BB6zrRN5SYpylzaRB47F+tKZfPp=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=gzYcRC2pLO1kIMGhc0rsItFCPon1mAqnswGUkRFCnQxD0vnBPpVM6on4kmTHQ6qPVPbMMuvvEDn2m1voKMemHt55viI8n+0O11LLevocj/98uEef8/CD9lyCbV7dffTko9SCx9HYt83wxQp1y2iYlxifCk50pvyZLoawpNZvft4Ubojpp49JX58QfvnTJw9yVBdPb7kkjusNj2321Fvckza3u4m34VS1BnH/V0CTbhCpjJEi6c3/GSz9XuwyCyI0k3dnhnsIhHwGXpNkC9Rsh6LVmV8Hg1p7fo0Ca9fmGYV3gQpTHMYhq92v55tDdxIRtnmWwnWSBUWIigyJcx/a1Q== X-YMail-OSG: _sWu6zwVM1knPpwLX4.ZIAvnGh0VpVbKuQEWdSA.E6j.w8MlZZ.Hw_70TMRoXiq Unu_ZNxbaEAMtAOK5z1nfa9GMioWcjUCKWJFpngfLff2aDT6YjB9HtxjKaPtYnkWPB6KSGkq2TtZ BbeCXUP7FYchn0z5CF717JIM3rXcfk6ZMTYmEevHj35KKGEdiNNTany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sonic310.consmr.mail.ne1.yahoo.com with HTTP; Thu, 29 Dec 2022 23:36:52 +0000 Received: by hermes--production-bf1-5458f64d4-x4bxm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 2c9ed6e23ac4176228a90f5214b07a1b; Thu, 29 Dec 2022 23:36:47 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: casey@schaufler-ca.com, 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 v4 5/8] LSM: Create lsm_module_list system call Date: Thu, 29 Dec 2022 15:34:51 -0800 Message-Id: <20221229233454.43880-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221229233454.43880-1-casey@schaufler-ca.com> References: <20221229233454.43880-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 chosing 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 | 41 +++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/Documentation/userspace-api/lsm.rst b/Documentation/userspace-api/lsm.rst index 98a0c191b499..e342d75b99ab 100644 --- a/Documentation/userspace-api/lsm.rst +++ b/Documentation/userspace-api/lsm.rst @@ -57,6 +57,9 @@ Get the 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_module_list + Additional documentation ======================== diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a89205c70ffa..9eb4cb6bbeb1 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1061,6 +1061,7 @@ asmlinkage long sys_set_mempolicy_home_node(unsigned long start, unsigned long l unsigned long flags); asmlinkage long sys_lsm_get_self_attr(struct lsm_ctx *ctx, size_t *size, int flags); +asmlinkage long sys_lsm_module_list(u32 *ids, size_t *size, int flags); /* * Architecture-specific system calls diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 7b2513d5605d..af1fd28c0420 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -264,6 +264,7 @@ COND_SYSCALL(mremap); /* security/lsm_syscalls.c */ COND_SYSCALL(lsm_get_self_attr); +COND_SYSCALL(lsm_module_list); /* security/keys/keyctl.c */ COND_SYSCALL(add_key); diff --git a/security/lsm_syscalls.c b/security/lsm_syscalls.c index c109a0dc18fe..3838cdf66310 100644 --- a/security/lsm_syscalls.c +++ b/security/lsm_syscalls.c @@ -180,3 +180,44 @@ SYSCALL_DEFINE3(lsm_get_self_attr, kfree(final); return rc; } + +/** + * sys_lsm_module_list - 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_module_list, + __u32 __user *, ids, + size_t __user *, size, + __u64, 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.38.1