Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2644485rwr; Fri, 28 Apr 2023 13:30:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vWEFGL1tZIoKS8nL3d8t2c/zqttqOvscRlSUVNsYpwoJYacz/ZiBi9mXcl5iJT2fo2Wch X-Received: by 2002:a17:90a:183:b0:236:1ec1:6d30 with SMTP id 3-20020a17090a018300b002361ec16d30mr5837419pjc.3.1682713847159; Fri, 28 Apr 2023 13:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682713847; cv=none; d=google.com; s=arc-20160816; b=GCp/wvUtXO1usnwZytIA5E38FTCwqA6MKOqxvgaH1v9NRp08sZpWFnLhA7rbQ9Rc/a 01BrH3OWJJOSMS+MnCRkGSQnFKeJEozgpXxxsEnC1TEDDG2DIk31cfr/qp/fxA2Ci88a +BO4wciKDu/vx0hTjPL1uTX0Dh34BAb+sIQYz9f2vkd5pO6yShGEg9MUftMCf831ADfP fIGt+7v6hCoqbhbd4HAioOYz/08My9qvP+sHH47mGvPBtFOY78NsO9jNunU5FhGfBOqA O7e7zrXcNIavMlhYEPa0XMENCMJ+gGb7gWS9v3Iem9na3IvFEd5+O2Aoh7Gc2jGXnhoM BTQw== 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=Ajm60wF5I0gYEUkydj0wCdAb9pRiDpAjZsyIeMwI/HzhBPT3tHB4giejCrm/K5hW+d 2HJ701pXFtLHH0FprVdU0dXNjfCx1pOEAQCmCoRofKWVKfrDL7ZVsP1V0DTh9058XRrM 3ilWf4LEMQAE2QNNszpK0uaFLiIsrnk8s33XeWXL+PsrOHVHfpXjMmruN4mOrkY9pQpP E41ICERL5hXr4WuiygHhVqev+ZoSzoTxgfySkc4o2rB+9Ce7CaICvPBUHS1PXpLRSHTI EOjg77V8i4py/XCji+tiHFW2HtXZpmBpn6Aql62M6rWH/7y3IcgOMxXJyDA2tLV1RVT6 A0sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=oiN6rQSl; 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 t19-20020a17090a5d9300b0024be0f71516si2789312pji.69.2023.04.28.13.30.33; Fri, 28 Apr 2023 13:30:47 -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=oiN6rQSl; 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 S1346534AbjD1U2t (ORCPT + 99 others); Fri, 28 Apr 2023 16:28:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346125AbjD1U2k (ORCPT ); Fri, 28 Apr 2023 16:28:40 -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 524D01A4 for ; Fri, 28 Apr 2023 13:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1682713718; bh=3rrx2/4CPchvROU7XfPjU63ZFDXsxZuUk/9nazGCq3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=oiN6rQSlVNOINNLUDvFahlFzE6OaW6ivEOwn3XEmFGJ0TkzELD5dEy+mw78yb1mMdwudcFmST7KGuj5nSxPfjiXTYU+evfrM/TPKbp3BGMHR2SlSHjmdbGKSUWPdvbPY5g32ePYkpZFNAgmE9si8XHnzebMwnJTK1HHfdwG6W+q4+aopgsWEizDV9ADckQFpfCs1PjLypRPkRmTOv/v8AoCbWT8GYe/qyiepYT2QG8y7BrfRRDdvQLmaKLn0PH6VUCPBmoQnoFO8oPciRcCSh92EkTHu5hsS5oEuiThhr1Z6YbvNtLqY+XiGHSNL03zRuWBfsKQFzdio0sjK06GaYA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1682713718; bh=lJ0QVD5wkDil+YgIbx19IPl2Vyf0WCSRCNhQ8pYXfiu=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=hXMQeLB4qPzS8pzTB/pzxV5ZL6RuZnOVehzz7xAJZab835qKvP8vohurf2PBG4LllbmT8N/kr6GQYf108wmDV3Pmzd5O/AA8P43LbzBGc17ioZzzv2wFP6R41kjaP4TNBi+Tw1hFbAH7tgkVoJnDDUMBx3Dtpn/tVU7X97ovBIQFlFVo9wffbzdQbtPW6yltUzYoCrWg/9VTlchWncf+t/9b2JEUUvtIjOszwiK7c77BlzrK/0KmqJD/wtIsbgsHIq20+cuPBoxytyh9wKbuaitMm3lNbB0rgE3lJgeDJYPDpNQahUXQgyV69NxUPptFrNz26yL25Sqlp0awgQzCvw== X-YMail-OSG: _7O72f8VM1nHW5HLy7KME2Hsa67vEzsSvgGv_iVXcWQR62mqtj6jJVOCS7qjIoZ KYNIGi8CEv9333NWNEUeFYfyrOBILADInQgmVwOk.D77arzZak7y9YHX9rOVnQLa3qyalLFnrJWy 8wn0vfwEJWxC71jlzCFXwD44TcVcfqJN5Ep1GlsuqjbOTpNvKDjtesuJ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toDn.5hKqbbY3A4vx5LtFS4Jjbm7MdCNd1d eVHIal39.dg94BqwACCY- X-Sonic-MF: X-Sonic-ID: b45a82f2-6dc2-4956-8fcd-1d405b8b8989 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Fri, 28 Apr 2023 20:28:38 +0000 Received: by hermes--production-ne1-7dbd98dd99-tcjjg (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID b58a5884cc254441b7169bc1ab603d8d; Fri, 28 Apr 2023 20:28:35 +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:26:45 -0700 Message-Id: <20230428202651.159828-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230428202651.159828-1-casey@schaufler-ca.com> References: <20230428202651.159828-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