Skip to content

Commit a78c65c

Browse files
jrjohansengregkh
authored andcommitted
apparmor: fix nnp subset test for unconfined
[ Upstream commit 3ed4aaa ] The subset test is not taking into account the unconfined exception which will cause profile transitions in the stacked confinement case to fail when no_new_privs is applied. This fixes a regression introduced in the fix for https://bugs.launchpad.net/bugs/1839037 BugLink: https://bugs.launchpad.net/bugs/1844186 Signed-off-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent af1f72a commit a78c65c

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎security/apparmor/domain.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
935935
* aways results in a further reduction of permissions.
936936
*/
937937
if ((bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS) &&
938-
!unconfined(label) && !aa_label_is_subset(new, ctx->nnp)) {
938+
!unconfined(label) &&
939+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
939940
error = -EPERM;
940941
info = "no new privs";
941942
goto audit;
@@ -1213,7 +1214,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
12131214
* reduce restrictions.
12141215
*/
12151216
if (task_no_new_privs(current) && !unconfined(label) &&
1216-
!aa_label_is_subset(new, ctx->nnp)) {
1217+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
12171218
/* not an apparmor denial per se, so don't log it */
12181219
AA_DEBUG("no_new_privs - change_hat denied");
12191220
error = -EPERM;
@@ -1234,7 +1235,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
12341235
* reduce restrictions.
12351236
*/
12361237
if (task_no_new_privs(current) && !unconfined(label) &&
1237-
!aa_label_is_subset(previous, ctx->nnp)) {
1238+
!aa_label_is_unconfined_subset(previous, ctx->nnp)) {
12381239
/* not an apparmor denial per se, so don't log it */
12391240
AA_DEBUG("no_new_privs - change_hat denied");
12401241
error = -EPERM;
@@ -1429,7 +1430,7 @@ int aa_change_profile(const char *fqname, int flags)
14291430
* reduce restrictions.
14301431
*/
14311432
if (task_no_new_privs(current) && !unconfined(label) &&
1432-
!aa_label_is_subset(new, ctx->nnp)) {
1433+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
14331434
/* not an apparmor denial per se, so don't log it */
14341435
AA_DEBUG("no_new_privs - change_hat denied");
14351436
error = -EPERM;

‎security/apparmor/include/label.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ bool aa_label_init(struct aa_label *label, int size, gfp_t gfp);
281281
struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp);
282282

283283
bool aa_label_is_subset(struct aa_label *set, struct aa_label *sub);
284+
bool aa_label_is_unconfined_subset(struct aa_label *set, struct aa_label *sub);
284285
struct aa_profile *__aa_label_next_not_in_set(struct label_it *I,
285286
struct aa_label *set,
286287
struct aa_label *sub);

‎security/apparmor/label.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,39 @@ bool aa_label_is_subset(struct aa_label *set, struct aa_label *sub)
550550
return __aa_label_next_not_in_set(&i, set, sub) == NULL;
551551
}
552552

553+
/**
554+
* aa_label_is_unconfined_subset - test if @sub is a subset of @set
555+
* @set: label to test against
556+
* @sub: label to test if is subset of @set
557+
*
558+
* This checks for subset but taking into account unconfined. IF
559+
* @sub contains an unconfined profile that does not have a matching
560+
* unconfined in @set then this will not cause the test to fail.
561+
* Conversely we don't care about an unconfined in @set that is not in
562+
* @sub
563+
*
564+
* Returns: true if @sub is special_subset of @set
565+
* else false
566+
*/
567+
bool aa_label_is_unconfined_subset(struct aa_label *set, struct aa_label *sub)
568+
{
569+
struct label_it i = { };
570+
struct aa_profile *p;
571+
572+
AA_BUG(!set);
573+
AA_BUG(!sub);
574+
575+
if (sub == set)
576+
return true;
577+
578+
do {
579+
p = __aa_label_next_not_in_set(&i, set, sub);
580+
if (p && !profile_unconfined(p))
581+
break;
582+
} while (p);
583+
584+
return p == NULL;
585+
}
553586

554587

555588
/**

0 commit comments

Comments
 (0)