From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9ED52417D9 for ; Sat, 9 May 2026 01:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778289758; cv=none; b=eqxDWhWaVWhI77bcYt7DH13p1SxHyFREKOnEDuLlIpLjWiss0Wq8pbrZBiyLx/JSibxCzY3KeHaBqjnvEUrECESk11wLWbO6b0VZN69X4y2r1XS+28Sq+j7cG1vkpKPGOGEY0V5lbl6vavJL1ANuE+cmzrg6CtrJNYCWe1Xmugc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778289758; c=relaxed/simple; bh=KoLIfUsJtE2vxPlZkT7zjeGuQ4Apxdj6qvZebaZ8m+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WbLMFm1OsuP4zLj6LFoXnizV3GsynJ60ykpaxrvNZXFkxKaMYnlXyf4qab6j6FPom99kB6ILQHJPT+MJK3yB6SxyWNfuhDNfi1fsPHW9Re44+aYQ5wg8zePPnT2cQm08mzATPpf4No9fm8dtHSj066CmS6H2kedvj8fwYkF3FAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mgGnIKtL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mgGnIKtL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3750EC2BCB0; Sat, 9 May 2026 01:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778289757; bh=KoLIfUsJtE2vxPlZkT7zjeGuQ4Apxdj6qvZebaZ8m+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mgGnIKtLAP9eEhkhOcwUsoR1SsWzGOao/FcZ90W6rJKuxFrFR7A+4QxPnSq7KGHy9 nRkzrc7F3RGoPHIMq62zV2LS2GFvl4B03zmxma4IubRu6bCKYxxliaiWB64Yy43pkU m68NkQeZRWRl87dJn1wJ0MECqpKv6dMuPvBCBtFkus6BchTV1aU7f9toua3htV8UrJ HA+quUGrhtlsWLuTukVnm2t3j2EALs7wq4d9S8k1Ug7C+0pj9Bn5RGPWZQEYmi/iW2 oaSrnxAUJRVK1FXBTDxIvrgnByh/VfYHuxwaw2ZAVGVBb8pOR/NHCOdzzKzAoiwEyr LOLMz8DiwYs2Q== From: Sasha Levin To: stable@vger.kernel.org Cc: Cengiz Can , Qualys Security Advisory , John Johansen , Sasha Levin Subject: [PATCH 5.10.y] apparmor: use target task's context in apparmor_getprocattr() Date: Fri, 8 May 2026 21:22:34 -0400 Message-ID: <20260509012234.2844474-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050424-perceive-compress-fcb1@gregkh> References: <2026050424-perceive-compress-fcb1@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cengiz Can [ Upstream commit 4afc61702bdcc3b9b519749ef966cf762a6e7051 ] apparmor_getprocattr() incorrectly calls task_ctx(current) instead of task_ctx(task) when retrieving prev and exec attributes, returning the caller's labels rather than the target's. Fix by passing task to task_ctx(). The issue can be reproduced when a process with an onexec transition (e.g., configured by a container runtime) is inspected via /proc//attr/apparmor/exec. The reader's own value is returned instead of the target's. Reported-by: Qualys Security Advisory Fixes: 3b529a7600d8 ("apparmor: move task domain change info to task security") Cc: stable@vger.kernel.org Co-developed-by: Cengiz Can Signed-off-by: Cengiz Can Co-developed-by: John Johansen Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/lsm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 37aa1650c74eb..c1c8efd7db8c3 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -589,25 +589,23 @@ static int apparmor_getprocattr(struct task_struct *task, char *name, char **value) { int error = -ENOENT; - /* released below */ - const struct cred *cred = get_task_cred(task); - struct aa_task_ctx *ctx = task_ctx(current); struct aa_label *label = NULL; + rcu_read_lock(); if (strcmp(name, "current") == 0) - label = aa_get_newest_label(cred_label(cred)); - else if (strcmp(name, "prev") == 0 && ctx->previous) - label = aa_get_newest_label(ctx->previous); - else if (strcmp(name, "exec") == 0 && ctx->onexec) - label = aa_get_newest_label(ctx->onexec); + label = aa_get_newest_cred_label(__task_cred(task)); + else if (strcmp(name, "prev") == 0 && task_ctx(task)->previous) + label = aa_get_newest_label(task_ctx(task)->previous); + else if (strcmp(name, "exec") == 0 && task_ctx(task)->onexec) + label = aa_get_newest_label(task_ctx(task)->onexec); else error = -EINVAL; + rcu_read_unlock(); if (label) error = aa_getprocattr(label, value); aa_put_label(label); - put_cred(cred); return error; } -- 2.53.0