Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2660254rwr; Fri, 28 Apr 2023 13:48:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5IvDk0Csv468zZiwy1yfQrfeQr+e3S4hrUY8WAffwvyF48+gLTuDDDXJz7DfV0AxDwuX3L X-Received: by 2002:a17:902:d4c5:b0:1a9:6467:aa8d with SMTP id o5-20020a170902d4c500b001a96467aa8dmr7847919plg.1.1682714892596; Fri, 28 Apr 2023 13:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682714892; cv=none; d=google.com; s=arc-20160816; b=ca39yfCQIhrnz2DB79NgAHq7jUhmbXlAT8fVG/DoTBiHLPMVBI7d0q/xMgdw7ljWs6 FxTcPrdQ379uIbP6MZvx3XHQ/6KZYKXGskcFYEdfPNjx8hfJhixF6dEBxBUeqC+YIFES RlL25+euGCPZEp5T57P3oIrliLXEOgmfsE22LtB+GXNaCzLEwgpgotM+/p1VIrY1wEQy b8/KHSIKcC6gdY8Rix5ecN6BHlrE7kQHmIB97cNsunXLK8HdVfNaQ9QrZX+lepXOgFlJ +7TsOtFzc4b4+5Suy3oEe99CDvPpYBgNPUIFdfVkyH5Bicfqs03CUTyTnVLzuaYJbXyo SaxQ== 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=3rrx2/4CPchvROU7XfPjU63ZFDXsxZuUk/9nazGCq3E=; b=kUmTcHro3Ko4gl7SPb66mJVjyvdCrMDDwSYrnLKib5g8YdqHKfQbP+qCjp6plnIfXU f4f7oVHHJmo99Rt5EXrmczTt5BRDcQZIja+aAUH6RFK6bxhcmWMKJf3jCBwAYmzYHykO xMLUvT1ilzcIhb30FgGV6LRtM0IJy7Tlf4r5GoUg36GwLHdsVEpY0KPbbdcSW0tHW7eA AmV4ienlec1QMUhvTw/KcppmURBNK21pXLipmkjBgu3BLY5zaSlEE/c0Gl3DW5OoPMpE pEysOhA5Yb9qT3VeLilFkzIhUA51MCQtuky/RX+I+HgFOQRccgnsdFUZD590GvLOBu6o A87Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=QarBwP1c; 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 t9-20020a170902e84900b001a804319df8si24716026plg.391.2023.04.28.13.47.59; Fri, 28 Apr 2023 13:48:12 -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=QarBwP1c; 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 S1346674AbjD1UgN (ORCPT + 99 others); Fri, 28 Apr 2023 16:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjD1UgG (ORCPT ); Fri, 28 Apr 2023 16:36:06 -0400 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC9D12D for ; Fri, 28 Apr 2023 13:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1682714164; bh=3rrx2/4CPchvROU7XfPjU63ZFDXsxZuUk/9nazGCq3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=QarBwP1cqGeFWbaKZ2C71JNds/uzP0VoVOxSrxp7xUGsHjKyB6uWQS3zFf7rEtsAPLtV1e+K2+xg892OSV4Z3IbPYDa/KJ21ZbBMrlyhTY1AiNLHjzvmrcFpg6JGbQgDscaGzBMSNCqsuAl1Fthd9DhLprR4uf2ONCirleclNjgngzrJpl65uvbWTpkcIV5bUbE0mcSFA80ejPiWemAEz8ApXD4f9Zr+NHtzH27/x7BTBeI23Ai9n4CNHeZB8LRG+UIwB/9DNDMiFwDkJIiL9fuMv3/wyG32bZjzvW0I9UH2QLKvm4xXtTQtnC8omeNWVujAeZkm8YV2BQcRXqzSjA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1682714164; bh=H37CGhumWx4FB7+rIMRkSjNGRaIDHEZs7VpSPRXrt6Y=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=UEVXPGch/X8yc9DZhmVFWvgABQjAJrZfxlbcPnyUVfpvQ6a4bV6Dh95AHIGMyBD/xmD42KDCd9nY0+p7YENiSw7HeL9FNP5tcGOzTM/Um618UP4UOKJ0qM0SpzCcs1qsgijzZQXfR8cqaC8NNEuhbWEMSAEuynmHk+PA920wGsjOdkzvfrRQo4Y30OMufzaEANYejhOmcpvlftV9kQUHXcmrhDozVTdOjB0i5/6w0mPgcXiyp9WYVYwV5dYmMNXV2IJkrf3WI6ymLQs8zb/jyx2S3suRc8g44m61iyRrpscngkpSj1YPQ6/GCk7wWD7cOrfq/as894z5Z92M9qXheg== X-YMail-OSG: heNZ4NsVM1mFG5yjiEhwstl562EkzWndqoodPUDm3pMTVFFYgRdMCN5inYmbGiG NTIXW2mH1TgDZMUcuc8VgZ592BRitseBsBxf7SCwniI_SlnMHp_pfG29W69tnlPjUEsPCtlaEUg4 0zX1c.chXLTrOzu4eyvxgSLTjgJDTve.H5BvMegvdQaw7rdlejjescvMv.B.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jaT wwp1bQwVH_0CwbgiYwPs2aQLR6_SpVw-- X-Sonic-MF: X-Sonic-ID: 04ee8b1f-8535-4f91-bcbb-ac5db4472d63 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Fri, 28 Apr 2023 20:36:04 +0000 Received: by hermes--production-gq1-546798879c-mpgfb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ba26e713cb439f1ca91afc1b8b946229; Fri, 28 Apr 2023 20:35:59 +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 v10 05/11] LSM: Create lsm_list_modules system call Date: Fri, 28 Apr 2023 13:34:11 -0700 Message-Id: <20230428203417.159874-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230428203417.159874-1-casey@schaufler-ca.com> References: <20230428203417.159874-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, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Reviewed-by: Kees Cook --- 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 e6c3f262addc..9edae18a2688 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 9a94c31bf6b6..ddbcc333f3c3 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, size_t size, __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 ee3881159241..b89cccb2f123 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