Skip to content

Commit e33c1b9

Browse files
keesjrjohansen
authored andcommitted
apparmor: Restore Y/N in /sys for apparmor's "enabled"
Before commit c5459b8 ("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 <[email protected]> Reviewed-by: David Rheinsberg <[email protected]> Link: https://lkml.kernel.org/r/CADyDSO6k8vYb1eryT4g6+EHrLCvb68GAbHVWuULkYjcZcYNhhw@mail.gmail.com Fixes: c5459b8 ("LSM: Plumb visibility into optional "enabled" state") Signed-off-by: Kees Cook <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 771acc7 commit e33c1b9

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

security/apparmor/lsm.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,16 @@ module_param_named(path_max, aa_g_path_max, aauint, S_IRUSR);
13361336
bool aa_g_paranoid_load = true;
13371337
module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);
13381338

1339+
static int param_get_aaintbool(char *buffer, const struct kernel_param *kp);
1340+
static int param_set_aaintbool(const char *val, const struct kernel_param *kp);
1341+
#define param_check_aaintbool param_check_int
1342+
static const struct kernel_param_ops param_ops_aaintbool = {
1343+
.set = param_set_aaintbool,
1344+
.get = param_get_aaintbool
1345+
};
13391346
/* Boot time disable flag */
13401347
static int apparmor_enabled __lsm_ro_after_init = 1;
1341-
module_param_named(enabled, apparmor_enabled, int, 0444);
1348+
module_param_named(enabled, apparmor_enabled, aaintbool, 0444);
13421349

13431350
static int __init apparmor_enabled_setup(char *str)
13441351
{
@@ -1413,6 +1420,46 @@ static int param_get_aauint(char *buffer, const struct kernel_param *kp)
14131420
return param_get_uint(buffer, kp);
14141421
}
14151422

1423+
/* Can only be set before AppArmor is initialized (i.e. on boot cmdline). */
1424+
static 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+
*/
1450+
static 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+
14161463
static int param_get_audit(char *buffer, const struct kernel_param *kp)
14171464
{
14181465
if (!apparmor_enabled)

0 commit comments

Comments
 (0)