From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sonic310-30.consmr.mail.ne1.yahoo.com (sonic310-30.consmr.mail.ne1.yahoo.com [66.163.186.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D23BA2F83BB for ; Fri, 10 Oct 2025 15:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.163.186.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760109344; cv=none; b=A4yXwSXCSmfMfpd0Gyco5KltrJbw7iXnexQqlha6iVOqMjvT7xUVutqSaS+bYHzeUWpc9cbtLPlr2BqrqgozAeh9m/2ziR/rvJPTeHBOwqRx3MD5PScszeiF8Eq3Z1Dz87XT0XzG29iozrWjQhcMu6LgreMqqh4Z3wNdHCJ6V7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760109344; c=relaxed/simple; bh=O7vJu4u6ys9inKro9P2h9NErr4/dr5wJFRq/c2zu5yk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EjkKKxpT3vZPqZnyyYyohk4H+cSaOnQKPpm9shwMX9u6EnttQqmh1sRcidiqDIqA+Gj3varGFkf8NkB0jJMprrO+E/meW80QHW6NImln1tI2ea21ZPZytE5tQ3MW2vMNKJgS30dTrKNTPddGJdJv9skOldGA7d6wMWHH6LO4RdU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com; spf=none smtp.mailfrom=schaufler-ca.com; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b=dpPycjBc; arc=none smtp.client-ip=66.163.186.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="dpPycjBc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1760109342; bh=dRYAjFrXP3E1+9sZiWcQjvbUIK8Bm2BRi67VqMWynBE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=dpPycjBcgmQTx7hQAb3doSpGyMh0Y8Wx4MkTMOrwosZJjIXFmygZ8F7qWQ83vppRXBCFlsJXv0QfafFlNJlsx+LduGJZNUnkO8FEOrBpP4YN+I4PBR8Yi/naINcS9x11F/dMsCN4nuAt2vHS9uonmHQb8GVEMxlyOCC0WiCrBd0YPD1NbCN/vdGMjpT4s3uOgvBcUcOA+xiEurFtv+b3DyDpVbzVfCE7BHG9zGOCugJnQckZzhsZddyfKDPcTqtQAXKb7zvi1O1+r6MFHf5jU7gwPTeYb+xdNAdKNtnSNsd5n+qFzKRwqiHUGv96ETUia+QOn6yGDMPNhkaSemr9HA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1760109342; bh=CMy7zU0hFZfi05XDI6EQ393Ll9F5DT12CZN1Tud9JHD=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=WmkzJdJUHRI/VOO2I0wZkZEnVLq3cwspKBPTiHllP45uijPBuYUVLGRALViNSzz/ZxKrq0gp24kbWbhApbfBVTNiEuGblRJ+9kYC8Y2yOOtYwZIkGdHGsI6edROtyLiXp700c39rRlhX84u73ekJzElRfWqCB8pF1MZmNRN7bqvdtXK2n/fb3rizR2ByTzvC/YGrmMDJHMXrl0fSXW/ILmCc2hsLBRyXHRUoevw1hSOsy3Ra2lYeQHXOt+iFwBa1k3zUHUXTPt7Qgo/itsQ72F1ecTnQepH31WS9SdyMbkAg8W0e+Ag4hNetYFVZ7CU0lZoqMMDgB8Ya4ZSx6f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oH8Fh5qc1wuqzF2iSZoDprqKkJ4.c_ZOTjkhepvLpybSDerV4adTCXFRZP4 MZi.893ef6N8FhiQ5_s8HSW2I5FOaxzZzokNe9G4wgBeboOBk4ETnAiH.WdIS5XUU11OqS9P_gYS OtkKC7sczAL8VitAIVRcJCSvYpVePXUbE_Rgb5M9tvP1TsYM.zILyCKbR6untwY5JxhSWAHsqNBc sN.cWSYo_3vaV1Dihzi51Wu9V X-Sonic-MF: X-Sonic-ID: 397e9ee9-8051-4bd7-a384-f966a5b3db07 Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Fri, 10 Oct 2025 15:15:42 +0000 Received: by hermes--production-gq1-66b66ffd5-4kj8j (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 5a3bbbe036446cce417e04accb83fa7c; Fri, 10 Oct 2025 15:15:39 +0000 (UTC) Message-ID: Date: Fri, 10 Oct 2025 08:15:37 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 5/5] Smack: add support for lsm_config_self_policy and lsm_config_system_policy To: =?UTF-8?Q?Maxime_B=C3=A9lair?= , linux-security-module@vger.kernel.org Cc: john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, mic@digikod.net, kees@kernel.org, stephen.smalley.work@gmail.com, takedakn@nttdata.co.jp, penguin-kernel@I-love.SAKURA.ne.jp, song@kernel.org, rdunlap@infradead.org, linux-api@vger.kernel.org, apparmor@lists.ubuntu.com, linux-kernel@vger.kernel.org, Casey Schaufler References: <20251010132610.12001-1-maxime.belair@canonical.com> <20251010132610.12001-6-maxime.belair@canonical.com> Content-Language: en-US From: Casey Schaufler In-Reply-To: <20251010132610.12001-6-maxime.belair@canonical.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: WebService/1.1.24562 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo On 10/10/2025 6:25 AM, Maxime Bélair wrote: > Enable users to manage Smack policies through the new hooks > lsm_config_self_policy and lsm_config_system_policy. > > lsm_config_self_policy allows adding Smack policies for the current cred. > For now it remains restricted to CAP_MAC_ADMIN. > > lsm_config_system_policy allows adding globabl Smack policies. This is > restricted to CAP_MAC_ADMIN. > > Signed-off-by: Maxime Bélair I will be reviewing these patches, but will not be able to do so until early November. I know how frustrating review delays can be, but it really can't be helped this time around. Thank you for your patience. > --- > security/smack/smack.h | 8 +++++ > security/smack/smack_lsm.c | 73 ++++++++++++++++++++++++++++++++++++++ > security/smack/smackfs.c | 2 +- > 3 files changed, 82 insertions(+), 1 deletion(-) > > diff --git a/security/smack/smack.h b/security/smack/smack.h > index bf6a6ed3946c..3e3d30dfdcf7 100644 > --- a/security/smack/smack.h > +++ b/security/smack/smack.h > @@ -275,6 +275,14 @@ struct smk_audit_info { > #endif > }; > > +/* > + * This function is in smackfs.c > + */ > +ssize_t smk_write_rules_list(struct file *file, const char __user *buf, > + size_t count, loff_t *ppos, > + struct list_head *rule_list, > + struct mutex *rule_lock, int format); > + > /* > * These functions are in smack_access.c > */ > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index 99833168604e..bf4bb2242768 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -5027,6 +5027,76 @@ static int smack_uring_cmd(struct io_uring_cmd *ioucmd) > > #endif /* CONFIG_IO_URING */ > > +/** > + * smack_lsm_config_system_policy - Configure a system smack policy > + * @op: operation to perform. Currently, only LSM_POLICY_LOAD is supported > + * @buf: User-supplied buffer in the form "" > + * is the 1-byte format of > + * is the policy to load > + * @size: size of @buf > + * @flags: reserved for future use; must be zero > + * > + * Returns: number of written rules on success, negative value on error > + */ > +static int smack_lsm_config_system_policy(u32 op, void __user *buf, size_t size, > + u32 flags) > +{ > + loff_t pos = 0; > + u8 fmt; > + > + if (op != LSM_POLICY_LOAD || flags) > + return -EOPNOTSUPP; > + > + if (size < 2) > + return -EINVAL; > + > + if (get_user(fmt, (uint8_t *)buf)) > + return -EFAULT; > + > + return smk_write_rules_list(NULL, buf + 1, size - 1, &pos, NULL, NULL, fmt); > +} > + > +/** > + * smack_lsm_config_self_policy - Configure a smack policy for the current cred > + * @op: operation to perform. Currently, only LSM_POLICY_LOAD is supported > + * @buf: User-supplied buffer in the form "" > + * is the 1-byte format of > + * is the policy to load > + * @size: size of @buf > + * @flags: reserved for future use; must be zero > + * > + * Returns: number of written rules on success, negative value on error > + */ > +static int smack_lsm_config_self_policy(u32 op, void __user *buf, size_t size, > + u32 flags) > +{ > + loff_t pos = 0; > + u8 fmt; > + struct task_smack *tsp; > + > + if (op != LSM_POLICY_LOAD || flags) > + return -EOPNOTSUPP; > + > + if (size < 2) > + return -EINVAL; > + > + if (get_user(fmt, (uint8_t *)buf)) > + return -EFAULT; > + /** > + * smk_write_rules_list could be used to gain privileges. > + * This function is thus restricted to CAP_MAC_ADMIN. > + * TODO: Ensure that the new rule does not give extra privileges > + * before dropping this CAP_MAC_ADMIN check. > + */ > + if (!capable(CAP_MAC_ADMIN)) > + return -EPERM; > + > + > + tsp = smack_cred(current_cred()); > + return smk_write_rules_list(NULL, buf + 1, size - 1, &pos, &tsp->smk_rules, > + &tsp->smk_rules_lock, fmt); > +} > + > struct lsm_blob_sizes smack_blob_sizes __ro_after_init = { > .lbs_cred = sizeof(struct task_smack), > .lbs_file = sizeof(struct smack_known *), > @@ -5203,6 +5273,9 @@ static struct security_hook_list smack_hooks[] __ro_after_init = { > LSM_HOOK_INIT(uring_sqpoll, smack_uring_sqpoll), > LSM_HOOK_INIT(uring_cmd, smack_uring_cmd), > #endif > + LSM_HOOK_INIT(lsm_config_self_policy, smack_lsm_config_self_policy), > + LSM_HOOK_INIT(lsm_config_system_policy, smack_lsm_config_system_policy), > + > }; > > > diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c > index 90a67e410808..ed1814588d56 100644 > --- a/security/smack/smackfs.c > +++ b/security/smack/smackfs.c > @@ -441,7 +441,7 @@ static ssize_t smk_parse_long_rule(char *data, struct smack_parsed_rule *rule, > * "subjectobject > * acc_enableacc_disable[...]" > */ > -static ssize_t smk_write_rules_list(struct file *file, const char __user *buf, > +ssize_t smk_write_rules_list(struct file *file, const char __user *buf, > size_t count, loff_t *ppos, > struct list_head *rule_list, > struct mutex *rule_lock, int format)