From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795910334; b=xca82xIx3arOBIKXPFVUP4AezJuXnbIVIp1fgChzHAbdOpmuiqB09OmdTuFwnPh5seWE k87q5HCw7sOwug057Naau14GbFgtxFvozygaZsBvXUMvGuwUFuH37UUeo9c8UYXKMFsF5 doeDeGrZidpvgMG6kH27fFpmu4m9U5pgcRIIfGmgKaAkv62y+8EWT35Rp3e4wNQfL6omc wvI7bJhtEA+q2EXFnDijkPw7jtol4S2Jz3XoI2QXtuYxtw5CIPSx+cjdw8ssu3sifYJL1 XjBNQ0feGpERxozJlbhrcirSn9JUvWRM2M0ZW3kcSsxAqzJj+s0Rm1/epSDk4k9Lm3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910334; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=t2jCrn0XBQDnJAlb1mgk9niYn/JkZAyZykFy426bAJE=; b=DygDYqLH9dcAhInU2lz2qpx9mtD518YxLubEbYDIm++NrUZrxuXORc7GkjfC8RbGiSAh W9XyTcgYk+/f5jZ8BZM8pH+1QWGbceU9qtZ9EOZzEoqnIsrF79OSbvsm3U7oq8BxZ2Vpr ipPNlRp8tONX6ZZ2pPLadTWYHSE5A6FwUtodJ+e3nPNl6eBx6IA77Y1l76QBZuLYTUU+c qHa21ufi77kOIvubz60OnzeOkudagWD33s/OXmUYHvF0kz3yvAsOOkm10OLigL03GC8u7 4WIt1DmQZtoe4k7f4jjX0ekI0BeJ+cTZZWSyeVwf4Z/tTTdEFkAc6ipERLW8+TyNtRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EfY7joaJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 91769606A681; Sat, 28 Nov 2026 23:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EfY7joaJ Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id B648B1F00919; Sat, 28 Nov 2026 23:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910334; bh=t2jCrn0XBQDnJAlb1mgk9niYn/JkZAyZykFy426bAJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfY7joaJ7q3GeOM6fXJg3bTRCE69QVZDU8CjxmcUy/PU3XsOe3+pz+bc1xqORaoWp hOBXcUTKqneVFH2NyPuC6mwTFhEz/SGcueQZ15qKfMAAm3GUJkivnTLNbqkoFAi7DP eq7JglhzPNF4iq3tFO/4blERjtdCp4YmAYTvyzXXkA5rO/K87EQ5t36irV2d7YlvuK YHlMapH/vazDPirD2pS0pqZHJkCketXh9sYbhH1MhFTgN0ZKVafLgDrQalSCo/8IIP OmWkjgAZ66r1pAsGVfRbzPHeeGsQDGLxzluatglaSxSNGVNKQng+Q+aN1UNPsMA/IR gkPS7BVZIm9Rw== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Aleksa Sarai , Alexander Mikhalitsyn , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Christian Brauner , David Howells , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , Hugh Dickins , James Morris , Jan Kara , Jeff Layton , John Johansen , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Matt Bobrowski , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Stephen Smalley , Zygmunt Krynicki Subject: [RFC PATCH v8 09/29] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Date: Sun, 29 Nov 2026 01:57:48 +0200 Message-ID: <20261128235808.2369970-10-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261128235808.2369970-1-jarkko@kernel.org> References: <20261128235808.2369970-1-jarkko@kernel.org> X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When move_mount() is invoked with MOVE_MOUNT_CLONE, the source mount is recursively loopback-cloned from the caller's mount namespace rather than moved or attached from a detached anonymous mount. Pass flags through aa_move_mount() and mediate MOVE_MOUNT_CLONE as MS_BIND | MS_REC while keeping from_path so AppArmor checks both source and destination paths against recursive bind rules. Signed-off-by: Jarkko Sakkinen --- security/apparmor/include/mount.h | 2 +- security/apparmor/lsm.c | 2 +- security/apparmor/mount.c | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/security/apparmor/include/mount.h b/security/apparmor/include/mount.h index 46834f828179..d771ee240d42 100644 --- a/security/apparmor/include/mount.h +++ b/security/apparmor/include/mount.h @@ -43,7 +43,7 @@ int aa_move_mount_old(const struct cred *subj_cred, const char *old_name); int aa_move_mount(const struct cred *subj_cred, struct aa_label *label, const struct path *from_path, - const struct path *to_path); + const struct path *to_path, unsigned int flags); int aa_new_mount(const struct cred *subj_cred, struct aa_label *label, const char *dev_name, diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index aefa71bc1cd2..797944de8273 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -751,7 +751,7 @@ static int apparmor_move_mount(const struct path *from_path, label = __begin_current_label_crit_section(&needput); if (!unconfined(label)) error = aa_move_mount(current_cred(), label, from_path, - to_path); + to_path, flags); __end_current_label_crit_section(label, needput); return error; diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c index 4ed7b9136beb..8d3db6bfdfb6 100644 --- a/security/apparmor/mount.c +++ b/security/apparmor/mount.c @@ -423,13 +423,15 @@ int aa_mount_change_type(const struct cred *subj_cred, int aa_move_mount(const struct cred *subj_cred, struct aa_label *label, const struct path *from_path, - const struct path *to_path) + const struct path *to_path, unsigned int flags) { struct aa_profile *profile; char *to_buffer = NULL, *from_buffer = NULL; + unsigned long mnt_flags = (flags & MOVE_MOUNT_CLONE) ? + (MS_BIND | MS_REC) : MS_MOVE; int error; DEFINE_AUDIT_MOUNT(ad, OP_MOUNT, subj_cred); - ad.mnt.flags = MS_MOVE; + ad.mnt.flags = mnt_flags; AA_BUG(!label); AA_BUG(!from_path); @@ -441,12 +443,12 @@ int aa_move_mount(const struct cred *subj_cred, if (!to_buffer || !from_buffer) goto out; - if (!our_mnt(from_path->mnt)) + if (!(flags & MOVE_MOUNT_CLONE) && !our_mnt(from_path->mnt)) /* moving a mount detached from the namespace */ from_path = NULL; error = fn_for_each(label, profile, match_mnt(profile, to_path, to_buffer, from_path, - from_buffer, NULL, MS_MOVE, NULL, false, + from_buffer, NULL, mnt_flags, NULL, false, &ad)); out: aa_put_buffer(to_buffer); @@ -467,7 +469,7 @@ int aa_move_mount_old(const struct cred *subj_cred, struct aa_label *label, if (error) return error; - error = aa_move_mount(subj_cred, label, &old_path, path); + error = aa_move_mount(subj_cred, label, &old_path, path, 0); path_put(&old_path); return error; -- 2.47.3