aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2019-04-08 12:07:06 -0400
committerJohn Johansen <john.johansen@canonical.com>2019-04-10 07:24:48 -0400
commite33c1b9923775d17ad246946fe67fcb9be288677 (patch)
tree11ff1477557e9608883f7d8986cb54f4fadfe239
parent771acc7e4a6e5dba779cb1a7fd851a164bc81033 (diff)
apparmor: Restore Y/N in /sys for apparmor's "enabled"
Before commit c5459b829b71 ("LSM: Plumb visibility into optional "enabled" state"), /sys/module/apparmor/parameters/enabled would show "Y" or "N" since it was using the "bool" handler. After being changed to "int", this switched to "1" or "0", breaking the userspace AppArmor detection of dbus-broker. This restores the Y/N output while keeping the LSM infrastructure happy. Before: $ cat /sys/module/apparmor/parameters/enabled 1 After: $ cat /sys/module/apparmor/parameters/enabled Y Reported-by: David Rheinsberg <david.rheinsberg@gmail.com> Reviewed-by: David Rheinsberg <david.rheinsberg@gmail.com> Link: https://lkml.kernel.org/r/CADyDSO6k8vYb1eryT4g6+EHrLCvb68GAbHVWuULkYjcZcYNhhw@mail.gmail.com Fixes: c5459b829b71 ("LSM: Plumb visibility into optional "enabled" state") Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: John Johansen <john.johansen@canonical.com>
-rw-r--r--security/apparmor/lsm.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 49d664ddff44..87500bde5a92 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1336,9 +1336,16 @@ module_param_named(path_max, aa_g_path_max, aauint, S_IRUSR);
1336bool aa_g_paranoid_load = true; 1336bool aa_g_paranoid_load = true;
1337module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO); 1337module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);
1338 1338
1339static int param_get_aaintbool(char *buffer, const struct kernel_param *kp);
1340static int param_set_aaintbool(const char *val, const struct kernel_param *kp);
1341#define param_check_aaintbool param_check_int
1342static const struct kernel_param_ops param_ops_aaintbool = {
1343 .set = param_set_aaintbool,
1344 .get = param_get_aaintbool
1345};
1339/* Boot time disable flag */ 1346/* Boot time disable flag */
1340static int apparmor_enabled __lsm_ro_after_init = 1; 1347static int apparmor_enabled __lsm_ro_after_init = 1;
1341module_param_named(enabled, apparmor_enabled, int, 0444); 1348module_param_named(enabled, apparmor_enabled, aaintbool, 0444);
1342 1349
1343static int __init apparmor_enabled_setup(char *str) 1350static int __init apparmor_enabled_setup(char *str)
1344{ 1351{
@@ -1413,6 +1420,46 @@ static int param_get_aauint(char *buffer, const struct kernel_param *kp)
1413 return param_get_uint(buffer, kp); 1420 return param_get_uint(buffer, kp);
1414} 1421}
1415 1422
1423/* Can only be set before AppArmor is initialized (i.e. on boot cmdline). */
1424static int param_set_aaintbool(const char *val, const struct kernel_param *kp)
1425{
1426 struct kernel_param kp_local;
1427 bool value;
1428 int error;
1429
1430 if (apparmor_initialized)
1431 return -EPERM;
1432
1433 /* Create local copy, with arg pointing to bool type. */
1434 value = !!*((int *)kp->arg);
1435 memcpy(&kp_local, kp, sizeof(kp_local));
1436 kp_local.arg = &value;
1437
1438 error = param_set_bool(val, &kp_local);
1439 if (!error)
1440 *((int *)kp->arg) = *((bool *)kp_local.arg);
1441 return error;
1442}
1443
1444/*
1445 * To avoid changing /sys/module/apparmor/parameters/enabled from Y/N to
1446 * 1/0, this converts the "int that is actually bool" back to bool for
1447 * display in the /sys filesystem, while keeping it "int" for the LSM
1448 * infrastructure.
1449 */
1450static int param_get_aaintbool(char *buffer, const struct kernel_param *kp)
1451{
1452 struct kernel_param kp_local;
1453 bool value;
1454
1455 /* Create local copy, with arg pointing to bool type. */
1456 value = !!*((int *)kp->arg);
1457 memcpy(&kp_local, kp, sizeof(kp_local));
1458 kp_local.arg = &value;
1459
1460 return param_get_bool(buffer, &kp_local);
1461}
1462
1416static int param_get_audit(char *buffer, const struct kernel_param *kp) 1463static int param_get_audit(char *buffer, const struct kernel_param *kp)
1417{ 1464{
1418 if (!apparmor_enabled) 1465 if (!apparmor_enabled)