From patchwork Fri Feb 9 21:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgia Garcia X-Patchwork-Id: 1897253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TWnRg5wPGz23hc for ; Sat, 10 Feb 2024 08:43:59 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rYYey-0004Eg-RX; Fri, 09 Feb 2024 21:43:48 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rYYen-00046u-67 for kernel-team@lists.ubuntu.com; Fri, 09 Feb 2024 21:43:38 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 82D373F5D9 for ; Fri, 9 Feb 2024 21:43:36 +0000 (UTC) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2909c95e737so1248535a91.1 for ; Fri, 09 Feb 2024 13:43:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707515014; x=1708119814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BqE0Jxu7iPf3Yy7M9WSaf3WuG7/spL5rEvdg64InMeY=; b=Reir9RNhtb865+nLX+aQ1leuyKXZAzrwnuZGOfpa7jWmxy/CR1GTOHEcc2nklJ5xpT SjaQ99BGOvfenyOVP/WpSAapbpiFgb5WFDuV27Y1RqINW+TBdPMZc5XS50EKxGJ7o06q 1vQgf+MvEO0y0YygQCCytV4JxqmJIN1N1yubFuRvQYCyh+skCyuaJmlKNpsYIhPxAa0c jAq3xpOYzJlELxky67H1iP2D0ODwi1UQswKGJEviC2kNlj40DfyoHVXvCWuuCJ2KH1NQ gdPxarUWLqtImAjoFmBOKG65BLU2oH1X2jlO+jtr/9B1T4E2jV1LhqKlVv6rWEG8k5KT plVg== X-Gm-Message-State: AOJu0YwdCGvv/hrDvmehV4lfndZmGCoO2gZjtcwOFjuNPknq5BM0h7TB rYzizEO9IbCm3T2vR4EuYLZjho7J7z3Oi79qr9rIDsrMbFjNPAkRXB7iIhHRkJWzAN5JoGAzxYX JQS4IqCuu/L9XNvWMjIY1ipMb+5YiKhYrpd9YhEaPCLWV4dexEbU6osxRvADZoJyMx2U2uZGE/8 uQt2I4pDWX3qzi X-Received: by 2002:a17:90b:17c6:b0:295:cb78:a6f7 with SMTP id me6-20020a17090b17c600b00295cb78a6f7mr299496pjb.8.1707515014344; Fri, 09 Feb 2024 13:43:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwV7PkfCPxxVs/PnFpRdLN8OdvPCTmoyvYKeb0hXUioTDMctBG6fX+ClBMgSNrdxcfTA74Kw== X-Received: by 2002:a17:90b:17c6:b0:295:cb78:a6f7 with SMTP id me6-20020a17090b17c600b00295cb78a6f7mr299473pjb.8.1707515013851; Fri, 09 Feb 2024 13:43:33 -0800 (PST) Received: from georgia.. ([2001:1284:f034:f554:634e:43c2:dd2a:b546]) by smtp.gmail.com with ESMTPSA id gm15-20020a17090b100f00b00296f780de33sm2272621pjb.36.2024.02.09.13.43.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:43:33 -0800 (PST) From: Georgia Garcia To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH v2 1/1] apparmor: Fix move_mount mediation by detecting if source is detached Date: Fri, 9 Feb 2024 18:43:28 -0300 Message-Id: <20240209214328.690764-2-georgia.garcia@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240209214328.690764-1-georgia.garcia@canonical.com> References: <20240209214328.690764-1-georgia.garcia@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: John Johansen BugLink: http://launchpad.net/bugs/2052662 Prevent move_mount from applying the attach_disconnected flag to move_mount(). This prevents detached mounts from appearing as / when applying mount mediation, which is not only incorrect but could result in bad policy being generated. Basic mount rules like allow mount, allow mount options=(move) -> /target/, will allow detached mounts, allowing older policy to continue to function. New policy gains the ability to specify `detached` as a source option allow mount detached -> /target/, In addition make sure support of move_mount is advertised as a feature to userspace so that applications that generate policy can respond to the addition. Note: this fixes mediation of move_mount when a detached mount is used, it does not fix the broader regression of apparmor mediation of mounts under the new mount api. Link: https://lore.kernel.org/all/68c166b8-5b4d-4612-8042-1dee3334385b@leemhuis.info/T/#mb35fdde37f999f08f0b02d58dc1bf4e6b65b8da2 Fixes: 157a3537d6bc ("apparmor: Fix regression in mount mediation") Reviewed-by: Georgia Garcia Signed-off-by: John Johansen (cherry picked from commit 8026e40608b4d552216d2a818ca7080a4264bb44) Signed-off-by: Georgia Garcia --- security/apparmor/apparmorfs.c | 1 + security/apparmor/mount.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index ab7aa97fe7e38..cfc1741916e08 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2619,6 +2619,7 @@ static struct aa_sfs_entry aa_sfs_entry_policy[] = { static struct aa_sfs_entry aa_sfs_entry_mount[] = { AA_SFS_FILE_STRING("mask", "mount umount pivot_root"), + AA_SFS_FILE_STRING("move_mount", "detached"), { } }; diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c index fb30204c761ad..49fe8da6fea45 100644 --- a/security/apparmor/mount.c +++ b/security/apparmor/mount.c @@ -499,6 +499,10 @@ int aa_move_mount(const struct cred *subj_cred, error = -ENOMEM; if (!to_buffer || !from_buffer) goto out; + + if (!our_mnt(from_path->mnt)) + /* moving a mount detached from the namespace */ + from_path = NULL; error = fn_for_each_confined(label, profile, match_mnt(subj_cred, profile, to_path, to_buffer, from_path, from_buffer,