Skip to content

Commit 3ed4aaa

Browse files
committed
apparmor: fix nnp subset test for unconfined
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>
1 parent a68d59f commit 3ed4aaa

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
@@ -929,7 +929,8 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
929929
* aways results in a further reduction of permissions.
930930
*/
931931
if ((bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS) &&
932-
!unconfined(label) && !aa_label_is_subset(new, ctx->nnp)) {
932+
!unconfined(label) &&
933+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
933934
error = -EPERM;
934935
info = "no new privs";
935936
goto audit;
@@ -1207,7 +1208,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
12071208
* reduce restrictions.
12081209
*/
12091210
if (task_no_new_privs(current) && !unconfined(label) &&
1210-
!aa_label_is_subset(new, ctx->nnp)) {
1211+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
12111212
/* not an apparmor denial per se, so don't log it */
12121213
AA_DEBUG("no_new_privs - change_hat denied");
12131214
error = -EPERM;
@@ -1228,7 +1229,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
12281229
* reduce restrictions.
12291230
*/
12301231
if (task_no_new_privs(current) && !unconfined(label) &&
1231-
!aa_label_is_subset(previous, ctx->nnp)) {
1232+
!aa_label_is_unconfined_subset(previous, ctx->nnp)) {
12321233
/* not an apparmor denial per se, so don't log it */
12331234
AA_DEBUG("no_new_privs - change_hat denied");
12341235
error = -EPERM;
@@ -1424,7 +1425,7 @@ int aa_change_profile(const char *fqname, int flags)
14241425
* reduce restrictions.
14251426
*/
14261427
if (task_no_new_privs(current) && !unconfined(label) &&
1427-
!aa_label_is_subset(new, ctx->nnp)) {
1428+
!aa_label_is_unconfined_subset(new, ctx->nnp)) {
14281429
/* not an apparmor denial per se, so don't log it */
14291430
AA_DEBUG("no_new_privs - change_hat denied");
14301431
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)